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