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