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