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