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