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