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