Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Tab.XtupleSalesInvoice.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.XtupleSalesInvoice = new Roo.XComponent({
6     part     :  ["Xtuple","SalesInvoice"],
7     order    : '300-Pman.Tab.XtupleSalesInvoice',
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: 'GridPanel',
19             xns: Roo,
20             listeners : {
21                 activate : function() {
22                     _this.panel = this;
23                     if (_this.grid) {
24                         _this.grid.footer.onClick('first');
25                     }
26                 }
27             },
28             background : true,
29             fitContainer : true,
30             fitToframe : true,
31             region : 'center',
32             tableName : 'invchead',
33             title : "Invoices",
34             grid : {
35                 xtype: 'Grid',
36                 xns: Roo.grid,
37                 listeners : {
38                     render : function() 
39                     {
40                         _this.grid = this; 
41                         //_this.dialog = Pman.Dialog.FILL_IN
42                         if (_this.panel.active) {
43                            this.footer.onClick('first');
44                         }
45                     },
46                     rowdblclick : function (_self, rowIndex, e)
47                     {
48                      
49                          
50                          var d =  this.getDataSource().getAt(rowIndex).data;
51                          
52                          if (d.cohead_id) {
53                          
54                             Pman.Dialog.XtupleSalesOrder.show( {
55                                 cohead_id : d.cohead_id
56                             
57                             }, function() {
58                                 _this.grid.footer.onClick('refresh');
59                                 // updated..
60                                 Pman.Tab.XtupleSales.grid.footer.onClick('first');
61                             });  
62                             return;
63                         }
64                         
65                         // other wise not a sales order related..
66                         
67                              
68                          Pman.Dialog.XtupleInvc.show( {
69                                 _id : d.invchead_id
70                             
71                             }, function() {
72                                 _this.grid.footer.onClick('refresh');
73                                 // updated..
74                                 Pman.Tab.XtupleSales.grid.footer.onClick('first');
75                             });  
76                         
77                     }
78                 },
79                 autoExpandColumn : 'cust_name',
80                 loadMask : true,
81                 dataSource : {
82                     xtype: 'Store',
83                     xns: Roo.data,
84                     listeners : {
85                         beforeload : function (_self, o)
86                         {
87                             if (_this.ordernumber.getValue().length) {
88                                 o.params['query[invchead_ordernumber]'] = _this.ordernumber.getValue();
89                             }
90                             
91                             if (_this.invcnumber.getValue().length) {
92                                 o.params['query[invchead_invcnumber]'] = _this.invcnumber.getValue();
93                             }
94                             
95                             
96                             if (_this.customer.getValue()) {
97                                 o.params.invchead_cust_id = _this.customer.getValue();
98                             }
99                             if (_this.fromDate.getValue()) {
100                                 o.params['search[fromDate]'] = _this.fromDate.getValue().format('Y-m-d');
101                             }
102                             if (_this.toDate.getValue()) {
103                                 o.params['search[toDate]'] = _this.toDate.getValue().format('Y-m-d');
104                             }
105                             o.params._show_status = _this.status.getValue();
106                             
107                             o.params._with_salesorder = 1;
108                         }
109                     },
110                     remoteSort : true,
111                     sortInfo : { field : 'invchead_invcdate', direction: 'DESC' },
112                     proxy : {
113                         xtype: 'HttpProxy',
114                         xns: Roo.data,
115                         method : 'GET',
116                         url : baseURL + '/Roo/invchead.php'
117                     },
118                     reader : {
119                         xtype: 'JsonReader',
120                         xns: Roo.data,
121                         totalProperty : 'total',
122                         root : 'data',
123                         id : 'id',
124                         fields : [
125                             {
126                                 'name': 'invchead_ordernumber',
127                                 'type': 'string'
128                             },
129                             {
130                                 'name': 'invchead_orderdate',
131                                 'type': 'date'
132                             },
133                             {
134                                 'name': 'invchead_posted',
135                                 'type': 'boolean'
136                             },
137                             {
138                                 'name': 'invchead_printed',
139                                 'type': 'boolean'
140                             },
141                             {
142                                 'name': 'invchead_invcdate',
143                                 'type': 'date'
144                             },
145                             {
146                                 'name': 'invchead_billto_name',
147                                 'type': 'string'
148                             }
149                         ]
150                     }
151                 },
152                 footer : {
153                     xtype: 'PagingToolbar',
154                     xns: Roo,
155                     pageSize : 25,
156                     displayInfo : true,
157                     displayMsg : "Displaying invchead{0} - {1} of {2}",
158                     emptyMsg : "No invchead found",
159                     items : [
160                         {
161                             xtype: 'Button',
162                             xns: Roo.Toolbar,
163                             listeners : {
164                                 click : function (_self, e)
165                                 {
166                                     new Pman.Download({
167                                         grid: _this.grid
168                                     });
169                                     Roo.MessageBox.alert("Notice", "Download should start soon");
170                                 }
171                             },
172                             text : "Download"
173                         }
174                     ]
175                 },
176                 toolbar : {
177                     xtype: 'Toolbar',
178                     xns: Roo,
179                     items : [
180                         {
181                             xtype: 'TextField',
182                             xns: Roo.form,
183                             listeners : {
184                                 render : function (_self)
185                                 {
186                                     _this.invcnumber = _self;
187                                 },
188                                 specialkey : function (_self, e)
189                                 {
190                                     _this.grid.footer.onClick('first');
191                                 }
192                             },
193                             emptyText : "Invoice #",
194                             width : 70
195                         },
196                         {
197                             xtype: 'ComboBox',
198                             xns: Roo.form,
199                             listeners : {
200                                 render : function (_self)
201                                 {
202                                     _this.ordernumber = _self;
203                                 },
204                                 select : function (combo, record, index)
205                                 {
206                                     Roo.log('select');
207                                     _this.grid.footer.onClick('first');
208                                 }
209                             },
210                             allowBlank : true,
211                             displayField : 'invchead_ordernumber',
212                             editable : true,
213                             emptyText : "Order",
214                             fieldLabel : 'ordernumber',
215                             forceSelection : true,
216                             hiddenName : 'invchead_id',
217                             listWidth : 400,
218                             loadingText : "Searching...",
219                             minChars : 2,
220                             name : 'invchead_ordernumber',
221                             pageSize : 20,
222                             qtip : "Select invchead",
223                             queryParam : 'query[invchead_ordernumber]',
224                             selectOnFocus : true,
225                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{invchead_ordernumber}</b> </div>',
226                             triggerAction : 'all',
227                             valueField : 'invchead_ordernumber',
228                             width : 150,
229                             store : {
230                                 xtype: 'Store',
231                                 xns: Roo.data,
232                                 sortInfo : { direction : 'ASC', field: 'invchead_ordernumber' },
233                                 remoteSort : true,
234                                 listeners : {
235                                     beforeload : function (_self, o){
236                                         o.params = o.params || {};
237                                         // set more here
238                                     }
239                                 },
240                                 proxy : {
241                                     xtype: 'HttpProxy',
242                                     xns: Roo.data,
243                                     method : 'GET',
244                                     url : baseURL + '/Roo/invchead.php'
245                                 },
246                                 reader : {
247                                     xtype: 'JsonReader',
248                                     xns: Roo.data,
249                                     id : 'invchead_id',
250                                     root : 'data',
251                                     totalProperty : 'total',
252                                     fields : [{"name":"invchead_id","type":"int"},"invchead_ordernumber"]
253                                 }
254                             }
255                         },
256                         {
257                             xtype: 'ComboBox',
258                             xns: Roo.form,
259                             listeners : {
260                                 render : function (_self)
261                                 {
262                                     _this.customer = _self;
263                                 },
264                                 select : function (combo, record, index)
265                                 {
266                                     _this.grid.footer.onClick('first');
267                                 }
268                             },
269                             allowBlank : true,
270                             displayField : 'cust_name',
271                             editable : true,
272                             emptyText : "Select Customer",
273                             fieldLabel : 'cust_name',
274                             forceSelection : true,
275                             hiddenName : 'cust_id',
276                             listWidth : 400,
277                             loadingText : "Searching...",
278                             minChars : 2,
279                             name : 'cust_name',
280                             pageSize : 20,
281                             qtip : "Select custinfo",
282                             queryParam : 'query[cust_name]',
283                             selectOnFocus : true,
284                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{cust_name}</b> </div>',
285                             triggerAction : 'all',
286                             valueField : 'cust_id',
287                             width : 200,
288                             store : {
289                                 xtype: 'Store',
290                                 xns: Roo.data,
291                                 sortInfo : { direction : 'ASC', field: 'cust_name' },
292                                 remoteSort : true,
293                                 listeners : {
294                                     beforeload : function (_self, o){
295                                         o.params = o.params || {};
296                                         // set more here
297                                     }
298                                 },
299                                 proxy : {
300                                     xtype: 'HttpProxy',
301                                     xns: Roo.data,
302                                     method : 'GET',
303                                     url : baseURL + '/Roo/custinfo.php'
304                                 },
305                                 reader : {
306                                     xtype: 'JsonReader',
307                                     xns: Roo.data,
308                                     id : 'cust_id',
309                                     root : 'data',
310                                     totalProperty : 'total',
311                                     fields : [{"name":"cust_id","type":"int"},"cust_name"]
312                                 }
313                             }
314                         },
315                         {
316                             xtype: 'ComboBox',
317                             xns: Roo.form,
318                             listeners : {
319                                 render : function (_self)
320                                 {
321                                   _this.status = _self;
322                                 },
323                                 beforeselect : function (combo, record, index)
324                                 {
325                                  (function() {   _this.grid.footer.onClick('first'); }).defer(100);
326                                 }
327                             },
328                             allowBlank : false,
329                             displayField : 'fname',
330                             editable : false,
331                             fieldLabel : 'Status',
332                             hiddenName : 'status',
333                             listWidth : 200,
334                             mode : 'local',
335                             name : 'status',
336                             triggerAction : 'all',
337                             value : "A",
338                             valueField : 'ftype',
339                             width : 100,
340                             store : {
341                                 xtype: 'SimpleStore',
342                                 xns: Roo.data,
343                                 data : [ 
344                                     [ 'U', "Unpaid"],
345                                     [ 'NV' , "Not Void Only"],
346                                     [ 'V' , "Void Only"],    
347                                     [ 'A', "All"] 
348                                 ],
349                                 fields : [  'ftype', 'fname']
350                             }
351                         },
352                         {
353                             xtype: 'TextItem',
354                             xns: Roo.Toolbar,
355                             text : "From:"
356                         },
357                         {
358                             xtype: 'DateField',
359                             xns: Roo.form,
360                             listeners : {
361                                 select : function (combo, date)
362                                 {
363                                     _this.grid.footer.onClick('first');
364                                 },
365                                 render : function (_self)
366                                 {
367                                     _this.fromDate = _self;
368                                 }
369                             },
370                             format : 'Y-m-d'
371                         },
372                         {
373                             xtype: 'TextItem',
374                             xns: Roo.Toolbar,
375                             text : " To:"
376                         },
377                         {
378                             xtype: 'DateField',
379                             xns: Roo.form,
380                             listeners : {
381                                 select : function (combo, date)
382                                 {
383                                     _this.grid.footer.onClick('first');
384                                 },
385                                 render : function (_self)
386                                 {
387                                     _this.toDate = _self;
388                                 }
389                             },
390                             format : 'Y-m-d'
391                         },
392                         {
393                             xtype: 'Fill',
394                             xns: Roo.Toolbar
395                         },
396                         {
397                             xtype: 'Button',
398                             xns: Roo.Toolbar,
399                             listeners : {
400                                 click : function ()
401                                 {
402                                 
403                                     if (!Pman.hasPerm('Xtuple.InvoiceAll', 'S')) {
404                                         Roo.MessageBox.alert("Error", "You do not have permissions to do that, please contact the administrator to void invoices, or edit the sales order.");
405                                         return;
406                                     
407                                     }
408                                     
409                                     
410                                      var sel  = _this.grid.getSelectionModel().getSelected();
411                                     if (!sel) {
412                                         Roo.MessageBox.alert("Error", "Select a invoice");
413                                         return;
414                                     }
415                                     // check current status of shipment..
416                                     
417                                     Roo.MessageBox.confirm("Are you sure", "Are you sure you want to VOID that invoice?",
418                                         function(r) {
419                                             if (r != 'yes') {
420                                                 return;
421                                             }
422                                             new Pman.Request({
423                                                 mask : 'Sending',
424                                                 url : baseURL + '/Roo/invchead',
425                                                 method : 'POST',
426                                                 params : {
427                                                     invchead_id : sel.data.invchead_id,
428                                                     _void : 1
429                                                 },
430                                                 success : function() {
431                                                     _this.grid.footer.onClick('refresh');
432                                                 }
433                                             })
434                                             
435                                         }
436                                     );
437                                             
438                                             
439                                    
440                                 }
441                             },
442                             cls : 'x-btn-text-icon',
443                             text : "Void Invoice",
444                             icon : rootURL + '/Pman/templates/images/trash.gif'
445                         }
446                     ]
447                 },
448                 colModel : [
449                     {
450                         xtype: 'ColumnModel',
451                         xns: Roo.grid,
452                         align : 'right',
453                         dataIndex : 'invchead_ordernumber',
454                         header : 'Sales Order#',
455                         width : 100,
456                         renderer : function(v) { return String.format('{0}', v); }
457                     },
458                     {
459                         xtype: 'ColumnModel',
460                         xns: Roo.grid,
461                         align : 'right',
462                         dataIndex : 'invchead_invcnumber',
463                         header : 'Invoice#',
464                         width : 100,
465                         renderer : function(v,x,r) {
466                             if (r.data.invchead_void) { 
467                                 var vv = v.split('x-').shift();
468                                 return String.format('<s>{0}</s>', vv);    
469                             }
470                             return String.format('{0}', v);
471                          }
472                     },
473                     {
474                         xtype: 'ColumnModel',
475                         xns: Roo.grid,
476                         header : 'Ordered',
477                         width : 75,
478                         dataIndex : 'invchead_orderdate',
479                         renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
480                     },
481                     {
482                         xtype: 'ColumnModel',
483                         xns: Roo.grid,
484                         dataIndex : 'invchead_posted',
485                         header : 'Posted',
486                         width : 75,
487                         renderer : function(v,x,r) {     
488                          
489                             if (r.data.invchead_void) { 
490                                 return String.format('<s>VOID</s>', v);    
491                             }
492                             
493                             return String.format('{0}', v); 
494                         }
495                     },
496                     {
497                         xtype: 'ColumnModel',
498                         xns: Roo.grid,
499                         dataIndex : 'invchead_void',
500                         header : 'Void',
501                         hidden : true,
502                         width : 75,
503                         renderer : function(v,x,r) {     
504                          
505                             
506                             return String.format('{0}', v); 
507                         }
508                     },
509                     {
510                         xtype: 'ColumnModel',
511                         xns: Roo.grid,
512                         dataIndex : 'invchead_salesrep_id_salesrep_name',
513                         header : 'Sales Rep',
514                         width : 75,
515                         renderer : function(v) { return String.format('{0}', v); }
516                     },
517                     {
518                         xtype: 'ColumnModel',
519                         xns: Roo.grid,
520                         dataIndex : 'cust_salesrep_id_salesrep_name',
521                         header : 'Customer Rep',
522                         width : 75,
523                         renderer : function(v) { return String.format('{0}', v); }
524                     },
525                     {
526                         xtype: 'ColumnModel',
527                         xns: Roo.grid,
528                         dataIndex : 'invchead_printed',
529                         header : 'Printed?',
530                         hidden : true,
531                         width : 75,
532                         renderer : function(v) { return String.format('{0}', v); }
533                     },
534                     {
535                         xtype: 'ColumnModel',
536                         xns: Roo.grid,
537                         header : 'Invoiced',
538                         width : 75,
539                         dataIndex : 'invchead_invcdate',
540                         renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
541                     },
542                     {
543                         xtype: 'ColumnModel',
544                         xns: Roo.grid,
545                         dataIndex : 'cust_addr_id_addr_postalcode',
546                         header : 'Customer Postcode',
547                         width : 75,
548                         renderer : function(v) { return String.format('{0}', v); }
549                     },
550                     {
551                         xtype: 'ColumnModel',
552                         xns: Roo.grid,
553                         dataIndex : 'cust_addr_id_addr_state',
554                         header : 'Customer State',
555                         width : 75,
556                         renderer : function(v) { return String.format('{0}', v); }
557                     },
558                     {
559                         xtype: 'ColumnModel',
560                         xns: Roo.grid,
561                         dataIndex : 'cust_name',
562                         header : 'Customer',
563                         width : 200,
564                         renderer : function(v) { return String.format('{0}', v); }
565                     },
566                     {
567                         xtype: 'ColumnModel',
568                         xns: Roo.grid,
569                         dataIndex : 'invchead_curr_id_curr_symbol',
570                         header : 'Currency',
571                         width : 75,
572                         renderer : function(v) { return String.format('{0}', v ? v : '??'); }
573                     },
574                     {
575                         xtype: 'ColumnModel',
576                         xns: Roo.grid,
577                         align : 'right',
578                         dataIndex : 'invchead_total',
579                         header : 'Value',
580                         width : 75,
581                         renderer : function(v) { return v ? Roo.util.Format.usMoney( v) : ''; }
582                     },
583                     {
584                         xtype: 'ColumnModel',
585                         xns: Roo.grid,
586                         align : 'right',
587                         dataIndex : 'aropen_amount',
588                         header : 'w/Tax',
589                         width : 75,
590                         renderer : function(v) { return v ? Roo.util.Format.usMoney( v) : ''; }
591                     }
592                 ]
593             }
594         };
595     }
596 });