Pman.Tab.XtupleSalesOrder.bjs
[Pman.Xtuple] / Pman.Tab.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.Tab.XtupleSalesOrder = new Roo.XComponent({
6     part     :  ["Xtuple","SalesOrder"],
7     order    : '001-Pman.Tab.XtupleSalesOrder',
8     region   : 'center',
9     parent   : 'Pman.Tab.XtupleSales',
10     name     : "unnamed module",
11     disabled : false, 
12     permname : '', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'NestedLayoutPanel',
19             xns: Roo,
20             listeners : {
21                 activate : function (_self)
22                 {
23                     this.setTitle('Sales Orders (' + Pman.Login.authUser.dbname +')');
24                 }
25             },
26             region : 'center',
27             title : "Sales Orders",
28             layout : {
29                 xtype: 'BorderLayout',
30                 xns: Roo,
31                 items : [
32                     {
33                         xtype: 'GridPanel',
34                         xns: Roo,
35                         listeners : {
36                             activate : function() {
37                                 _this.panel = this;
38                                 if (_this.grid) {
39                                     _this.grid.footer.onClick('first');
40                                 }
41                             }
42                         },
43                         background : true,
44                         fitContainer : true,
45                         fitToframe : true,
46                         region : 'center',
47                         tableName : 'cohead',
48                         title : "cohead",
49                         grid : {
50                             xtype: 'Grid',
51                             xns: Roo.grid,
52                             listeners : {
53                                 render : function() 
54                                 {
55                                     _this.grid = this; 
56                                     try { 
57                                         _this.dialog = Pman.Dialog.XtupleSalesOrder;
58                                     } catch(e) {}
59                                     if (_this.panel.active) {
60                                        this.footer.onClick('first');
61                                     }
62                                 },
63                                 rowdblclick : function (_self, rowIndex, e)
64                                 {
65                                     if (!_this.dialog) return;
66                                     _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
67                                         _this.grid.footer.onClick('refresh');
68                                         Pman.Tab.XtupleSales.grid.footer.onClick('first');
69                                     }); 
70                                 }
71                             },
72                             autoExpandColumn : 'cohead_cust_id_cust_name',
73                             loadMask : true,
74                             dataSource : {
75                                 xtype: 'Store',
76                                 xns: Roo.data,
77                                 listeners : {
78                                     beforeload : function (_self, options)
79                                     {
80                                         var vl;
81                                         try { 
82                                              vl = _this.form.getFieldValues();
83                                          } catch (e) {
84                                             vl = {};
85                                          }
86                                     
87                                          
88                                          
89                                         for(var x in vl) {
90                                             if (!(new String(vl[x])).length) {
91                                                 continue;
92                                             }
93                                             options.params[x] = vl[x];
94                                             
95                                         }
96                                         try {
97                                             if (options.params['query[cohead_number]'].length) {
98                                                 options.params.viewtype = 'REALALL';
99                                             }
100                                         } catch (e) {}
101                                     }
102                                 },
103                                 remoteSort : true,
104                                 sortInfo : { field : 'cohead_orderdate', direction: 'DESC' },
105                                 proxy : {
106                                     xtype: 'HttpProxy',
107                                     xns: Roo.data,
108                                     method : 'GET',
109                                     timeout : 60000,
110                                     url : baseURL + '/Roo/cohead.php'
111                                 },
112                                 reader : {
113                                     xtype: 'JsonReader',
114                                     xns: Roo.data,
115                                     totalProperty : 'total',
116                                     root : 'data',
117                                     id : 'id',
118                                     fields : [
119                                         {
120                                             'name': 'cohead_number',
121                                             'type': 'string'
122                                         },
123                                         {
124                                             'name': 'cohead_cust_id_cust_name',
125                                             'type': 'string'
126                                         },
127                                         {
128                                             'name': 'cohead_custponumber',
129                                             'type': 'string'
130                                         },
131                                         {
132                                             'name': 'cohead_type'
133                                         },
134                                         {
135                                             'name': 'cohead_orderdate',
136                                             'type': 'date'
137                                         },
138                                         {
139                                             'name': 'cohead_shipto_id_shipto_name',
140                                             'type': 'string'
141                                         },
142                                         {
143                                             'name': 'cohead_terms_id_terms_descrip',
144                                             'type': 'string'
145                                         },
146                                         {
147                                             'name': 'cohead_curr_id_curr_name',
148                                             'type': 'string'
149                                         }
150                                     ]
151                                 }
152                             },
153                             footer : {
154                                 xtype: 'PagingToolbar',
155                                 xns: Roo,
156                                 pageSize : 25,
157                                 displayInfo : true,
158                                 displayMsg : "Displaying cohead{0} - {1} of {2}",
159                                 emptyMsg : "No cohead found",
160                                 items : [
161                                     {
162                                         xtype: 'Button',
163                                         xns: Roo.Toolbar,
164                                         listeners : {
165                                             click : function ()
166                                             {
167                                                 new Pman.Download({
168                                                     grid : _this.grid
169                                                 });     
170                                                
171                                             }
172                                         },
173                                         cls : 'x-btn-text-icon',
174                                         text : "Download Results",
175                                         icon : rootURL + '/Pman/templates/images/spreadsheet.gif'
176                                     }
177                                 ]
178                             },
179                             toolbar : {
180                                 xtype: 'Toolbar',
181                                 xns: Roo,
182                                 items : [
183                                     {
184                                         xtype: 'Button',
185                                         xns: Roo.Toolbar,
186                                         listeners : {
187                                             click : function (_self, e)
188                                             {
189                                              Pman.Dialog.XtupleInvHistory.show({
190                                              
191                                              
192                                                 });
193                                             }
194                                         },
195                                         text : "Quick Stock Check"
196                                     },
197                                     {
198                                         xtype: 'Button',
199                                         xns: Roo.Toolbar,
200                                         listeners : {
201                                             click : function (_self, e)
202                                             {
203                                                Pman.Dialog.Image.show(
204                                                    {
205                                                         _url : baseURL+'/Xtuple/Import/Magento',
206                                                         timeout : 90000
207                                                     
208                                                    },
209                                                    function (data) {
210                                                         Roo.MessageBox.alert("Notice", data); 
211                                                         _this.grid.footer.onClick('first');
212                                             
213                                                    }
214                                                );
215                                             }
216                                         },
217                                         text : "Magento Upload"
218                                     },
219                                     {
220                                         xtype: 'Button',
221                                         xns: Roo.Toolbar,
222                                         hidden : true,
223                                         text : "Magento Upload",
224                                         menu : {
225                                             xtype: 'Menu',
226                                             xns: Roo.menu,
227                                             items : [
228                                                 {
229                                                     xtype: 'Item',
230                                                     xns: Roo.menu,
231                                                     listeners : {
232                                                         click : function (_self, e)
233                                                         {
234                                                            Pman.Dialog.Image.show(
235                                                                {
236                                                                     _url : baseURL+'/Xtuple/Import/MagentoOld',
237                                                                     timeout : 90000
238                                                                     
239                                                                 
240                                                                },
241                                                                function (data) {
242                                                                     Roo.MessageBox.alert("Notice", data); 
243                                                                     _this.grid.footer.onClick('first');
244                                                                   /*  var msg = [];
245                                                                    
246                                                                     if (data.updated) {
247                                                                         msg.push("Updated " + data.updated + " Products(s)");
248                                                                     }            
249                                                                     if (data.inserted) {
250                                                                         msg.push("Added " + data.inserted + " Products(s)");
251                                                                     }
252                                                                     if (data.skipped) {
253                                                                         msg.push("Skipped " + data.skipped);
254                                                                     }
255                                                                     
256                                                                     if (!msg.length) {
257                                                                         msg.push("No data changed");
258                                                                     }
259                                                                     Roo.MessageBox.alert("Notice", msg.join("\n")); */
260                                                         
261                                                                }
262                                                            );
263                                                         }
264                                                     },
265                                                     text : "Upload Magento File (Old Format)"
266                                                 },
267                                                 {
268                                                     xtype: 'Item',
269                                                     xns: Roo.menu,
270                                                     listeners : {
271                                                         click : function (_self, e)
272                                                         {
273                                                            Pman.Dialog.Image.show(
274                                                                {
275                                                                     _url : baseURL+'/Xtuple/Import/Magento',
276                                                                     timeout : 90000
277                                                                 
278                                                                },
279                                                                function (data) {
280                                                                     Roo.MessageBox.alert("Notice", data); 
281                                                                     _this.grid.footer.onClick('first');
282                                                         
283                                                                }
284                                                            );
285                                                         }
286                                                     },
287                                                     text : "Upload Magento File (New Format)"
288                                                 }
289                                             ]
290                                         }
291                                     },
292                                     {
293                                         xtype: 'Button',
294                                         xns: Roo.Toolbar,
295                                         cls : 'x-btn-text-icon',
296                                         text : "Reports",
297                                         icon : rootURL + '/Pman/templates/images/spreadsheet.gif',
298                                         menu : {
299                                             xtype: 'Menu',
300                                             xns: Roo.menu,
301                                             items : [
302                                                 {
303                                                     xtype: 'Item',
304                                                     xns: Roo.menu,
305                                                     text : "AR Aging",
306                                                     menu : {
307                                                         xtype: 'Menu',
308                                                         xns: Roo.menu,
309                                                         items : [
310                                                             {
311                                                                 xtype: 'Item',
312                                                                 xns: Roo.menu,
313                                                                 listeners : {
314                                                                     click : function (_self, e)
315                                                                     {
316                                                                         var from = _this.form.findField('_fromdate').getValue();
317                                                                         var to = _this.form.findField('_todate').getValue();
318                                                                         
319                                                                         if(!from || !to){
320                                                                             Roo.Msg.alert('Error', 'Please select a date range for the report');
321                                                                             return;
322                                                                         }
323                                                                         
324                                                                         var params  =   {
325                                                                             template: 'ARAging',
326                                                                             filename : 'ARAging-' + to.format('Y-m-d'),
327                                                                             'param[0]':   "startDate:string='" + from.format('Y-m-d') + "'",
328                                                                             'param[1]':   "relDate:string='" + to.format('Y-m-d') + "'",
329                                                                             'param[2]':   "useDocDate:number=1"
330                                                                         };
331                                                                         var cust_id =     _this.form.findField('cohead_cust_id').getValue();
332                                                                         if (cust_id * 1 > 0) {
333                                                                             params['param[3]'] = 'cust_id:number=' + cust_id;
334                                                                         }
335                                                                      
336                                                                         new Pman.Download({
337                                                                           url : baseURL + '/Xtuple/Print',
338                                                                           params :   params,
339                                                                           method : 'GET'
340                                                                         });
341                                                                         Roo.MessageBox.alert("Notice", "Report will download shortly");
342                                                                     }
343                                                                 },
344                                                                 text : "as PDF"
345                                                             },
346                                                             {
347                                                                 xtype: 'Item',
348                                                                 xns: Roo.menu,
349                                                                 listeners : {
350                                                                     click : function (_self, e)
351                                                                     {
352                                                                         var from = _this.form.findField('_fromdate').getValue();
353                                                                         var to = _this.form.findField('_todate').getValue();
354                                                                         
355                                                                        
356                                                                         
357                                                                         var params = {
358                                                                             '_group' : 'arAging',
359                                                                             '_name' : 'bydate',
360                                                                             'limit' : 99999,
361                                                                             
362                                                                               'startDate:text' : from ? from.format('Y-m-d') : '2000-01-01' ,
363                                                                             'relDate:text' : to ? to.format('Y-m-d') : '2100-01-01',
364                                                                          
365                                                                             
366                                                                             
367                                                                             'useDocDate:text' : 'TRUE',
368                                                                             'csvTitles' : '*',
369                                                                             'csvCols' : '*'
370                                                                         };
371                                                                         
372                                                                         
373                                                                         var cust_id =     _this.form.findField('cohead_cust_id').getValue();
374                                                                         if (cust_id * 1 > 0) {
375                                                                             params['cust_id:number'] = cust_id;
376                                                                         }
377                                                                         
378                                                                         new Pman.Download({\r
379                                                                           url : baseURL + '/Roo/Metasql',\r
380                                                                           params :   params,\r
381                                                                           method : 'GET'\r
382                                                                         });\r
383                                                                         Roo.MessageBox.alert("Notice", "Report will download shortly");\r
384                                                                         \r
385                                                                     }
386                                                                 },
387                                                                 text : "as Excel"
388                                                             },
389                                                             {
390                                                                 xtype: 'Item',
391                                                                 xns: Roo.menu,
392                                                                 listeners : {
393                                                                     click : function (_self, e)
394                                                                     {
395                                                                         var from = _this.form.findField('_fromdate').getValue();
396                                                                         var to = _this.form.findField('_todate').getValue();
397                                                                         
398                                                                        
399                                                                         
400                                                                         var params = {
401                                                                             '_group' : 'arAging',
402                                                                             '_name' : 'summary',
403                                                                             'limit' : 99999,
404                                                                             
405                                                                             
406                                                                           
407                                                                             'startDate:text' : from ? from.format('Y-m-d') : '2000-01-01' ,
408                                                                             'relDate:text' : to ? to.format('Y-m-d') : '2100-01-01',
409                                                                          
410                                                                             
411                                                                             'useDocDate:text' : 'TRUE',
412                                                                             'csvTitles' : '*',
413                                                                             'csvCols' : '*'
414                                                                         };
415                                                                         
416                                                                         var cust_id =     _this.form.findField('cohead_cust_id').getValue();
417                                                                         if (cust_id * 1 > 0) {
418                                                                             params['cust_id:number'] = cust_id;
419                                                                         }
420                                                                         
421                                                                         new Pman.Download({\r
422                                                                           url : baseURL + '/Roo/Metasql',\r
423                                                                           params :   params,\r
424                                                                           method : 'GET'\r
425                                                                         });\r
426                                                                         Roo.MessageBox.alert("Notice", "Report will download shortly");\r
427                                                                         \r
428                                                                     }
429                                                                 },
430                                                                 text : "Summary Excel"
431                                                             }
432                                                         ]
433                                                     }
434                                                 },
435                                                 {
436                                                     xtype: 'Item',
437                                                     xns: Roo.menu,
438                                                     text : "Customer History",
439                                                     menu : {
440                                                         xtype: 'Menu',
441                                                         xns: Roo.menu,
442                                                         items : [
443                                                             {
444                                                                 xtype: 'Item',
445                                                                 xns: Roo.menu,
446                                                                 listeners : {
447                                                                     click : function (_self, e)
448                                                                     {
449                                                                         var cust_id = _this.form.findField('cohead_cust_id').getValue();
450                                                                         if (cust_id * 1 < 1) {
451                                                                             Roo.Msg.alert('Error', 'Please select a customer');
452                                                                             return;
453                                                                         }
454                                                                         
455                                                                         var from = _this.form.findField('_fromdate').getValue();
456                                                                         var to = _this.form.findField('_todate').getValue();
457                                                                         
458                                                                         if(!from || !to){
459                                                                             Roo.Msg.alert('Error', 'Please select a date range for the report');
460                                                                             return;
461                                                                         }
462                                                                         
463                                                                         var params  =   {
464                                                                             template: 'customer_ar_history',
465                                                                             filename : 'customer_ar_history-' + to.format('Y-m-d'),
466                                                                             'param[0]':   "startDate:string='" + from.format('Y-m-d') + "'",
467                                                                             'param[1]':   "endDate:string='" + to.format('Y-m-d') + "'",
468                                                                             'param[2]':   "cust_id:number=" + cust_id
469                                                                         };
470                                                                              
471                                                                         new Pman.Download({
472                                                                             url : baseURL + '/Xtuple/Print',
473                                                                             params :   params,
474                                                                             method : 'GET'
475                                                                         });
476                                                                         Roo.MessageBox.alert("Notice", "Report will download shortly");
477                                                                     }
478                                                                 },
479                                                                 text : "as PDF"
480                                                             },
481                                                             {
482                                                                 xtype: 'Item',
483                                                                 xns: Roo.menu,
484                                                                 listeners : {
485                                                                     click : function (_self, e)
486                                                                     {
487                                                                         var cust_id = _this.form.findField('cohead_cust_id').getValue();
488                                                                         if (cust_id * 1 < 1) {
489                                                                             Roo.Msg.alert('Error', 'Please select a customer');
490                                                                             return;
491                                                                         }
492                                                                         
493                                                                         var from = _this.form.findField('_fromdate').getValue();
494                                                                         var to = _this.form.findField('_todate').getValue();
495                                                                         
496                                                                       
497                                                                         
498                                                                         var params = {
499                                                                             '_group' : 'customerHistory',
500                                                                             '_name' : 'detail',
501                                                                             'limit' : 99999,
502                                                                             
503                                                                             'startDate:text' : from ? from.format('Y-m-d') : '2000-01-01' ,
504                                                                             'endDate:text' : to ? to.format('Y-m-d') : '2100-01-01',
505                                                                            
506                                                                             'cust_id:number' : cust_id,
507                                                                             'csvTitles' : '*',
508                                                                             'csvCols' : '*'
509                                                                         };
510                                                                         
511                                                                         
512                                                                         new Pman.Download({\r
513                                                                           url : baseURL + '/Roo/Metasql',\r
514                                                                           params :   params,\r
515                                                                           method : 'GET'\r
516                                                                         });\r
517                                                                         Roo.MessageBox.alert("Notice", "Report will download shortly");
518                                                                     }
519                                                                 },
520                                                                 text : "as Excel"
521                                                             }
522                                                         ]
523                                                     }
524                                                 },
525                                                 {
526                                                     xtype: 'Item',
527                                                     xns: Roo.menu,
528                                                     text : "Customer Statement",
529                                                     menu : {
530                                                         xtype: 'Menu',
531                                                         xns: Roo.menu,
532                                                         items : [
533                                                             {
534                                                                 xtype: 'Item',
535                                                                 xns: Roo.menu,
536                                                                 listeners : {
537                                                                     click : function (_self, e)
538                                                                     {
539                                                                         var cust_id = _this.form.findField('cohead_cust_id').getValue();
540                                                                         if (cust_id * 1 < 1) {
541                                                                             Roo.Msg.alert('Error', 'Please select a customer');
542                                                                             return;
543                                                                         }
544                                                                         
545                                                                         var from = _this.form.findField('_fromdate').getValue();
546                                                                         var to = _this.form.findField('_todate').getValue();
547                                                                         
548                                                                      
549                                                                          
550                                                                         var params  =   {
551                                                                             template: 'customer_ar_statement',
552                                                                             filename : 'customer_ar_statement-' +(to ? to.format('Y-m-d') : '2100-01-01'),
553                                                                             'param[0]':   "startDate:string='" + (from ? from.format('Y-m-d') : '2000-01-01') + "'",
554                                                                             'param[1]':   "asofdate:string='" + (to ? to.format('Y-m-d') : '2100-01-01')+ "'",
555                                                                             'param[2]':   "cust_id:number=" + cust_id
556                                                                         };
557                                                                         
558                                                                         new Pman.Download({
559                                                                             url : baseURL + '/Xtuple/Print',
560                                                                             params :   params,
561                                                                             method : 'GET'
562                                                                         });
563                                                                         Roo.MessageBox.alert("Notice", "Report will download shortly");
564                                                                     }
565                                                                 },
566                                                                 text : "as PDF"
567                                                             },
568                                                             {
569                                                                 xtype: 'Item',
570                                                                 xns: Roo.menu,
571                                                                 listeners : {
572                                                                     click : function (_self, e)
573                                                                     {
574                                                                         var cust_id = _this.form.findField('cohead_cust_id').getValue();
575                                                                         if (cust_id * 1 < 1) {
576                                                                             Roo.Msg.alert('Error', 'Please select a customer');
577                                                                             return;
578                                                                         }
579                                                                         
580                                                                        var from = _this.form.findField('_fromdate').getValue();
581                                                                        var to = _this.form.findField('_todate').getValue();
582                                                                     
583                                                                         //if(!from || !to){
584                                                                         //    Roo.Msg.alert('Error', 'Please select a date range for the report');
585                                                                         //    return;
586                                                                         //}
587                                                                         
588                                                                         var params = {
589                                                                             '_group' : 'customerStatement',
590                                                                             '_name' : 'detail',
591                                                                             'limit' : 99999,
592                                                                             'startDate:text' : from ? from.format('Y-m-d') : '2000-01-01' ,
593                                                                             'asofdate:text' : to ? to.format('Y-m-d') : '2100-01-01',
594                                                                             'cust_id:number' : cust_id,
595                                                                             'csvTitles' : '*',
596                                                                             'csvCols' : '*'
597                                                                         };
598                                                                     
599                                                                         
600                                                                         new Pman.Download({\r
601                                                                           url : baseURL + '/Roo/Metasql',\r
602                                                                           params :   params,\r
603                                                                           method : 'GET'\r
604                                                                         });\r
605                                                                         Roo.MessageBox.alert("Notice", "Report will download shortly");
606                                                                     }
607                                                                 },
608                                                                 text : "as Excel"
609                                                             }
610                                                         ]
611                                                     }
612                                                 }
613                                             ]
614                                         }
615                                     },
616                                     {
617                                         xtype: 'Button',
618                                         xns: Roo.Toolbar,
619                                         listeners : {
620                                             click : function()
621                                             {
622                                                 var s = _this.grid.getSelectionModel().getSelected();
623                                                 if (!s) {
624                                                     Roo.MessageBox.alert("Error", "Select an order to close");
625                                                     return;
626                                                 }
627                                                 
628                                                 if(s.data.cohead_status == 'C'){
629                                                     Roo.MessageBox.alert("Error", "This order has been closed");
630                                                     return;
631                                                 }
632                                                 
633                                                 new Pman.Request({
634                                                     url: baseURL + '/Roo/cohead',
635                                                     method : 'POST',
636                                                     params :  {
637                                                         cohead_id : s.data.cohead_id,
638                                                         _close : 1
639                                                     },
640                                                     mask : 'Sending',
641                                                     success : function()
642                                                     {
643                                                         Roo.MessageBox.alert("Notice", "DONE");
644                                                         _this.grid.footer.onClick('first');
645                                                     }
646                                                });
647                                                 
648                                             }
649                                         },
650                                         cls : 'x-btn-text-icon',
651                                         text : "Complete and Close",
652                                         icon : Roo.rootURL + 'images/default/tree/leaf.gif'
653                                     },
654                                     {
655                                         xtype: 'Button',
656                                         xns: Roo.Toolbar,
657                                         listeners : {
658                                             click : function (_self, e)
659                                             {
660                                                 var s = _this.grid.getSelectionModel().getSelected();
661                                                 if (!s) {
662                                                     Roo.MessageBox.alert("Error", "Select an order");
663                                                     return;
664                                                 }
665                                                 
666                                                 new Pman.Download({\r
667                                                   url : baseURL + '/Xtuple/Reports/SalesOrderBookingDetail',\r
668                                                   params :   {
669                                                     cohead_id : s.data.cohead_id
670                                                   },\r
671                                                   method : 'GET'\r
672                                                 });\r
673                                                 
674                                                 Roo.MessageBox.alert("Notice", "Report will download shortly");
675                                             }
676                                         },
677                                         cls : 'x-btn-text-icon',
678                                         text : "Email to warehouse",
679                                         icon : Roo.rootURL + 'images/default/tree/leaf.gif'
680                                     },
681                                     {
682                                         xtype: 'Fill',
683                                         xns: Roo.Toolbar
684                                     },
685                                     {
686                                         xtype: 'Button',
687                                         xns: Roo.Toolbar,
688                                         listeners : {
689                                             click : function()
690                                             {
691                                                // check if the login in user have more than 25 open orders..
692                                                // if yes, warning...
693                                                new Pman.Request({
694                                                     url : baseURL + '/Roo/cohead.php',
695                                                     method :'GET',
696                                                     params : {
697                                                         viewtype : 'MYOPEN',
698                                                         _count_order : 1 // make the search faster!
699                                                     },
700                                                     success : function(res) {
701                                                         if(res.data[0].order_totals * 1 > 25){
702                                                             Roo.MessageBox.alert("Warning", "Can you please close old orders before creating new ones");
703                                                         }
704                                                     }
705                                                 });
706                                                
707                                                Pman.Dialog.XtupleSalesOrderNew.show( { id : 0 } , function() {
708                                                     _this.grid.footer.onClick('first');
709                                                }); 
710                                             }
711                                         },
712                                         cls : 'x-btn-text-icon',
713                                         text : "Add",
714                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
715                                     },
716                                     {
717                                         xtype: 'Button',
718                                         xns: Roo.Toolbar,
719                                         listeners : {
720                                             click : function()
721                                             {
722                                                var s = _this.grid.getSelectionModel().getSelected();
723                                                if (!s) {
724                                                     Roo.MessageBox.alert("Error", "Select an order to copy");
725                                                     return;
726                                                }
727                                                
728                                                
729                                                Pman.Dialog.XtupleSalesOrderCopy.show( { _copy_cohead_id : s.data.cohead_id } , function(data) {
730                                                
731                                                     // get the id from the data, then 
732                                                
733                                                     _this.grid.footer.onClick('first');
734                                                     Pman.Tab.XtupleSales.grid.footer.onClick('first');
735                                                     // get the id from the data, then start editing it..
736                                                     Roo.log(data);
737                                                         _this.dialog.show(data,  function() {
738                                                         _this.grid.footer.onClick('refresh');
739                                                         Pman.Tab.XtupleSales.grid.footer.onClick('first');
740                                                     }); 
741                                                     
742                                                }); 
743                                             }
744                                         },
745                                         cls : 'x-btn-text-icon',
746                                         text : "Copy",
747                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
748                                     }
749                                 ]
750                             },
751                             colModel : [
752                                 {
753                                     xtype: 'ColumnModel',
754                                     xns: Roo.grid,
755                                     dataIndex : 'cohead_orderdate',
756                                     header : 'Ordered',
757                                     sortable : true,
758                                     width : 75,
759                                     renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
760                                 },
761                                 {
762                                     xtype: 'ColumnModel',
763                                     xns: Roo.grid,
764                                     dataIndex : 'cohead_targetdate',
765                                     header : 'Target Delivery',
766                                     hidden : true,
767                                     sortable : true,
768                                     width : 75,
769                                     renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
770                                 },
771                                 {
772                                     xtype: 'ColumnModel',
773                                     xns: Roo.grid,
774                                     dataIndex : 'cohead_salesrep_id_salesrep_name',
775                                     header : 'Staff IC.',
776                                     sortable : true,
777                                     width : 100,
778                                     renderer : function(v,x,r) { 
779                                     
780                                         if (r.data.cohead_display_salesrep_id) {
781                                             return String.format('{0} ({1})', v, r.data.cohead_display_salesrep_id_salesrep_name);
782                                         }
783                                         return String.format('{0}', v );
784                                         
785                                         
786                                      }
787                                 },
788                                 {
789                                     xtype: 'ColumnModel',
790                                     xns: Roo.grid,
791                                     dataIndex : 'cohead_number',
792                                     header : '#order',
793                                     sortable : true,
794                                     width : 100,
795                                     renderer : function(v,x,r) {
796                                     
797                                          if (r.data.cohead_status == 'C') {
798                                               return String.format('<i qtip="closed">{0}</i>', v); 
799                                           }
800                                            if (r.data.cohead_status == 'X') {
801                                               return String.format('<s qtip="void">{0}</s>', v); 
802                                           }
803                                          return String.format('{0}', v); 
804                                      }
805                                 },
806                                 {
807                                     xtype: 'ColumnModel',
808                                     xns: Roo.grid,
809                                     dataIndex : 'cohead_cust_id_cust_number',
810                                     header : 'Customer#',
811                                     sortable : true,
812                                     width : 100,
813                                     renderer : function(v) { return String.format('{0}', v); }
814                                 },
815                                 {
816                                     xtype: 'ColumnModel',
817                                     xns: Roo.grid,
818                                     dataIndex : 'cohead_cust_id_cust_name',
819                                     header : 'Customer',
820                                     sortable : true,
821                                     width : 200,
822                                     renderer : function(v) { return String.format('{0}', v); }
823                                 },
824                                 {
825                                     xtype: 'ColumnModel',
826                                     xns: Roo.grid,
827                                     dataIndex : 'cohead_custponumber',
828                                     header : 'Cust. PO#',
829                                     width : 50,
830                                     renderer : function(v) { return String.format('{0}', v); }
831                                 },
832                                 {
833                                     xtype: 'ColumnModel',
834                                     xns: Roo.grid,
835                                     dataIndex : 'cohead_type',
836                                     header : 'Type',
837                                     width : 50,
838                                     renderer : function(v) { return String.format('{0}', v); }
839                                 },
840                                 {
841                                     xtype: 'ColumnModel',
842                                     xns: Roo.grid,
843                                     dataIndex : 'cohead_src_locations',
844                                     header : 'From',
845                                     width : 100,
846                                     renderer : function(v) { return String.format('{0}', v); }
847                                 },
848                                 {
849                                     xtype: 'ColumnModel',
850                                     xns: Roo.grid,
851                                     dataIndex : 'cohead_shiptoaddress1',
852                                     header : 'Ship to',
853                                     width : 200,
854                                     renderer : function(v) { return String.format('{0}', v); }
855                                 },
856                                 {
857                                     xtype: 'ColumnModel',
858                                     xns: Roo.grid,
859                                     dataIndex : 'cohead_terms_id_terms_descrip',
860                                     header : 'Terms',
861                                     width : 100,
862                                     renderer : function(v) { return String.format('{0}', v); }
863                                 },
864                                 {
865                                     xtype: 'ColumnModel',
866                                     xns: Roo.grid,
867                                     align : 'right',
868                                     dataIndex : 'cohead_total',
869                                     header : 'Total',
870                                     width : 100,
871                                     renderer : function(v,x,r) { 
872                                         var ret =  String.format('{0} {1}',
873                                              r.data.cohead_curr_id_curr_name, v ?   parseFloat(v).toFixed(3) : '---'
874                                          ); 
875                                          
876                                          if (parseInt(r.data.cohead_qtyordered)  != 0 && 
877                                             parseInt(r.data.cohead_unshipped) == 0 && 
878                                              parseInt(r.data.cohead_qtyunshipped) == 0 &&
879                                              parseInt(r.data.cohead_qtyuninvoiced) == 0 &&         
880                                               parseInt(r.data.cohead_unshipped) == 0 &&
881                                              parseInt(r.data.cohead_uninvoiced) == 0 
882                                          ) {
883                                             return ret;
884                                         }
885                                          
886                                          return String.format('<b style="color:red" ' + 
887                                                 'qtip="Products: {3} ({4}) &lt;BR/&gt;Unshipped: {1} ({5})&lt;BR&gt;Uninvoiced: {2} ({6})">{0}</b>',
888                                              ret, 
889                                                 r.data.cohead_unshipped, r.data.cohead_uninvoiced, r.data.cohead_subtotal,
890                                                 r.data.cohead_qtyordered, r.data.cohead_qtyunshipped, r.data.cohead_qtyuninvoiced
891                                              );
892                                          
893                                      }
894                                 }
895                             ]
896                         }
897                     },
898                     {
899                         xtype: 'ContentPanel',
900                         xns: Roo,
901                         background : false,
902                         region : 'west',
903                         items : [
904                             {
905                                 xtype: 'Form',
906                                 xns: Roo.form,
907                                 listeners : {
908                                     rendered : function (form)
909                                     {
910                                         _this.form= form;
911                                     }
912                                 },
913                                 labelAlign : 'top',
914                                 method : 'POST',
915                                 style : 'margin:5px;',
916                                 items : [
917                                     {
918                                         xtype: 'ComboBox',
919                                         xns: Roo.form,
920                                         listeners : {
921                                             select : function (combo, record, index)
922                                             {
923                                               _this.grid.footer.onClick('first');
924                                             },
925                                             render : function (_self)
926                                             {
927                                               _this.viewtypeSel = _self;
928                                             }
929                                         },
930                                         allowBlank : false,
931                                         displayField : 'value',
932                                         editable : false,
933                                         emptyText : "View type",
934                                         fieldLabel : 'View',
935                                         forceSelection : true,
936                                         listWidth : 200,
937                                         loadingText : "Searching...",
938                                         minChars : 2,
939                                         name : 'viewtype',
940                                         pageSize : 20,
941                                         qtip : "Select Action",
942                                         queryParam : 'query[action]',
943                                         selectOnFocus : true,
944                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{value}</b> </div>',
945                                         triggerAction : 'all',
946                                         typeAhead : true,
947                                         value : "MYOPEN",
948                                         valueField : 'key',
949                                         width : 150,
950                                         store : {
951                                             xtype: 'SimpleStore',
952                                             xns: Roo.data,
953                                             id : 0,
954                                             data : [
955                                               [ 'MYOPEN', 'My Open orders' ],
956                                               [ 'MYCLOSED', 'My Closed orders' ],
957                                               [ 'MYALL', 'My orders (all)' ],    
958                                               [ 'MYVOID', 'My Voided orders' ],      
959                                               [ 'OPEN', 'All Open orders' ],
960                                               [ 'CLOSED', 'All Closed orders' ],
961                                               [ 'ALL', 'All orders' ],
962                                               [ 'VOID', 'Voided orders' ],
963                                               [ 'INCOMPLETE', 'Incomplete orders' ],  
964                                               [ 'DRAFTSHIP', 'Have Un-confirmed Shipments' ],
965                                             //  [ 'SHIPPOSTBUG', 'Bugs with Posted transactions' ],  
966                                             //  [ 'SHIPQTYBUG', 'Bugs with Shipment Qty' ] ,
967                                               [ 'FIFOBUG', 'Problems with FIFO' ] 
968                                                 
969                                             ],
970                                             fields : [ 'key', 'value' ]
971                                         }
972                                     },
973                                     {
974                                         xtype: 'ComboBox',
975                                         xns: Roo.form,
976                                         listeners : {
977                                             select : function (combo, record, index)
978                                             {
979                                                 (function() { _this.grid.footer.onClick('first'); }).defer(100);
980                                             },
981                                             specialkey : function (_self, e)
982                                             {
983                                                 //Roo.log(e.getKey());
984                                                 if (e.getKey() == 13) {
985                                                     (function() { _this.grid.footer.onClick('first'); }).defer(100);
986                                                     e.stopEvent();
987                                                     _this.rsearch = true;
988                                                 }
989                                                 
990                                             },
991                                             beforequery : function (combo, query, forceAll, cancel, e)
992                                             {
993                                              
994                                                if( _this.rsearch) {
995                                                     _this.rsearch =false;
996                                                     return false;
997                                                 }
998                                              
999                                             }
1000                                         },
1001                                         allowBlank : true,
1002                                         displayField : 'cohead_number',
1003                                         editable : true,
1004                                         emptyText : "Select Order",
1005                                         fieldLabel : 'Order #',
1006                                         forceSelection : false,
1007                                         listWidth : 400,
1008                                         loadingText : "Searching...",
1009                                         minChars : 2,
1010                                         name : 'query[cohead_number]',
1011                                         pageSize : 20,
1012                                         qtip : "Select Order",
1013                                         queryParam : 'query[cohead_number]',
1014                                         selectOnFocus : true,
1015                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{cohead_number}</b> </div>',
1016                                         triggerAction : 'all',
1017                                         typeAhead : false,
1018                                         valueField : 'cohead_number',
1019                                         width : 180,
1020                                         store : {
1021                                             xtype: 'Store',
1022                                             xns: Roo.data,
1023                                             listeners : {
1024                                                 beforeload : function (_self, o){
1025                                                     o.params = o.params || {};
1026                                                     o.params['_columns'] = 'cohead_number';
1027                                                     // set more here
1028                                                 }
1029                                             },
1030                                             remoteSort : true,
1031                                             sortInfo : { direction : 'ASC', field: 'cohead_number' },
1032                                             proxy : {
1033                                                 xtype: 'HttpProxy',
1034                                                 xns: Roo.data,
1035                                                 method : 'GET',
1036                                                 url : baseURL + '/Roo/cohead.php'
1037                                             },
1038                                             reader : {
1039                                                 xtype: 'JsonReader',
1040                                                 xns: Roo.data,
1041                                                 id : 'cohead_number',
1042                                                 root : 'data',
1043                                                 totalProperty : 'total',
1044                                                 fields : ["cohead_number"]
1045                                             }
1046                                         }
1047                                     },
1048                                     {
1049                                         xtype: 'ComboBox',
1050                                         xns: Roo.form,
1051                                         listeners : {
1052                                             select : function (combo, record, index)
1053                                             {
1054                                                    (function() { _this.grid.footer.onClick('first'); }).defer(100);
1055                                             }
1056                                         },
1057                                         allowBlank : true,
1058                                         displayField : 'cust_name',
1059                                         editable : true,
1060                                         emptyText : "Select custinfo",
1061                                         fieldLabel : 'Customer',
1062                                         forceSelection : true,
1063                                         hiddenName : 'cohead_cust_id',
1064                                         listWidth : 400,
1065                                         loadingText : "Searching...",
1066                                         minChars : 2,
1067                                         name : 'cohead_cust_id_cust_name',
1068                                         pageSize : 20,
1069                                         qtip : "Select custinfo",
1070                                         queryParam : 'query[cust_name]',
1071                                         selectOnFocus : true,
1072                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{cust_name}</b>  ({cust_number})</div>',
1073                                         triggerAction : 'all',
1074                                         typeAhead : false,
1075                                         valueField : 'cust_id',
1076                                         width : 180,
1077                                         store : {
1078                                             xtype: 'Store',
1079                                             xns: Roo.data,
1080                                             sortInfo : { direction : 'ASC', field: 'cust_name' },
1081                                             remoteSort : true,
1082                                             listeners : {
1083                                                 beforeload : function (_self, o){
1084                                                     o.params = o.params || {};
1085                                                     // set more here
1086                                                 }
1087                                             },
1088                                             proxy : {
1089                                                 xtype: 'HttpProxy',
1090                                                 xns: Roo.data,
1091                                                 method : 'GET',
1092                                                 url : baseURL + '/Roo/custinfo.php'
1093                                             },
1094                                             reader : {
1095                                                 xtype: 'JsonReader',
1096                                                 xns: Roo.data,
1097                                                 id : 'cust_id',
1098                                                 root : 'data',
1099                                                 totalProperty : 'total',
1100                                                 fields : [{"name":"cust_id","type":"int"},"cust_name"]
1101                                             }
1102                                         }
1103                                     },
1104                                     {
1105                                         xtype: 'DateField',
1106                                         xns: Roo.form,
1107                                         listeners : {
1108                                             select : function (combo, date)
1109                                             {
1110                                                 _this.grid.footer.onClick('first');
1111                                             }
1112                                         },
1113                                         fieldLabel : 'From',
1114                                         format : 'Y-m-d',
1115                                         name : '_fromdate',
1116                                         width : 100
1117                                     },
1118                                     {
1119                                         xtype: 'DateField',
1120                                         xns: Roo.form,
1121                                         listeners : {
1122                                             select : function (combo, date)
1123                                             {
1124                                                 _this.grid.footer.onClick('first');
1125                                             }
1126                                         },
1127                                         fieldLabel : 'To',
1128                                         format : 'Y-m-d',
1129                                         name : '_todate',
1130                                         width : 100
1131                                     }
1132                                 ]
1133                             }
1134                         ],
1135                         toolbar : {
1136                             xtype: 'Toolbar',
1137                             xns: Roo,
1138                             items : [
1139                                 {
1140                                     xtype: 'Fill',
1141                                     xns: Roo.Toolbar
1142                                 },
1143                                 {
1144                                     xtype: 'Button',
1145                                     xns: Roo.Toolbar,
1146                                     listeners : {
1147                                         click : function (_self, e)
1148                                         {
1149                                         _this.grid.footer.onClick('first');
1150                                         }
1151                                     },
1152                                     cls : 'x-btn-icon',
1153                                     icon : rootURL + '/Pman/templates/images/search.gif'
1154                                 },
1155                                 {
1156                                     xtype: 'Button',
1157                                     xns: Roo.Toolbar,
1158                                     listeners : {
1159                                         click : function (_self, e)
1160                                         {
1161                                             _this.form.reset('');
1162                                         
1163                                             
1164                                             _this.grid.footer.onClick('first');
1165                                         }
1166                                     },
1167                                     cls : 'x-btn-icon',
1168                                     icon : rootURL + '/Pman/templates/images/edit-clear.gif'
1169                                 }
1170                             ]
1171                         }
1172                     }
1173                 ],
1174                 west : {
1175                     xtype: 'LayoutRegion',
1176                     xns: Roo,
1177                     width : '200',
1178                     split : true,
1179                     title : "Search"
1180                 },
1181                 center : {
1182                     xtype: 'LayoutRegion',
1183                     xns: Roo
1184                 }
1185             }
1186         };
1187     }
1188 });