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