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