Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Tab.XtupleStockHistory.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.XtupleStockHistory = new Roo.XComponent({
6     part     :  ["Xtuple","StockHistory"],
7     order    : '005-Pman.Tab.XtupleStockHistory',
8     region   : 'center',
9     parent   : 'Pman.Tab.XtupleManage',
10     name     : "Pman.Tab.XtupleStockHistory",
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 : 'invhist',
33             title : "Inventory History",
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                     celldblclick : function (_self, rowIndex, colIndex, e)
47                     {
48                         var col = _this.grid.colModel.config[colIndex].dataIndex;
49                         
50                         if (col !='item_number') {
51                             return;
52                         }
53                         var r = _this.grid.ds.getAt(rowIndex).data;
54                         
55                         _this.itemsiteCombo.setValue(r.item_number);
56                         _this.grid.footer.onClick('first');
57                         
58                         
59                     }
60                 },
61                 autoExpandColumn : 'invhist_comments',
62                 loadMask : true,
63                 toolbar : {
64                     xtype: 'Toolbar',
65                     xns: Roo,
66                     items : [
67                         {
68                             xtype: 'ComboBox',
69                             xns: Roo.form,
70                             listeners : {
71                                 select : function (combo, record, index)
72                                 {
73                                   
74                                  
75                                    (function() { 
76                                      if (_this.grid) {
77                                         _this.grid.footer.onClick('first'); 
78                                     }
79                                      }).defer(100);
80                                 },
81                                 render : function (_self)
82                                 {
83                                     _this.itemsiteCombo = _self;
84                                 }
85                             },
86                             allowBlank : true,
87                             displayField : 'itemsite_item_id_item_number',
88                             editable : true,
89                             emptyText : "Select itemsite",
90                             fieldLabel : 'Item',
91                             forceSelection : true,
92                             listWidth : 400,
93                             loadingText : "Searching...",
94                             minChars : 2,
95                             name : 'itemsite_item_id_item_number',
96                             pageSize : 20,
97                             qtip : "Select itemsite",
98                             queryParam : 'query[number]',
99                             selectOnFocus : true,
100                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{itemsite_item_id_item_number}</b> {itemsite_item_id_item_descrip1}</div>',
101                             triggerAction : 'all',
102                             typeAhead : true,
103                             valueField : 'itemsite_item_id_item_number',
104                             width : 200,
105                             store : {
106                                 xtype: 'Store',
107                                 xns: Roo.data,
108                                 listeners : {
109                                     beforeload : function (_self, o){
110                                         o.params = o.params || {};
111                                         var l = _this.locationCombo.getValue();
112                                         if (l ) { 
113                                             o.params._has_invdetail_location_id = l;
114                                         }
115                                     
116                                     }
117                                 },
118                                 remoteSort : true,
119                                 sortInfo : { direction : 'ASC', field: 'id' },
120                                 proxy : {
121                                     xtype: 'HttpProxy',
122                                     xns: Roo.data,
123                                     method : 'GET',
124                                     url : baseURL + '/Roo/itemsite.php'
125                                 },
126                                 reader : {
127                                     xtype: 'JsonReader',
128                                     xns: Roo.data,
129                                     id : 'id',
130                                     root : 'data',
131                                     totalProperty : 'total',
132                                     fields : [{"name":"id","type":"int"},{"name":"itemsite_abcclass","type":"string"}]
133                                 }
134                             }
135                         },
136                         {
137                             xtype: 'ComboBox',
138                             xns: Roo.form,
139                             listeners : {
140                                 select : function (combo, record, index)
141                                 {
142                                   
143                                  
144                                    (function() { 
145                                      if (_this.grid) {
146                                         _this.grid.footer.onClick('first'); 
147                                     }
148                                      }).defer(100);
149                                 },
150                                 render : function (_self)
151                                 {
152                                     _this.locationCombo = _self;
153                                 }
154                             },
155                             allowBlank : true,
156                             displayField : 'location_descrip',
157                             editable : true,
158                             emptyText : "Select location",
159                             fieldLabel : 'location',
160                             forceSelection : true,
161                             hiddenName : 'location_id',
162                             listWidth : 400,
163                             loadingText : "Searching...",
164                             minChars : 2,
165                             name : 'location_descrip',
166                             pageSize : 200,
167                             qtip : "Select location",
168                             queryParam : 'query[location_name]',
169                             selectOnFocus : true,
170                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{location_descrip}</b> </div>',
171                             triggerAction : 'all',
172                             typeAhead : true,
173                             valueField : 'location_id',
174                             width : 200,
175                             store : {
176                                 xtype: 'Store',
177                                 xns: Roo.data,
178                                 listeners : {
179                                     beforeload : function (_self, o){
180                                         o.params = o.params || {};
181                                         o.params._has_invdetail = 1;
182                                         // set more here
183                                          var item_num =  _this.itemsiteCombo.getValue();
184                                          if (item_num.length) {
185                                             o.params._has_invdetail_item = item_num;
186                                         }
187                                         
188                                     }
189                                 },
190                                 remoteSort : true,
191                                 sortInfo : { direction : 'ASC', field: 'location_name' },
192                                 proxy : {
193                                     xtype: 'HttpProxy',
194                                     xns: Roo.data,
195                                     method : 'GET',
196                                     url : baseURL + '/Roo/location.php'
197                                 },
198                                 reader : {
199                                     xtype: 'JsonReader',
200                                     xns: Roo.data,
201                                     id : 'id',
202                                     root : 'data',
203                                     totalProperty : 'total',
204                                     fields : [{"name":"id","type":"int"},{"name":"location_name","type":"string"}]
205                                 }
206                             }
207                         },
208                         {
209                             xtype: 'ComboBox',
210                             xns: Roo.form,
211                             listeners : {
212                                 render : function (_self)
213                                 {
214                                   _this.viewtype = _self;
215                                 },
216                                 select : function (combo, record, index)
217                                 {
218                                     Roo.log('select');
219                                     _this.grid.footer.onClick('first');
220                                 }
221                             },
222                             allowBlank : false,
223                             displayField : 'fname',
224                             editable : false,
225                             hiddenName : 'status',
226                             listWidth : 200,
227                             mode : 'local',
228                             name : 'status_name',
229                             triggerAction : 'all',
230                             value : "BOTH",
231                             valueField : 'ftype',
232                             width : 150,
233                             store : {
234                                 xtype: 'SimpleStore',
235                                 xns: Roo.data,
236                                 data : [ 
237                                     [ 'BOTH', "All Transactions"],
238                                     [ 'IN' , "Incomming"],
239                                     [ 'OUT', "Outgoing"] ,
240                                     [ 'BOTHALL', "All Transactions (with voided)"]
241                                 
242                                 ],
243                                 fields : [  'ftype', 'fname']
244                             }
245                         },
246                         {
247                             xtype: 'Separator',
248                             xns: Roo.Toolbar
249                         },
250                         {
251                             xtype: 'TextItem',
252                             xns: Roo.Toolbar,
253                             text : "From"
254                         },
255                         {
256                             xtype: 'DateField',
257                             xns: Roo.form,
258                             listeners : {
259                                 render : function (_self)
260                                 {
261                                     _this.dateSel = _self;
262                                 },
263                                 select : function (combo, date)
264                                 {
265                                     _this.grid.footer.onClick('first');
266                                 }
267                             },
268                             allowBlank : true,
269                             fieldLabel : 'Date',
270                             format : 'Y-m-d',
271                             useIso : true,
272                             width : 150
273                         },
274                         {
275                             xtype: 'Separator',
276                             xns: Roo.Toolbar
277                         },
278                         {
279                             xtype: 'TextItem',
280                             xns: Roo.Toolbar,
281                             text : "To"
282                         },
283                         {
284                             xtype: 'DateField',
285                             xns: Roo.form,
286                             listeners : {
287                                 render : function (_self)
288                                 {
289                                     _this.endDateSel = _self;
290                                 },
291                                 select : function (combo, date)
292                                 {
293                                     _this.grid.footer.onClick('first');
294                                 }
295                             },
296                             allowBlank : true,
297                             fieldLabel : 'Date',
298                             format : 'Y-m-d',
299                             useIso : true,
300                             width : 150
301                         },
302                         {
303                             xtype: 'Fill',
304                             xns: Roo.Toolbar
305                         },
306                         {
307                             xtype: 'Button',
308                             xns: Roo.Toolbar,
309                             text : "Download Reports",
310                             icon : rootURL + '/Pman/templates/images/spreadsheet.gif',
311                             menu : {
312                                 xtype: 'Menu',
313                                 xns: Roo.menu,
314                                 items : [
315                                     {
316                                         xtype: 'Item',
317                                         xns: Roo.menu,
318                                         listeners : {
319                                             click : function (_self, e)
320                                             {
321                                                 if (!_this.itemsiteCombo.getValue().length  && 
322                                                     !_this.locationCombo.getValue() && 
323                                                     !_this.dateSel.getValue() && 
324                                                     !_this.endDateSel.getValue()) {
325                                                     _this.grid.ds.removeAll();
326                                                     Roo.MessageBox.alert("Error", "Nothing to download!");
327                                                     return false;
328                                                 }
329                                                 
330                                                 new Pman.Download({
331                                                     //params : {_asExcel : 1,  limit : 99999},
332                                                     grid : _this.grid,
333                                                     newWindow : 1
334                                                 });
335                                                 
336                                                 Roo.MessageBox.alert("Notice", "Report will download shortly");
337                                             }
338                                         },
339                                         text : "History"
340                                     },
341                                     {
342                                         xtype: 'Item',
343                                         xns: Roo.menu,
344                                         listeners : {
345                                             click : function (_self, e)
346                                             {
347                                                 
348                                                 var dt = _this.dateSel.getValue();
349                                                 var end_dt =           _this.endDateSel.getValue();
350                                                
351                                                 
352                                                 if(!dt){
353                                                     Roo.Msg.alert('Error', 'Please select a FROM date to download');
354                                                     return;
355                                                 }
356                                                 if(!end_dt){
357                                                     Roo.Msg.alert('Error', 'Please select a TO date to download');
358                                                     return;
359                                                 }
360                                                 
361                                                 var    params = {
362                                                     _group : 'invhist',
363                                                     _name : 'summary',
364                                                     'from_dt:text' : dt,
365                                                     'to_dt:text' : end_dt,
366                                                             
367                                                     csvCols : '*',
368                                                     csvTitles : '*',    
369                                                     limit : 9999   
370                                                     
371                                                 }
372                                                 if (  _this.locationCombo.getValue() * 1) {
373                                                           params['invdetail_location_id:number']  =  _this.locationCombo.getValue() ;
374                                                 }
375                                                 
376                                                 
377                                                 new Pman.Download({
378                                                     url : baseURL + '/Roo/Metasql',
379                                                     method : 'GET',
380                                                     params :  params
381                                                 });
382                                                 
383                                                 Roo.MessageBox.alert("Notice", "Report will download shortly");
384                                             }
385                                         },
386                                         text : "Summary of Orders/Transfers"
387                                     },
388                                     {
389                                         xtype: 'Separator',
390                                         xns: Roo.menu
391                                     },
392                                     {
393                                         xtype: 'Item',
394                                         xns: Roo.menu,
395                                         listeners : {
396                                             click : function (_self, e)
397                                             {
398                                             
399                                                 new Pman.Download({
400                                                     url : baseURL + '/Roo/Metasql',
401                                                     method : 'GET',
402                                                     params : {
403                                                         _group : 'inventory',
404                                                         _name : 'asset',
405                                                         csvCols : '*',
406                                                         csvTitles : '*', 
407                                                         limit : 9999         
408                                                         
409                                                     }
410                                                 });
411                                                 
412                                                 Roo.MessageBox.alert("Notice", "Report will download shortly");
413                                             }
414                                         },
415                                         text : "Day by Day - GL to stock comparison"
416                                     },
417                                     {
418                                         xtype: 'Item',
419                                         xns: Roo.menu,
420                                         listeners : {
421                                             click : function (_self, e)
422                                             {
423                                                 var dt = _this.dateSel.getValue();
424                                                 
425                                                 if(!dt){
426                                                     Roo.Msg.alert('Error', 'Please select a FROM date to download');
427                                                     return;
428                                                 }
429                                                 
430                                                 new Pman.Download({
431                                                     url : baseURL + '/Roo/Metasql',
432                                                     method : 'GET',
433                                                     params : {
434                                                         _group : 'inventory',
435                                                         _name : 'bydate',
436                                                         '_as_of:text' : typeof(dt) == 'string' ? dt : dt.format('Y-m-d'),
437                                                         csvCols : '*',
438                                                         csvTitles : '*', 
439                                                         limit : 9999         
440                                                         
441                                                     }
442                                                 });
443                                                 
444                                                 Roo.MessageBox.alert("Notice", "Report will download shortly");
445                                             }
446                                         },
447                                         text : "Inventory Transactions on From date"
448                                     },
449                                     {
450                                         xtype: 'Item',
451                                         xns: Roo.menu,
452                                         listeners : {
453                                             click : function (_self, e)
454                                             {
455                                                 var dt = _this.dateSel.getValue();
456                                                 
457                                                 if(!dt){
458                                                     Roo.Msg.alert('Error', 'Please select a FROM date to download');
459                                                     return;
460                                                 }
461                                                 
462                                                 new Pman.Download({
463                                                     url : baseURL + '/Roo/Metasql',
464                                                     method : 'GET',
465                                                     params : {
466                                                         _group : 'gltrans',
467                                                         _name : 'bydate',
468                                                         '_as_of:text' : typeof(dt) == 'string' ? dt : dt.format('Y-m-d'),
469                                                         csvCols : '*',
470                                                         csvTitles : '*', 
471                                                         limit : 9999         
472                                                         
473                                                     }
474                                                 });
475                                                 
476                                                 Roo.MessageBox.alert("Notice", "Report will download shortly");
477                                             }
478                                         },
479                                         text : "GL Stock Transactions on From date"
480                                     },
481                                     {
482                                         xtype: 'Separator',
483                                         xns: Roo.menu
484                                     },
485                                     {
486                                         xtype: 'Item',
487                                         xns: Roo.menu,
488                                         listeners : {
489                                             click : function (_self, e)
490                                             {
491                                                 var dt = _this.dateSel.getValue();
492                                                 var end_dt =           _this.endDateSel.getValue();
493                                                 var location_id =           _this.locationCombo.getValue() *1;
494                                                 
495                                                 if(!dt){
496                                                     Roo.Msg.alert('Error', 'Please select a FROM date to download');
497                                                     return;
498                                                 }
499                                                 if(!end_dt){
500                                                     Roo.Msg.alert('Error', 'Please select a TO date to download');
501                                                     return;
502                                                 }
503                                                  if(!location_id){
504                                                     Roo.Msg.alert('Error', 'Please select a Location to download');
505                                                     return;
506                                                 }
507                                                 new Pman.Download({
508                                                     url : baseURL + '/Roo/Metasql',
509                                                     newWindow : 1,
510                                                     method : 'GET',
511                                                     params : {
512                                                         _group : 'invdetail',
513                                                         '_name[0]' : 'opening',
514                                                         '_name[1]' : 'closing',                        
515                                                         '_name[2]' : 'byitem',
516                                                         '_name[3]' : 'bydate',     
517                                                         'location_id:number' : location_id,
518                                                         'from_dt:text' : typeof(dt) == 'string' ? dt : dt.format('Y-m-d'),
519                                                         'to_dt:text' : typeof(end_dt) == 'string' ? end_dt : end_dt.format('Y-m-d'),            
520                                                         limit : 9999         
521                                                         
522                                                     }
523                                                 });
524                                                 
525                                                 Roo.MessageBox.alert("Notice", "Report will download shortly");
526                                             }
527                                         },
528                                         text : "Consignment Detail Report"
529                                     }
530                                 ]
531                             }
532                         }
533                     ]
534                 },
535                 dataSource : {
536                     xtype: 'Store',
537                     xns: Roo.data,
538                     listeners : {
539                         beforeload : function (_self, o)
540                         {
541                             if (!_this.itemsiteCombo.getValue().length  && 
542                                 !_this.locationCombo.getValue() && 
543                                 !_this.dateSel.getValue() && 
544                                 !_this.endDateSel.getValue()) {
545                                 _this.grid.ds.removeAll();
546                                 return false;
547                             }
548                             o.params['query[item_number]'] = _this.itemsiteCombo.getValue();
549                             o.params.invdetail_location_id   = _this.locationCombo.getValue();
550                             o.params['query[viewtype]']   = _this.viewtype.getValue();    
551                             o.params._with_item =1;
552                             
553                             var start = _this.dateSel.getValue();
554                             var end = _this.endDateSel.getValue();
555                            
556                             o.params['query[dateSel]'] = typeof(start) == 'string' ? start : start.format('Y-m-d');
557                             o.params['query[endDateSel]'] = typeof(end) == 'string' ? end : end.format('Y-m-d');
558                             
559                             o.params._with_balance = 1;
560                             
561                            
562                         }
563                     },
564                     remoteSort : true,
565                     sortInfo : { field : 'invhist_transdate,invdetail_id', direction: 'DESC' },
566                     proxy : {
567                         xtype: 'HttpProxy',
568                         xns: Roo.data,
569                         method : 'GET',
570                         url : baseURL + '/Roo/invdetail.php'
571                     },
572                     reader : {
573                         xtype: 'JsonReader',
574                         xns: Roo.data,
575                         totalProperty : 'total',
576                         root : 'data',
577                         id : 'id',
578                         fields : [
579                             {
580                                 'name': 'invhist_id',
581                                 'type': 'int'
582                             },
583                             {
584                                 'name': 'invhist_itemsite_id',
585                                 'type': 'int'
586                             },
587                             {
588                                 'name': 'invhist_transdate',
589                                 'type': 'date',
590                                 'dateFormat': 'Y-m-d'
591                             },
592                             {
593                                 'name': 'invhist_transtype',
594                                 'type': 'string'
595                             },
596                             {
597                                 'name': 'invhist_invqty',
598                                 'type': 'float'
599                             },
600                             {
601                                 'name': 'invhist_invuom',
602                                 'type': 'string'
603                             },
604                             {
605                                 'name': 'invhist_ordnumber',
606                                 'type': 'string'
607                             },
608                             {
609                                 'name': 'invhist_docnumber',
610                                 'type': 'string'
611                             },
612                             {
613                                 'name': 'invhist_qoh_before',
614                                 'type': 'float'
615                             },
616                             {
617                                 'name': 'invhist_qoh_after',
618                                 'type': 'float'
619                             },
620                             {
621                                 'name': 'invhist_unitcost',
622                                 'type': 'float'
623                             },
624                             {
625                                 'name': 'invhist_acct_id',
626                                 'type': 'int'
627                             },
628                             {
629                                 'name': 'invhist_xfer_warehous_id',
630                                 'type': 'int'
631                             },
632                             {
633                                 'name': 'invhist_comments',
634                                 'type': 'string'
635                             },
636                             {
637                                 'name': 'invhist_posted',
638                                 'type': 'int'
639                             },
640                             {
641                                 'name': 'invhist_imported',
642                                 'type': 'int'
643                             },
644                             {
645                                 'name': 'invhist_hasdetail',
646                                 'type': 'int'
647                             },
648                             {
649                                 'name': 'invhist_ordtype',
650                                 'type': 'string'
651                             },
652                             {
653                                 'name': 'invhist_analyze',
654                                 'type': 'int'
655                             },
656                             {
657                                 'name': 'invhist_user',
658                                 'type': 'string'
659                             },
660                             {
661                                 'name': 'invhist_created',
662                                 'type': 'date',
663                                 'dateFormat': 'Y-m-d'
664                             },
665                             {
666                                 'name': 'invhist_costmethod',
667                                 'type': 'string'
668                             },
669                             {
670                                 'name': 'invhist_value_before',
671                                 'type': 'float'
672                             },
673                             {
674                                 'name': 'invhist_value_after',
675                                 'type': 'float'
676                             },
677                             {
678                                 'name': 'invhist_series',
679                                 'type': 'int'
680                             }
681                         ]
682                     }
683                 },
684                 footer : {
685                     xtype: 'PagingToolbar',
686                     xns: Roo,
687                     displayInfo : true,
688                     displayMsg : "Displaying invhist{0} - {1} of {2}",
689                     emptyMsg : "No invhist found",
690                     pageSize : 25,
691                     items : [
692                         {
693                             xtype: 'Button',
694                             xns: Roo.Toolbar,
695                             listeners : {
696                                 click : function (_self, e)
697                                 {
698                                    Roo.MessageBox.progress ("Syncing Fifo fill", "Sending");
699                                   
700                                    var offset = 0;
701                                    var st = new Date();
702                                    
703                                    // for a single location.
704                                    
705                                    
706                                   
707                                    var runSync=  function() {
708                                        
709                                 
710                                        
711                                        
712                                        new Pman.Request( {
713                                             url : baseURL+'/Roo/Invdetail',
714                                             method : 'GET',
715                                             timeout : 60000,
716                                             params : {
717                                                 _fifo_fill : 1,
718                                                 offset : offset,
719                                                 location_id : _this.locationCombo.getValue(),
720                                                 item_number : _this.itemsiteCombo.getValue()
721                                             },
722                                             success : function(res) {
723                                                 Roo.log(res);
724                                                 if (!res.data.total) {
725                                                     Roo.MessageBox.hide();
726                                                     return;
727                                                 }
728                                                 var el = new Date();
729                                        
730                                                 var elapsed = el - st;
731                                                 
732                                                 var total_time = (elapsed / offset) * res.data.total ;
733                                                 var remaining = (total_time - elapsed) / (1000 * 60);
734                                                 
735                                                 
736                                                 offset = res.data.offset + res.data.limit;
737                                                 Roo.MessageBox.updateProgress ( offset  / res.data.total, "Done " + offset + '/' + res.data.total + 
738                                                     " Est. complete in " + remaining.toFixed(1) + "mins");
739                                                 runSync();
740                                             }, 
741                                             failure : function() {
742                                                 Roo.MessageBox.alert("Error", "Sending failed - probably a timeout");
743                                             }
744                                             
745                                         
746                                        });
747                                    }
748                                    runSync();
749                                 }
750                             },
751                             text : "Fifo Fill"
752                         },
753                         {
754                             xtype: 'Button',
755                             xns: Roo.Toolbar,
756                             listeners : {
757                                 click : function (_self, e)
758                                 {
759                                    Roo.MessageBox.progress ("Syncing Fifo fill values", "Sending");
760                                   
761                                    var offset = 0;
762                                    var st = new Date();
763                                    
764                                    // for a single location.
765                                    
766                                    
767                                   
768                                    var runSync=  function() {
769                                        
770                                 
771                                        
772                                        
773                                        new Pman.Request( {
774                                             url : baseURL+'/Roo/Invdetail',
775                                             method : 'GET',
776                                             timeout : 60000,
777                                             params : {
778                                                 _fifo_fill : 2,
779                                                 offset : offset,
780                                                 location_id : _this.locationCombo.getValue(),
781                                                 item_number : _this.itemsiteCombo.getValue()
782                                             },
783                                             success : function(res) {
784                                                 Roo.log(res);
785                                                 if (!res.data.total) {
786                                                     Roo.MessageBox.hide();
787                                                     return;
788                                                 }
789                                                 var el = new Date();
790                                        
791                                                 var elapsed = el - st;
792                                                 
793                                                 var total_time = (elapsed / offset) * res.data.total ;
794                                                 var remaining = (total_time - elapsed) / (1000 * 60);
795                                                 
796                                                 
797                                                 offset = res.data.offset + res.data.limit;
798                                                 Roo.MessageBox.updateProgress ( offset  / res.data.total, "Done " + offset + '/' + res.data.total + 
799                                                     " Est. complete in " + remaining.toFixed(1) + "mins");
800                                                 runSync();
801                                             }, 
802                                             failure : function() {
803                                                 Roo.MessageBox.alert("Error", "Sending failed - probably a timeout");
804                                             }
805                                             
806                                         
807                                        });
808                                    }
809                                    runSync();
810                                 }
811                             },
812                             text : "Fifo Fill Values"
813                         },
814                         {
815                             xtype: 'Button',
816                             xns: Roo.Toolbar,
817                             listeners : {
818                                 click : function (_self, e)
819                                 {
820                                    Roo.MessageBox.progress ("Syncing shipvoid fill", "Sending");
821                                   
822                                    var offset = 0;
823                                    var st = new Date();
824                                    
825                                    // for a single location.
826                                    
827                                    
828                                   
829                                    var runSync=  function() {
830                                         
831                                        
832                                        new Pman.Request( {
833                                             url : baseURL+'/Roo/cohead',
834                                             method : 'GET',
835                                             timeout : 60000,
836                                             params : {
837                                                 _fill_shipvoid : 1,
838                                                 offset : offset
839                                             },
840                                             success : function(res) {
841                                                 Roo.log(res);
842                                                 if (!res.data.total) {
843                                                     Roo.MessageBox.hide();
844                                                     return;
845                                                 }
846                                                 var el = new Date();
847                                        
848                                                 var elapsed = el - st;
849                                                 
850                                                 var total_time = (elapsed / offset) * res.data.total ;
851                                                 var remaining = (total_time - elapsed) / (1000 * 60);
852                                                 
853                                                 
854                                                 offset = res.data.offset + res.data.limit;
855                                                 Roo.MessageBox.updateProgress ( offset  / res.data.total, "Done " + offset + '/' + res.data.total + 
856                                                     " Est. complete in " + remaining.toFixed(1) + "mins");
857                                                 runSync();
858                                             }, 
859                                             failure : function() {
860                                                 Roo.MessageBox.alert("Error", "Sending failed - probably a timeout");
861                                             }
862                                             
863                                         
864                                        });
865                                    }
866                                    runSync();
867                                 }
868                             },
869                             text : "Shipvoid Fill"
870                         }
871                     ]
872                 },
873                 colModel : [
874                     {
875                         xtype: 'ColumnModel',
876                         xns: Roo.grid,
877                         align : 'right',
878                         dataIndex : 'invdetail_id',
879                         header : 'Invdetail#',
880                         width : 75,
881                         renderer : function(v,x,r) { 
882                             if (r.data.invfifo_void > 0) { 
883                                 return '<s>' + v + '</s>'; 
884                             }
885                             return v;
886                          }
887                     },
888                     {
889                         xtype: 'ColumnModel',
890                         xns: Roo.grid,
891                         dataIndex : 'invhist_transdate',
892                         header : 'Date',
893                         sortable : true,
894                         width : 75,
895                         renderer : function(v,x,r) {
896                             
897                             var vv = Date.parseDate(v.split(' ')[0],'Y-m-d' );
898                             
899                             if (r.data.invfifo_void > 0) { 
900                                 return String.format('<s>{0}</s>', vv ? vv.format('d/M/Y') : '');
901                             } 
902                             
903                             return String.format('{0}', vv ? vv.format('d/M/Y') : '');
904                          }
905                     },
906                     {
907                         xtype: 'ColumnModel',
908                         xns: Roo.grid,
909                         dataIndex : 'invhist_created',
910                         header : 'Entered',
911                         hidden : true,
912                         sortable : true,
913                         width : 75,
914                         renderer : function(v) { 
915                             var vv = Date.parseDate(v.split(' ')[0],'Y-m-d' );
916                             return String.format('{0}', vv ? vv.format('d/M/Y') : '');
917                          }
918                     },
919                     {
920                         xtype: 'ColumnModel',
921                         xns: Roo.grid,
922                         dataIndex : 'item_number',
923                         header : 'Item',
924                         width : 75,
925                         renderer : function(v) { 
926                              
927                             return String.format('<b>{0}</b>', v );
928                          }
929                     },
930                     {
931                         xtype: 'ColumnModel',
932                         xns: Roo.grid,
933                         dataIndex : 'invhist_ordnumber',
934                         header : 'Order#',
935                         width : 100,
936                         renderer : function(v,x,r) {
937                         
938                         
939                              return String.format('{0}', v); }
940                     },
941                     {
942                         xtype: 'ColumnModel',
943                         xns: Roo.grid,
944                         dataIndex : 'invhist_docnumber',
945                         header : 'doc#',
946                         width : 100,
947                         renderer : function(v) { return String.format('{0}', v); }
948                     },
949                     {
950                         xtype: 'ColumnModel',
951                         xns: Roo.grid,
952                         dataIndex : 'invhist_transtype',
953                         header : 'Type',
954                         width : 50,
955                         renderer : function(v,x,r) { return String.format('{0}/{1}', v,r.data.invhist_ordtype); }
956                     },
957                     {
958                         xtype: 'ColumnModel',
959                         xns: Roo.grid,
960                         align : 'right',
961                         dataIndex : 'invhist_unitcost',
962                         header : ' unitcost',
963                         width : 50,
964                         renderer : function(v) { return String.format('{0}', v); }
965                     },
966                     {
967                         xtype: 'ColumnModel',
968                         xns: Roo.grid,
969                         dataIndex : 'location_name',
970                         header : 'Location',
971                         width : 100,
972                         renderer : function(v) { return String.format('<B>{0}</B>', v); }
973                     },
974                     {
975                         xtype: 'ColumnModel',
976                         xns: Roo.grid,
977                         align : 'right',
978                         dataIndex : 'invdetail_qty',
979                         header : 'Change',
980                         width : 50,
981                         renderer : function(v,x,r) 
982                         {
983                             if (r.data.invfifo_void > 0) { 
984                                 return String.format('<s>{0}</s>', parseInt( v)); 
985                             } 
986                             return String.format('{0}', parseInt( v)); 
987                         }
988                     },
989                     {
990                         xtype: 'ColumnModel',
991                         xns: Roo.grid,
992                         align : 'right',
993                         dataIndex : 'invdetail_balance_qty',
994                         header : 'Balance',
995                         width : 75,
996                         renderer : function(v,x,r) 
997                         {
998                             if (r.data.invfifo_void > 0) { 
999                                 return String.format('<s>{0}</s>', parseInt( v)); 
1000                             } 
1001                             return String.format('{0}', parseInt( v)); 
1002                         }
1003                     },
1004                     {
1005                         xtype: 'ColumnModel',
1006                         xns: Roo.grid,
1007                         header : 'Invhist comments',
1008                         width : 200,
1009                         dataIndex : 'invhist_comments',
1010                         renderer : function(v) { return String.format('{0}', v); }
1011                     },
1012                     {
1013                         xtype: 'ColumnModel',
1014                         xns: Roo.grid,
1015                         align : 'right',
1016                         dataIndex : 'invfifo_qty_after',
1017                         header : 'Fifo After',
1018                         width : 75,
1019                         renderer : function(v,x,r) { 
1020                             if ( r.data.invdetail_qty < 0 ) {
1021                                 return '';
1022                             }
1023                             return   (v*1).toFixed(0) ;
1024                          }
1025                     },
1026                     {
1027                         xtype: 'ColumnModel',
1028                         xns: Roo.grid,
1029                         align : 'right',
1030                         dataIndex : 'invfifo_qty_after',
1031                         header : 'Fifo After',
1032                         width : 75,
1033                         renderer : function(v,x,r) { 
1034                             if ( r.data.invdetail_qty > 0 ) {
1035                                 return '';
1036                             }
1037                             return   (v*1).toFixed(0) ;
1038                          }
1039                     },
1040                     {
1041                         xtype: 'ColumnModel',
1042                         xns: Roo.grid,
1043                         align : 'right',
1044                         dataIndex : 'invfifo_cost_before',
1045                         header : 'Fifo Cost Before',
1046                         width : 75,
1047                         renderer : function(v,x,r) { 
1048                                 if ( r.data.invdetail_qty < 0 ) {
1049                                 return '';
1050                             } 
1051                             return   (v*1).toFixed(2) ;
1052                          }
1053                     },
1054                     {
1055                         xtype: 'ColumnModel',
1056                         xns: Roo.grid,
1057                         align : 'right',
1058                         dataIndex : 'invfifo_cost_after',
1059                         header : 'Fifo Cost After',
1060                         width : 75,
1061                         renderer : function(v,x,r) { 
1062                                 if ( r.data.invdetail_qty < 0 ) {
1063                                 return '';
1064                             } 
1065                             return   (v*1).toFixed(2) ;
1066                          }
1067                     },
1068                     {
1069                         xtype: 'ColumnModel',
1070                         xns: Roo.grid,
1071                         align : 'right',
1072                         dataIndex : 'invfifo_cost_before',
1073                         header : 'Fifo Cost Before',
1074                         width : 75,
1075                         renderer : function(v,x,r) { 
1076                             if ( r.data.invdetail_qty > 0 ) {
1077                                 return '';
1078                             }
1079                             return   (v*1).toFixed(2) ;
1080                          }
1081                     },
1082                     {
1083                         xtype: 'ColumnModel',
1084                         xns: Roo.grid,
1085                         align : 'right',
1086                         dataIndex : 'invfifo_cost_after',
1087                         header : 'Fifo Cost After',
1088                         width : 75,
1089                         renderer : function(v,x,r) { 
1090                             if ( r.data.invdetail_qty > 0 ) {
1091                                 return '';
1092                             }
1093                             return   (v*1).toFixed(2) ;
1094                          }
1095                     },
1096                     {
1097                         xtype: 'ColumnModel',
1098                         xns: Roo.grid,
1099                         align : 'right',
1100                         dataIndex : 'invfifo_unitcost',
1101                         header : 'Fifo Unitcost',
1102                         width : 75,
1103                         renderer : function(v,x,r) 
1104                         {
1105                             if (r.data.invfifo_void > 0) { 
1106                                 return   '<s>' + (v*1).toFixed(2) + '</s>';
1107                             } 
1108                             return   (v*1).toFixed(2) ;
1109                         }
1110                     },
1111                     {
1112                         xtype: 'ColumnModel',
1113                         xns: Roo.grid,
1114                         align : 'right',
1115                         dataIndex : 'invfifo_landedunitcost',
1116                         header : 'Fifo Landed Unitcost',
1117                         width : 75,
1118                         renderer : function(v,x,r) { 
1119                             
1120                             var cu = ((r.data.invfifo_cost_after*1 - r.data.invfifo_cost_before*1) / Math.abs(r.data.invdetail_qty)).toFixed(2);
1121                             var lu = (v*1).toFixed(2) ;
1122                             if (cu != lu) {
1123                                 
1124                                 if (r.data.invfifo_void > 0) { 
1125                                     return   '<s><span style="color:red">' + + lu +'/' +cu + '</span></s>';
1126                                 } 
1127                                 
1128                                 return '<span style="color:red">' + lu +'/' +cu + '</span>';
1129                             }
1130                             if (r.data.invfifo_void > 0) { 
1131                                 return   '<s>' + lu + '</s>';
1132                             } 
1133                                 
1134                             return  lu;
1135                          }
1136                     }
1137                 ]
1138             }
1139         };
1140     }
1141 });