Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtuplePurchaseOrder.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.Dialog.XtuplePurchaseOrder = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             listeners : {
34                 show : function () 
35                 {
36                        this.layout.getRegion('center').showPanel(0);
37                 }
38             },
39             closable : false,
40             collapsible : false,
41             height : 550,
42             modal : true,
43             resizable : true,
44             title : "New Purchase Order",
45             width : 900,
46             items : [
47                 {
48                     xtype: 'ContentPanel',
49                     xns: Roo,
50                     region : 'center',
51                     title : "Order Details",
52                     items : [
53                         {
54                             xtype: 'Form',
55                             xns: Roo.form,
56                             listeners : {
57                                 actioncomplete : function(_self,action)
58                                 {
59                                     if (action.type == 'setdata') {
60                                         _this.uploadBtn.disabled = false;
61                                         if(!_this.data.pohead_id && Pman.Login.authUser.name.length){
62                                             _this.saveBtn.show();
63                                             _this.form.findField('pohead_agent_username').setValue(Pman.Login.authUser.name);
64                                             _this.form.findField('pohead_orderdate').setValue(new Date());
65                                             _this.form.findField('pohead_bg_arrival_est_day').setValue(new Date());
66                                             _this.form.findField('pohead_bg_available_est_day').setValue(new Date());
67                                             _this.form.findField('pohead_bg_available_latest_day').setValue(new Date());
68                                             return;
69                                         }
70                                         _this.dialog.setTitle("Edit Purchase Order");
71                                         var params = {
72                                             '_id' : _this.data.pohead_id
73                                         }
74                                         if(_this.data.office){
75                                             params['_roo_office'] = _this.data.office;
76                                         }
77                                         
78                                         this.load({ method: 'GET', params: params});
79                                         return;
80                                     }
81                                     if (action.type == 'load') {
82                                          _this.dontClose = false;
83                                         if(_this.data.office){
84                                             _this.uploadBtn.disabled = true;
85                                         }
86                                         _this.saveBtn.hide();
87                                         if (action.result.data.pohead_status == 'U') {
88                                             _this.saveBtn.show();
89                                         }
90                                         var cn = _this.form.findField('pohead_curr_id');
91                                         cn.setDisabled(true);
92                                         if (action.result.data.pohead_id * 1 < 1) {
93                                             cn.setDisabled(false);
94                                         }
95                                         
96                                         if(_this.grid){
97                                             _this.grid.footer.onClick('first');
98                                         }
99                                         
100                                         return;
101                                     }
102                                     if (action.type =='submit') {
103                                     
104                                 
105                                         var cid = this.findField('pohead_id').getValue()*1;
106                                         if (cid && !_this.dontClose) {
107                                         
108                                           _this.dialog.hide();
109                                         
110                                              if (_this.callback) {
111                                                 _this.callback.call(_this, _this.form.getValues());
112                                              }
113                                              _this.form.reset();
114                                              return;
115                                          }
116                                          Roo.log(action);
117                                          _this.dontClose = false;
118                                          _this.data.pohead_id = action.result.data.pohead_id;
119                                          this.fireEvent('actioncomplete', this,   { 
120                                                 type: 'setdata', 
121                                                 data: { 
122                                                     pohead_id : action.result.data.pohead_id
123                                                  } 
124                                          });
125                                 
126                                          
127                                     }
128                                 },
129                                 rendered : function (form)
130                                 {
131                                     _this.form= form;
132                                 },
133                                 actionfailed : function (_self, action)
134                                 {
135                                     _this.dialog.el.unmask();
136                                     if (action.failureType == 'client') {
137                                         Roo.MessageBox.alert("Error", "Please fill in all the required fields");
138                                     }
139                                     if (action.failureType == 'server') {
140                                         Roo.MessageBox.alert("Error", action.result.errorMsg);
141                                     }
142                                     _this.dialog.layout.getRegion('center').showPanel(0);
143                                 
144                                 }
145                             },
146                             labelWidth : 200,
147                             method : 'POST',
148                             style : 'margin:10px;',
149                             url : baseURL + '/Xtuple/Roo/Pohead.php',
150                             items : [
151                                 {
152                                     xtype: 'TextField',
153                                     xns: Roo.form,
154                                     emptyText : "Automatic",
155                                     fieldLabel : 'Order #',
156                                     name : 'pohead_number',
157                                     readOnly : true,
158                                     width : 150
159                                 },
160                                 {
161                                     xtype: 'DateField',
162                                     xns: Roo.form,
163                                     allowBlank : false,
164                                     fieldLabel : 'Order Date',
165                                     format : 'Y-m-d',
166                                     name : 'pohead_orderdate',
167                                     width : 150
168                                 },
169                                 {
170                                     xtype: 'DateField',
171                                     xns: Roo.form,
172                                     fieldLabel : 'Estimated Arrival Date',
173                                     format : 'Y-m-d',
174                                     name : 'pohead_bg_arrival_est_day',
175                                     width : 150
176                                 },
177                                 {
178                                     xtype: 'DateField',
179                                     xns: Roo.form,
180                                     fieldLabel : 'Estimated Available Date',
181                                     format : 'Y-m-d',
182                                     name : 'pohead_bg_available_est_day',
183                                     width : 150
184                                 },
185                                 {
186                                     xtype: 'DateField',
187                                     xns: Roo.form,
188                                     fieldLabel : 'Latest Estimated Available Date',
189                                     format : 'Y-m-d',
190                                     name : 'pohead_bg_available_latest_day',
191                                     width : 150
192                                 },
193                                 {
194                                     xtype: 'TextField',
195                                     xns: Roo.form,
196                                     fieldLabel : 'VA',
197                                     name : 'pohead_bg_va',
198                                     width : 150
199                                 },
200                                 {
201                                     xtype: 'TextField',
202                                     xns: Roo.form,
203                                     fieldLabel : 'Vendor',
204                                     name : 'pohead_vend_id_vend_name',
205                                     readOnly : true,
206                                     width : 250
207                                 },
208                                 {
209                                     xtype: 'ComboBox',
210                                     xns: Roo.form,
211                                     allowBlank : false,
212                                     displayField : 'fname',
213                                     editable : false,
214                                     fieldLabel : 'Status',
215                                     hiddenName : 'pohead_status',
216                                     listWidth : 200,
217                                     mode : 'local',
218                                     name : 'pohead_status',
219                                     readOnly : true,
220                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{fname}</b> </div>',
221                                     triggerAction : 'all',
222                                     value : "U",
223                                     valueField : 'ftype',
224                                     width : 250,
225                                     store : {
226                                         xtype: 'SimpleStore',
227                                         xns: Roo.data,
228                                         data : [ 
229                                             [ 'U', "Unreleased"],
230                                             [ 'O', "Open"],
231                                             [ 'C' , "Closed"]
232                                         ],
233                                         fields : [  'ftype', 'fname']
234                                     }
235                                 },
236                                 {
237                                     xtype: 'ComboBox',
238                                     xns: Roo.form,
239                                     allowBlank : false,
240                                     displayField : 'curr_name',
241                                     editable : false,
242                                     emptyText : "Select Currency",
243                                     fieldLabel : 'Currency',
244                                     forceSelection : true,
245                                     hiddenName : 'pohead_curr_id',
246                                     listWidth : 400,
247                                     loadingText : "Searching...",
248                                     minChars : 2,
249                                     name : 'pohead_curr_id_curr_name',
250                                     pageSize : 20,
251                                     qtip : "Select Currency",
252                                     queryParam : 'query[curr_name]',
253                                     selectOnFocus : true,
254                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{curr_name}</b> </div>',
255                                     triggerAction : 'all',
256                                     typeAhead : true,
257                                     valueField : 'curr_id',
258                                     width : 250,
259                                     store : {
260                                         xtype: 'Store',
261                                         xns: Roo.data,
262                                         listeners : {
263                                             beforeload : function (_self, o){
264                                                 o.params = o.params || {};
265                                             }
266                                         },
267                                         remoteSort : true,
268                                         sortInfo : { direction : 'ASC', field: 'curr_id' },
269                                         proxy : {
270                                             xtype: 'HttpProxy',
271                                             xns: Roo.data,
272                                             method : 'GET',
273                                             url : baseURL + '/Roo/curr_symbol.php'
274                                         },
275                                         reader : {
276                                             xtype: 'JsonReader',
277                                             xns: Roo.data,
278                                             id : 'curr_id',
279                                             root : 'data',
280                                             totalProperty : 'total',
281                                             fields : [
282                                                 {"name":"curr_id","type":"int"},
283                                                 {"name":"curr_name","type":"string"}
284                                             ]
285                                         }
286                                     }
287                                 },
288                                 {
289                                     xtype: 'ComboBox',
290                                     xns: Roo.form,
291                                     allowBlank : false,
292                                     displayField : 'location_name',
293                                     editable : true,
294                                     emptyText : "Select a location",
295                                     fieldLabel : 'Location',
296                                     forceSelection : true,
297                                     hiddenName : 'pohead_location_id',
298                                     listWidth : 400,
299                                     loadingText : "Searching...",
300                                     minChars : 2,
301                                     name : 'pohead_location_id_location_name',
302                                     pageSize : 200,
303                                     qtip : "Select terms",
304                                     queryParam : 'query[location_name]',
305                                     selectOnFocus : true,
306                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{location_name}</b> </div>',
307                                     triggerAction : 'all',
308                                     typeAhead : false,
309                                     valueField : 'location_id',
310                                     width : 250,
311                                     store : {
312                                         xtype: 'Store',
313                                         xns: Roo.data,
314                                         listeners : {
315                                             beforeload : function (_self, o){
316                                                 o.params = o.params || {};
317                                                 // set more here
318                                                  o.params.location_netable = 1;
319                                                  o.params._viewType = 'local';
320                                             }
321                                         },
322                                         remoteSort : true,
323                                         sortInfo : { direction : 'ASC', field: 'location_name' },
324                                         proxy : {
325                                             xtype: 'HttpProxy',
326                                             xns: Roo.data,
327                                             method : 'GET',
328                                             url : baseURL + '/Roo/location.php'
329                                         },
330                                         reader : {
331                                             xtype: 'JsonReader',
332                                             xns: Roo.data,
333                                             id : 'location_id',
334                                             root : 'data',
335                                             totalProperty : 'total',
336                                             fields : [{"name":"location_id","type":"int"},"location_name"]
337                                         }
338                                     }
339                                 },
340                                 {
341                                     xtype: 'ComboBox',
342                                     xns: Roo.form,
343                                     allowBlank : false,
344                                     displayField : 'terms_descrip',
345                                     editable : false,
346                                     emptyText : "Select Terms",
347                                     fieldLabel : 'Terms',
348                                     forceSelection : true,
349                                     hiddenName : 'pohead_terms_id',
350                                     listWidth : 400,
351                                     loadingText : "Searching...",
352                                     minChars : 2,
353                                     name : 'pohead_terms_id_terms_descrip',
354                                     pageSize : 20,
355                                     qtip : "Select Terms",
356                                     queryParam : 'query[terms_descrip]',
357                                     selectOnFocus : true,
358                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{terms_descrip}</b> </div>',
359                                     triggerAction : 'all',
360                                     typeAhead : true,
361                                     valueField : 'terms_id',
362                                     width : 250,
363                                     store : {
364                                         xtype: 'Store',
365                                         xns: Roo.data,
366                                         listeners : {
367                                             beforeload : function (_self, o){
368                                                 o.params = o.params || {};
369                                             }
370                                         },
371                                         remoteSort : true,
372                                         sortInfo : { direction : 'ASC', field: 'terms_descrip' },
373                                         proxy : {
374                                             xtype: 'HttpProxy',
375                                             xns: Roo.data,
376                                             method : 'GET',
377                                             url : baseURL + '/Roo/Terms.php'
378                                         },
379                                         reader : {
380                                             xtype: 'JsonReader',
381                                             xns: Roo.data,
382                                             id : 'terms_id',
383                                             root : 'data',
384                                             totalProperty : 'total',
385                                             fields : [
386                                                 {"name":"terms_id","type":"int"},
387                                                 {"name":"terms_descrip","type":"string"}
388                                             ]
389                                         }
390                                     }
391                                 },
392                                 {
393                                     xtype: 'ComboBox',
394                                     xns: Roo.form,
395                                     allowBlank : false,
396                                     displayField : 'taxzone_descrip',
397                                     editable : false,
398                                     emptyText : "Select Tax Zone",
399                                     fieldLabel : 'Tax Zone',
400                                     forceSelection : true,
401                                     hiddenName : 'pohead_taxzone_id',
402                                     listWidth : 400,
403                                     loadingText : "Searching...",
404                                     minChars : 2,
405                                     name : 'pohead_taxzone_id_taxzone_descrip',
406                                     pageSize : 20,
407                                     qtip : "Select Tax Zone",
408                                     queryParam : 'query[taxzone_descrip]',
409                                     selectOnFocus : true,
410                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{taxzone_descrip}</b> </div>',
411                                     triggerAction : 'all',
412                                     typeAhead : true,
413                                     valueField : 'taxzone_id',
414                                     width : 250,
415                                     store : {
416                                         xtype: 'Store',
417                                         xns: Roo.data,
418                                         listeners : {
419                                             beforeload : function (_self, o){
420                                                 o.params = o.params || {};
421                                             }
422                                         },
423                                         remoteSort : true,
424                                         sortInfo : { direction : 'ASC', field: 'taxzone_id' },
425                                         proxy : {
426                                             xtype: 'HttpProxy',
427                                             xns: Roo.data,
428                                             method : 'GET',
429                                             url : baseURL + '/Roo/Taxzone.php'
430                                         },
431                                         reader : {
432                                             xtype: 'JsonReader',
433                                             xns: Roo.data,
434                                             id : 'taxzone_id',
435                                             root : 'data',
436                                             totalProperty : 'total',
437                                             fields : [
438                                                 {"name":"taxzone_id","type":"int"},
439                                                 {"name":"taxzone_descrip","type":"string"}
440                                             ]
441                                         }
442                                     }
443                                 },
444                                 {
445                                     xtype: 'ComboBox',
446                                     xns: Roo.form,
447                                     allowBlank : true,
448                                     displayField : 'emp_name',
449                                     editable : false,
450                                     emptyText : "Select Purchasing Agent",
451                                     fieldLabel : 'Purchase Agent',
452                                     forceSelection : true,
453                                     hiddenName : 'pohead_agent_username',
454                                     listWidth : 400,
455                                     loadingText : "Searching...",
456                                     minChars : 2,
457                                     name : 'pohead_agent_username',
458                                     pageSize : 20,
459                                     qtip : "Select Purchasing Agent",
460                                     queryParam : 'query[emp_name]',
461                                     selectOnFocus : true,
462                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{emp_name}</b> </div>',
463                                     triggerAction : 'all',
464                                     typeAhead : true,
465                                     valueField : 'emp_name',
466                                     width : 250,
467                                     store : {
468                                         xtype: 'Store',
469                                         xns: Roo.data,
470                                         listeners : {
471                                             beforeload : function (_self, o){
472                                                 o.params = o.params || {};
473                                             }
474                                         },
475                                         remoteSort : true,
476                                         sortInfo : { direction : 'ASC', field: 'emp_id' },
477                                         proxy : {
478                                             xtype: 'HttpProxy',
479                                             xns: Roo.data,
480                                             method : 'GET',
481                                             url : baseURL + '/Roo/Emp.php'
482                                         },
483                                         reader : {
484                                             xtype: 'JsonReader',
485                                             xns: Roo.data,
486                                             id : 'emp_id',
487                                             root : 'data',
488                                             totalProperty : 'total',
489                                             fields : [
490                                                 {"name":"emp_id","type":"int"},
491                                                 {"name":"emp_name","type":"string"}
492                                             ]
493                                         }
494                                     }
495                                 },
496                                 {
497                                     xtype: 'TextArea',
498                                     xns: Roo.form,
499                                     fieldLabel : 'Comments',
500                                     height : 100,
501                                     name : 'pohead_comments',
502                                     width : 400
503                                 },
504                                 {
505                                     xtype: 'Hidden',
506                                     xns: Roo.form,
507                                     name : 'pohead_vend_id'
508                                 },
509                                 {
510                                     xtype: 'Hidden',
511                                     xns: Roo.form,
512                                     name : 'items'
513                                 },
514                                 {
515                                     xtype: 'Hidden',
516                                     xns: Roo.form,
517                                     name : 'pohead_id'
518                                 }
519                             ]
520                         }
521                     ]
522                 },
523                 {
524                     xtype: 'GridPanel',
525                     xns: Roo,
526                     listeners : {
527                         activate : function() {
528                             _this.panel = this;
529                             
530                             
531                             var pid = _this.form.findField('pohead_id').getValue() * 1;
532                             if (pid < 1) {
533                                 Roo.MessageBox.alert("Save First", "Please save the purchase order first, before adding items");
534                                 _this.dialog.layout.getRegion('center').showPanel(0);
535                                 return;
536                             }
537                             
538                             if (_this.grid) {
539                                 _this.grid.footer.onClick('first');
540                             }
541                         },
542                         deactivate : function (_self)
543                         {
544                              if(_this.grid){
545                                 var ar = [];
546                         
547                                 _this.grid.ds.each(function(r) {
548                                     ar.push({
549                                         poitem_id : r.data.poitem_id,
550                                         poitem_itemsite_id : r.data.poitem_itemsite_id,
551                                         poitem_unitprice : r.data.poitem_unitprice,
552                                         poitem_qty_ordered : r.data.poitem_qty_ordered
553                                     });
554                                         
555                                 });
556                                 
557                                 _this.form.findField('items').setValue(JSON.stringify(ar));
558                             }
559                             _this.dontClose = true;
560                             _this.form.doAction("submit");
561                         
562                         }
563                     },
564                     background : true,
565                     fitContainer : true,
566                     fitToframe : true,
567                     region : 'center',
568                     tableName : 'poitem',
569                     title : "Order Items",
570                     grid : {
571                         xtype: 'EditorGrid',
572                         xns: Roo.grid,
573                         listeners : {
574                             render : function() 
575                             {
576                                 _this.grid = this; 
577                                 //_this.dialog = Pman.Dialog.FILL_IN
578                                 if (_this.panel.active) {
579                                    this.footer.onClick('first');
580                                 }
581                             },
582                             beforeedit : function (e)
583                             {
584                                 var r = e.record.data.poitem_qty_received * 1;
585                                 
586                                 if(r > 0){
587                                     Roo.MessageBox.alert("Error", "This item has been receipted");
588                                     return false;
589                                 }
590                                 
591                                 var status = _this.form.findField('pohead_status').getValue();
592                                 
593                                 if(status == 'C'){
594                                     Roo.MessageBox.alert("Error", "This PO has been closed");
595                                     return false;
596                                 }
597                                 
598                                 
599                             }
600                         },
601                         autoExpandColumn : 'item_descrip1',
602                         clicksToEdit : 1,
603                         loadMask : true,
604                         dataSource : {
605                             xtype: 'Store',
606                             xns: Roo.data,
607                             listeners : {
608                                 beforeload : function (_self, o){
609                                     o.params = o.params || {};
610                                     var hid = _this.form.findField('pohead_id').getValue();
611                                     
612                                     if(!hid.length){
613                                         return false;
614                                     }
615                                     
616                                     o.params.poitem_pohead_id = hid;
617                                     o.params._with_item = 1;
618                                     o.params._roo_office = _this.data.office ? _this.data.office : baseURL.split('/').pop().substr(0,2);
619                                 
620                                 },
621                                 load : function (_self, records, options)
622                                 {
623                                     _this.grid.footer.updateSummary();
624                                 }
625                             },
626                             remoteSort : true,
627                             sortInfo : { field : 'poitem_linenumber', direction: 'ASC' },
628                             proxy : {
629                                 xtype: 'HttpProxy',
630                                 xns: Roo.data,
631                                 method : 'GET',
632                                 timeout : 90000,
633                                 url : baseURL + '/Xtuple/Roo/Poitem.php'
634                             },
635                             reader : {
636                                 xtype: 'JsonReader',
637                                 xns: Roo.data,
638                                 id : 'poitem_id',
639                                 root : 'data',
640                                 totalProperty : 'total',
641                                 fields : [
642                                     {
643                                         'name': 'poitem_id',
644                                         'type': 'int'
645                                     }
646                                 ]
647                             }
648                         },
649                         toolbar : {
650                             xtype: 'Toolbar',
651                             xns: Roo,
652                             items : [
653                                 {
654                                     xtype: 'Button',
655                                     xns: Roo.Toolbar,
656                                     listeners : {
657                                         click : function()
658                                         {
659                                             var status = _this.form.findField('pohead_status').getValue();
660                                             
661                                             if(status == 'C'){
662                                                 Roo.MessageBox.alert("Error", "This PO has been closed");
663                                                 return;
664                                             }
665                                             
666                                             var ct  =    _this.grid.ds.getCount();
667                                             
668                                             var last = ct ? _this.grid.ds.getAt(ct-1).data.poitem_linenumber * 1 + 1 : 1;
669                                             
670                                             var dt = _this.form.findField('pohead_orderdate').getValue();
671                                             
672                                             var nr = _this.grid.ds.reader.newRow({
673                                                 poitem_id : 0,
674                                                 poitem_linenumber : last,
675                                                 item_number : '',
676                                                 item_descrip1 : '',
677                                                 poitem_duedate : dt,
678                                                 poitem_qty_ordered : 1,
679                                                 poitem_unitprice : 0
680                                             });
681                                             
682                                             _this.grid.stopEditing();
683                                             _this.grid.ds.insert(_this.grid.ds.getCount(), nr); 
684                                             _this.grid.startEditing(_this.grid.ds.getCount()-1, 1);
685                                         }
686                                     },
687                                     cls : 'x-btn-text-icon',
688                                     text : "Add",
689                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
690                                 },
691                                 {
692                                     xtype: 'Button',
693                                     xns: Roo.Toolbar,
694                                     listeners : {
695                                         click : function ()
696                                         {
697                                             var status = _this.form.findField('pohead_status').getValue();
698                                             
699                                             if(status == 'C'){
700                                                 Roo.MessageBox.alert("Error", "This PO has been closed");
701                                                 return;
702                                             }
703                                             
704                                             var cs = _this.grid.getSelectionModel().getSelectedCell();
705                                             if (!cs) {
706                                                 Roo.MessageBox.alert("Error", "Select a cell");
707                                                 return;
708                                             }
709                                             _this.grid.stopEditing();
710                                             var r = _this.grid.ds.getAt(cs[0]);
711                                             
712                                             if(r.data.poitem_qty_received * 1 > 0){
713                                                 Roo.MessageBox.alert("Error", "This item has been receipted");
714                                                 return;
715                                             }
716                                             
717                                             
718                                             _this.grid.ds.remove(r);
719                                            
720                                         }
721                                     },
722                                     cls : 'x-btn-text-icon',
723                                     text : "Remove",
724                                     icon : rootURL + '/Pman/templates/images/trash.gif'
725                                 }
726                             ]
727                         },
728                         footer : {
729                             xtype: 'PagingToolbar',
730                             xns: Roo,
731                             displayInfo : true,
732                             emptyMsg : "No Item found",
733                             pageSize : 100,
734                             updateSummary : function() {
735                             \r
736                                 var f = this;\r
737                                 new Pman.Request({\r
738                                     url : baseURL + '/Xtuple/Roo/Poitem',\r
739                                     method : 'GET',\r
740                                     params : {
741                                         _roo_office : _this.data.office ? _this.data.office : baseURL.split('/').pop().substr(0,2),\r
742                                         _totals : 1,\r
743                                         poitem_pohead_id : _this.form.findField('pohead_id').getValue()\r
744                                     },\r
745                                     success : function(d) {
746                                         Roo.log(d);\r
747                                         f.displayEl.update(String.format(\r
748                                             "{0} items | Total : {1} {2}",\r
749                                             d.data[0].count_item,\r
750                                             _this.form.findField('pohead_curr_id').el.dom.value,\r
751                                             d.data[0].totals\r
752                                         ));\r
753                                             \r
754                                     }\r
755                                 });\r
756                             
757                             }
758                         },
759                         colModel : [
760                             {
761                                 xtype: 'ColumnModel',
762                                 xns: Roo.grid,
763                                 align : 'right',
764                                 dataIndex : 'poitem_linenumber',
765                                 header : 'Line#',
766                                 width : 50,
767                                 renderer : function(v) { return String.format('{0}', v); }
768                             },
769                             {
770                                 xtype: 'ColumnModel',
771                                 xns: Roo.grid,
772                                 dataIndex : 'item_number',
773                                 header : 'Item code',
774                                 width : 100,
775                                 renderer : function(v) { return String.format('{0}', v); },
776                                 editor : {
777                                     xtype: 'GridEditor',
778                                     xns: Roo.grid,
779                                     field : {
780                                         xtype: 'ComboBox',
781                                         xns: Roo.form,
782                                         listeners : {
783                                             beforeselect : function (combo, record, index)
784                                             {
785                                               var ar = _this.grid.activeEditor.record;
786                                               
787                                               (function() { 
788                                                   ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
789                                                   ar.set('poitem_itemsite_id', record.data.itemsite_id);
790                                               }).defer(100);
791                                               
792                                             }
793                                         },
794                                         allowBlank : false,
795                                         displayField : 'itemsite_item_id_item_number',
796                                         editable : true,
797                                         emptyText : "Select item",
798                                         forceSelection : true,
799                                         hiddenName : 'itemsite_item_id_item_number',
800                                         listWidth : 400,
801                                         loadingText : "Searching...",
802                                         minChars : 2,
803                                         name : 'item_number',
804                                         pageSize : 20,
805                                         qtip : "Select item",
806                                         queryParam : 'query[number]',
807                                         selectOnFocus : true,
808                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{itemsite_item_id_item_number}</b> - {itemsite_item_id_item_descrip1} </div>',
809                                         triggerAction : 'all',
810                                         typeAhead : false,
811                                         valueField : 'item_number',
812                                         store : {
813                                             xtype: 'Store',
814                                             xns: Roo.data,
815                                             listeners : {
816                                                 beforeload : function (_self, o){
817                                                     o.params = o.params || {}; 
818                                                     o.params.itemsite_posupply = 1;
819                                                 }
820                                             },
821                                             remoteSort : true,
822                                             sortInfo : { direction : 'ASC', field: 'item_number' },
823                                             proxy : {
824                                                 xtype: 'HttpProxy',
825                                                 xns: Roo.data,
826                                                 method : 'GET',
827                                                 url : baseURL + '/Roo/itemsite.php'
828                                             },
829                                             reader : {
830                                                 xtype: 'JsonReader',
831                                                 xns: Roo.data,
832                                                 id : 'itemsite_id',
833                                                 root : 'data',
834                                                 totalProperty : 'total',
835                                                 fields : [{"name":"item_id","type":"int"},"item_number"]
836                                             }
837                                         }
838                                     }
839                                 }
840                             },
841                             {
842                                 xtype: 'ColumnModel',
843                                 xns: Roo.grid,
844                                 dataIndex : 'item_descrip1',
845                                 header : 'Item description',
846                                 width : 150,
847                                 renderer : function(v) { return String.format('{0}', v); }
848                             },
849                             {
850                                 xtype: 'ColumnModel',
851                                 xns: Roo.grid,
852                                 dataIndex : 'poitem_duedate',
853                                 header : 'Due date',
854                                 width : 100,
855                                 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
856                             },
857                             {
858                                 xtype: 'ColumnModel',
859                                 xns: Roo.grid,
860                                 align : 'right',
861                                 dataIndex : 'poitem_qty_ordered',
862                                 header : 'Ordered',
863                                 width : 75,
864                                 renderer : function(v) { return String.format('{0}', v); },
865                                 editor : {
866                                     xtype: 'GridEditor',
867                                     xns: Roo.grid,
868                                     field : {
869                                         xtype: 'NumberField',
870                                         xns: Roo.form,
871                                         allowDecimals : false,
872                                         decimalPrecision : 0,
873                                         minValue : 1,
874                                         style : 'text-align:right'
875                                     }
876                                 }
877                             },
878                             {
879                                 xtype: 'ColumnModel',
880                                 xns: Roo.grid,
881                                 align : 'right',
882                                 dataIndex : 'poitem_qty_received',
883                                 header : 'Received',
884                                 width : 75,
885                                 renderer : function(v,x,r) { 
886                                     return String.format(
887                                         r.data.poitem_qty_ordered != (v-r.data.poitem_qty_returned) ? '<span style="color:red">{0}</span>':  '{0}',
888                                          v - r.data.poitem_qty_returned);
889                                 }
890                             },
891                             {
892                                 xtype: 'ColumnModel',
893                                 xns: Roo.grid,
894                                 align : 'right',
895                                 dataIndex : 'poitem_qty_vouchered',
896                                 header : 'Vouchered',
897                                 width : 65,
898                                 renderer : function(v,x,r) { 
899                                     return String.format(
900                                         r.data.poitem_qty_ordered != v ? '<span style="color:red">{0}</span>':  '{0}',
901                                          v);
902                                 }
903                             },
904                             {
905                                 xtype: 'ColumnModel',
906                                 xns: Roo.grid,
907                                 align : 'right',
908                                 dataIndex : 'poitem_unitprice',
909                                 header : 'Unit price',
910                                 width : 100,
911                                 renderer : function(v) { return String.format('{0}', (v || v == 0) ? parseFloat(v).toFixed(3) : ''); },
912                                 editor : {
913                                     xtype: 'GridEditor',
914                                     xns: Roo.grid,
915                                     field : {
916                                         xtype: 'NumberField',
917                                         xns: Roo.form,
918                                         allowBlank : false,
919                                         allowDecimals : false,
920                                         decimalPrecision : 0,
921                                         minValue : 1,
922                                         style : 'text-align:right'
923                                     }
924                                 }
925                             }
926                         ]
927                     }
928                 },
929                 {
930                     xtype: 'NestedLayoutPanel',
931                     xns: Roo,
932                     region : 'center',
933                     title : "TX",
934                     layout : {
935                         xtype: 'BorderLayout',
936                         xns: Roo,
937                         items : [
938                             {
939                                 xtype: 'GridPanel',
940                                 xns: Roo,
941                                 listeners : {
942                                     activate : function() {
943                                         _this.itempanel = this;
944                                         
945                                         
946                                         if (_this.itemgrid) {
947                                             _this.itemgrid.footer.onClick('first');
948                                         }
949                                     }
950                                 },
951                                 background : false,
952                                 fitContainer : true,
953                                 fitToframe : true,
954                                 region : 'center',
955                                 tableName : 'poitem',
956                                 title : "Items",
957                                 grid : {
958                                     xtype: 'Grid',
959                                     xns: Roo.grid,
960                                     listeners : {
961                                         render : function() 
962                                         {
963                                             _this.itemgrid = this; 
964                                             //_this.dialog = Pman.Dialog.FILL_IN
965                                             if (_this.itempanel.active) {
966                                                this.footer.onClick('first');
967                                             }
968                                         },
969                                         rowclick : function (_self, rowIndex, e)
970                                         {
971                                             
972                                             _this.gltransgrid.footer.onClick('first');
973                                         }
974                                     },
975                                     autoExpandColumn : 'item_number',
976                                     loadMask : true,
977                                     toolbar : {
978                                         xtype: 'Toolbar',
979                                         xns: Roo,
980                                         items : [
981                                             {
982                                                 xtype: 'Button',
983                                                 xns: Roo.Toolbar,
984                                                 listeners : {
985                                                     click : function (_self, e)
986                                                     {
987                                                         
988                                                          new Pman.Download({
989                                                             url : baseURL + '/Roo/Metasql',
990                                                             method : 'GET',
991                                                             timeout: 600000,
992                                                             params : {
993                                                                 _group : 'gltrans_stock',
994                                                                 _name : 'byorder',
995                                                                 'pohead_number:text' : _this.form.findField('pohead_number').getValue(),
996                                                                 csvCols : '*',
997                                                                 csvTitles : '*', 
998                                                                 limit : 9999       
999                                                             }
1000                                                         });
1001                                                     }
1002                                                 },
1003                                                 text : "PO analysis"
1004                                             }
1005                                         ]
1006                                     },
1007                                     sm : {
1008                                         xtype: 'RowSelectionModel',
1009                                         xns: Roo.grid,
1010                                         singleSelect : true
1011                                     },
1012                                     dataSource : {
1013                                         xtype: 'Store',
1014                                         xns: Roo.data,
1015                                         listeners : {
1016                                             beforeload : function (_self, o)
1017                                             {
1018                                                 o.params = o.params || {};
1019                                                 var hid = _this.form.findField('pohead_id').getValue();
1020                                                 
1021                                                 if(!hid.length){
1022                                                     return false;
1023                                                 }
1024                                                 
1025                                                 o.params.poitem_pohead_id = hid;
1026                                                 
1027                                                 o.params._with_item = 1;
1028                                                 
1029                                             },
1030                                             load : function (_self, records, options)
1031                                             {
1032                                                 _this.gltransgrid.footer.onClick('first');
1033                                             }
1034                                         },
1035                                         remoteSort : true,
1036                                         sortInfo : { field : 'poitem_id', direction: 'ASC' },
1037                                         proxy : {
1038                                             xtype: 'HttpProxy',
1039                                             xns: Roo.data,
1040                                             method : 'GET',
1041                                             url : baseURL + '/Roo/poitem.php'
1042                                         },
1043                                         reader : {
1044                                             xtype: 'JsonReader',
1045                                             xns: Roo.data,
1046                                             totalProperty : 'total',
1047                                             root : 'data',
1048                                             id : 'id',
1049                                             fields : [
1050                                                 {
1051                                                     'name': 'id',
1052                                                     'type': 'int'
1053                                                 },
1054                                                 {
1055                                                     'name': 'name',
1056                                                     'type': 'string'
1057                                                 },
1058                                                 {
1059                                                     'name': 'type',
1060                                                     'type': 'int'
1061                                                 },
1062                                                 {
1063                                                     'name': 'leader',
1064                                                     'type': 'int'
1065                                                 },
1066                                                 {
1067                                                     'name': 'leader_id',
1068                                                     'type': 'int'
1069                                                 },
1070                                                 {
1071                                                     'name': 'leader_office_id',
1072                                                     'type': 'int'
1073                                                 },
1074                                                 {
1075                                                     'name': 'leader_name',
1076                                                     'type': 'string'
1077                                                 },
1078                                                 {
1079                                                     'name': 'leader_phone',
1080                                                     'type': 'string'
1081                                                 },
1082                                                 {
1083                                                     'name': 'leader_fax',
1084                                                     'type': 'string'
1085                                                 },
1086                                                 {
1087                                                     'name': 'leader_email',
1088                                                     'type': 'string'
1089                                                 },
1090                                                 {
1091                                                     'name': 'leader_company_id',
1092                                                     'type': 'int'
1093                                                 },
1094                                                 {
1095                                                     'name': 'leader_role',
1096                                                     'type': 'string'
1097                                                 },
1098                                                 {
1099                                                     'name': 'leader_active',
1100                                                     'type': 'int'
1101                                                 },
1102                                                 {
1103                                                     'name': 'leader_remarks',
1104                                                     'type': 'string'
1105                                                 },
1106                                                 {
1107                                                     'name': 'leader_passwd',
1108                                                     'type': 'string'
1109                                                 },
1110                                                 {
1111                                                     'name': 'leader_owner_id',
1112                                                     'type': 'int'
1113                                                 },
1114                                                 {
1115                                                     'name': 'leader_lang',
1116                                                     'type': 'string'
1117                                                 },
1118                                                 {
1119                                                     'name': 'leader_no_reset_sent',
1120                                                     'type': 'int'
1121                                                 },
1122                                                 {
1123                                                     'name': 'leader_action_type',
1124                                                     'type': 'string'
1125                                                 },
1126                                                 {
1127                                                     'name': 'leader_project_id',
1128                                                     'type': 'int'
1129                                                 },
1130                                                 {
1131                                                     'name': 'leader_deleted_by',
1132                                                     'type': 'int'
1133                                                 },
1134                                                 {
1135                                                     'name': 'leader_deleted_dt',
1136                                                     'type': 'date'
1137                                                 },
1138                                                 {
1139                                                     'name': 'leader_firstname',
1140                                                     'type': 'string'
1141                                                 },
1142                                                 {
1143                                                     'name': 'leader_lastname',
1144                                                     'type': 'string'
1145                                                 },
1146                                                 {
1147                                                     'name': 'leader_name_facebook',
1148                                                     'type': 'string'
1149                                                 },
1150                                                 {
1151                                                     'name': 'leader_url_blog',
1152                                                     'type': 'string'
1153                                                 },
1154                                                 {
1155                                                     'name': 'leader_url_twitter',
1156                                                     'type': 'string'
1157                                                 },
1158                                                 {
1159                                                     'name': 'leader_url_linkedin',
1160                                                     'type': 'string'
1161                                                 },
1162                                                 {
1163                                                     'name': 'leader_crm_lead_percentage',
1164                                                     'type': 'int'
1165                                                 },
1166                                                 {
1167                                                     'name': 'leader_crm_industry_id',
1168                                                     'type': 'int'
1169                                                 },
1170                                                 {
1171                                                     'name': 'leader_crm_updated_action_id',
1172                                                     'type': 'int'
1173                                                 },
1174                                                 {
1175                                                     'name': 'leader_crm_created_action_id',
1176                                                     'type': 'int'
1177                                                 },
1178                                                 {
1179                                                     'name': 'leader_crm_type_id',
1180                                                     'type': 'int'
1181                                                 }
1182                                             ]
1183                                         }
1184                                     },
1185                                     footer : {
1186                                         xtype: 'PagingToolbar',
1187                                         xns: Roo,
1188                                         displayInfo : false,
1189                                         displayMsg : "Displaying poitem{0} - {1} of {2}",
1190                                         emptyMsg : "No item found",
1191                                         pageSize : 25
1192                                     },
1193                                     colModel : [
1194                                         {
1195                                             xtype: 'ColumnModel',
1196                                             xns: Roo.grid,
1197                                             dataIndex : 'poitem_linenumber',
1198                                             header : 'Line #',
1199                                             width : 25,
1200                                             renderer : function(v) { return String.format('{0}', v); }
1201                                         },
1202                                         {
1203                                             xtype: 'ColumnModel',
1204                                             xns: Roo.grid,
1205                                             dataIndex : 'item_number',
1206                                             header : 'Item #',
1207                                             width : 75,
1208                                             renderer : function(v) { return String.format('{0}', v); }
1209                                         },
1210                                         {
1211                                             xtype: 'ColumnModel',
1212                                             xns: Roo.grid,
1213                                             dataIndex : 'poitem_qty_ordered',
1214                                             header : 'Ordered',
1215                                             width : 50,
1216                                             renderer : function(v) { return String.format('{0}', v); }
1217                                         },
1218                                         {
1219                                             xtype: 'ColumnModel',
1220                                             xns: Roo.grid,
1221                                             dataIndex : 'poitem_qty_received',
1222                                             header : 'Received',
1223                                             width : 50,
1224                                             renderer : function(v,x,r) 
1225                                             {
1226                                                 
1227                                             
1228                                                 var recv = (v- r.data.poitem_qty_returned);
1229                                                 if (recv !=  r.data.tx_qty) {
1230                                                     return String.format('<s style="color:red;font-weight:bold">{0}</s>{1} ', recv, 
1231                                                         (r.data.tx_qty *1).toFixed(0)        ) ;      
1232                                                 }
1233                                                 return String.format('{0}', (v- r.data.poitem_qty_returned)) ;  
1234                                                 
1235                                             }
1236                                         },
1237                                         {
1238                                             xtype: 'ColumnModel',
1239                                             xns: Roo.grid,
1240                                             dataIndex : 'poitem_unitprice',
1241                                             header : 'Unit Price',
1242                                             width : 75,
1243                                             renderer : function(v,x,r) 
1244                                             {
1245                                                  
1246                                                 return String.format('{0}', (v- r.data.poitem_qty_returned) ? parseFloat(v- r.data.poitem_qty_returned).toFixed(3) : '') ;  
1247                                                 
1248                                             }
1249                                         }
1250                                     ]
1251                                 }
1252                             },
1253                             {
1254                                 xtype: 'GridPanel',
1255                                 xns: Roo,
1256                                 listeners : {
1257                                     activate : function() {
1258                                         _this.gltranspanel = this;
1259                                         //if (_this.gltransgrid) {
1260                                         //    _this.gltransgrid.footer.onClick('first');
1261                                         // }
1262                                     }
1263                                 },
1264                                 background : false,
1265                                 fitContainer : true,
1266                                 fitToframe : true,
1267                                 region : 'east',
1268                                 tableName : 'Gltrans',
1269                                 title : "Gltrans",
1270                                 grid : {
1271                                     xtype: 'Grid',
1272                                     xns: Roo.grid,
1273                                     listeners : {
1274                                         render : function() 
1275                                         {
1276                                             _this.gltransgrid = this; 
1277                                             //_this.dialog = Pman.Dialog.FILL_IN
1278                                           //  if (_this.gltranspanel.active) {
1279                                           //     this.footer.onClick('first');
1280                                           //  }
1281                                         }
1282                                     },
1283                                     autoExpandColumn : 'gltrans_notes',
1284                                     loadMask : true,
1285                                     sm : {
1286                                         xtype: 'RowSelectionModel',
1287                                         xns: Roo.grid,
1288                                         singleSelect : true
1289                                     },
1290                                     dataSource : {
1291                                         xtype: 'Store',
1292                                         xns: Roo.data,
1293                                         listeners : {
1294                                             beforeload : function (_self, o)
1295                                             {
1296                                                 o.params = o.params || {};
1297                                                 
1298                                                 var s = _this.itemgrid.getSelectionModel().getSelected();
1299                                                 if(!s){
1300                                                     this.removeAll();
1301                                                     return false;
1302                                                 }
1303                                                 
1304                                                 o.params._poview = 1;
1305                                                 o.params.gltrans_deleted = 0;
1306                                                 o.params.gltrans_doctype = 'PO';
1307                                                 o.params._linenumber = s.data.poitem_linenumber;
1308                                                 o.params._item = s.data.item_number;
1309                                                 o.params._ponumber = _this.form.findField('pohead_number').getValue();
1310                                                 
1311                                             }
1312                                         },
1313                                         remoteSort : true,
1314                                         sortInfo : { field : 'gltrans_id', direction: 'ASC' },
1315                                         proxy : {
1316                                             xtype: 'HttpProxy',
1317                                             xns: Roo.data,
1318                                             method : 'GET',
1319                                             url : baseURL + '/Roo/gltrans.php'
1320                                         },
1321                                         reader : {
1322                                             xtype: 'JsonReader',
1323                                             xns: Roo.data,
1324                                             totalProperty : 'total',
1325                                             root : 'data',
1326                                             id : 'id',
1327                                             fields : [
1328                                                 {
1329                                                     'name': 'id',
1330                                                     'type': 'int'
1331                                                 },
1332                                                 {
1333                                                     'name': 'name',
1334                                                     'type': 'string'
1335                                                 },
1336                                                 {
1337                                                     'name': 'type',
1338                                                     'type': 'int'
1339                                                 },
1340                                                 {
1341                                                     'name': 'leader',
1342                                                     'type': 'int'
1343                                                 },
1344                                                 {
1345                                                     'name': 'leader_id',
1346                                                     'type': 'int'
1347                                                 },
1348                                                 {
1349                                                     'name': 'leader_office_id',
1350                                                     'type': 'int'
1351                                                 },
1352                                                 {
1353                                                     'name': 'leader_name',
1354                                                     'type': 'string'
1355                                                 },
1356                                                 {
1357                                                     'name': 'leader_phone',
1358                                                     'type': 'string'
1359                                                 },
1360                                                 {
1361                                                     'name': 'leader_fax',
1362                                                     'type': 'string'
1363                                                 },
1364                                                 {
1365                                                     'name': 'leader_email',
1366                                                     'type': 'string'
1367                                                 },
1368                                                 {
1369                                                     'name': 'leader_company_id',
1370                                                     'type': 'int'
1371                                                 },
1372                                                 {
1373                                                     'name': 'leader_role',
1374                                                     'type': 'string'
1375                                                 },
1376                                                 {
1377                                                     'name': 'leader_active',
1378                                                     'type': 'int'
1379                                                 },
1380                                                 {
1381                                                     'name': 'leader_remarks',
1382                                                     'type': 'string'
1383                                                 },
1384                                                 {
1385                                                     'name': 'leader_passwd',
1386                                                     'type': 'string'
1387                                                 },
1388                                                 {
1389                                                     'name': 'leader_owner_id',
1390                                                     'type': 'int'
1391                                                 },
1392                                                 {
1393                                                     'name': 'leader_lang',
1394                                                     'type': 'string'
1395                                                 },
1396                                                 {
1397                                                     'name': 'leader_no_reset_sent',
1398                                                     'type': 'int'
1399                                                 },
1400                                                 {
1401                                                     'name': 'leader_action_type',
1402                                                     'type': 'string'
1403                                                 },
1404                                                 {
1405                                                     'name': 'leader_project_id',
1406                                                     'type': 'int'
1407                                                 },
1408                                                 {
1409                                                     'name': 'leader_deleted_by',
1410                                                     'type': 'int'
1411                                                 },
1412                                                 {
1413                                                     'name': 'leader_deleted_dt',
1414                                                     'type': 'date'
1415                                                 },
1416                                                 {
1417                                                     'name': 'leader_firstname',
1418                                                     'type': 'string'
1419                                                 },
1420                                                 {
1421                                                     'name': 'leader_lastname',
1422                                                     'type': 'string'
1423                                                 },
1424                                                 {
1425                                                     'name': 'leader_name_facebook',
1426                                                     'type': 'string'
1427                                                 },
1428                                                 {
1429                                                     'name': 'leader_url_blog',
1430                                                     'type': 'string'
1431                                                 },
1432                                                 {
1433                                                     'name': 'leader_url_twitter',
1434                                                     'type': 'string'
1435                                                 },
1436                                                 {
1437                                                     'name': 'leader_url_linkedin',
1438                                                     'type': 'string'
1439                                                 },
1440                                                 {
1441                                                     'name': 'leader_crm_lead_percentage',
1442                                                     'type': 'int'
1443                                                 },
1444                                                 {
1445                                                     'name': 'leader_crm_industry_id',
1446                                                     'type': 'int'
1447                                                 },
1448                                                 {
1449                                                     'name': 'leader_crm_updated_action_id',
1450                                                     'type': 'int'
1451                                                 },
1452                                                 {
1453                                                     'name': 'leader_crm_created_action_id',
1454                                                     'type': 'int'
1455                                                 },
1456                                                 {
1457                                                     'name': 'leader_crm_type_id',
1458                                                     'type': 'int'
1459                                                 }
1460                                             ]
1461                                         }
1462                                     },
1463                                     footer : {
1464                                         xtype: 'PagingToolbar',
1465                                         xns: Roo,
1466                                         displayInfo : true,
1467                                         displayMsg : "Displaying gltrans{0} - {1} of {2}",
1468                                         emptyMsg : "No gltrans found",
1469                                         pageSize : 25
1470                                     },
1471                                     toolbar : {
1472                                         xtype: 'Toolbar',
1473                                         xns: Roo,
1474                                         items : [
1475                                             {
1476                                                 xtype: 'Fill',
1477                                                 xns: Roo.Toolbar
1478                                             },
1479                                             {
1480                                                 xtype: 'Button',
1481                                                 xns: Roo.Toolbar,
1482                                                 text : "Apply fixes",
1483                                                 menu : {
1484                                                     xtype: 'Menu',
1485                                                     xns: Roo.menu,
1486                                                     items : [
1487                                                         {
1488                                                             xtype: 'Item',
1489                                                             xns: Roo.menu,
1490                                                             listeners : {
1491                                                                 click : function()
1492                                                                 {
1493                                                                    var pohead_number = _this.form.findField('pohead_number').getValue();
1494                                                                     var pohead_id = _this.form.findField('pohead_id').getValue();
1495                                                                         
1496                                                                     
1497                                                                         new Pman.Request({
1498                                                                             url : baseURL + '/Roo/pohead.php',
1499                                                                             mask : 'sending',
1500                                                                             method :'POST',
1501                                                                             params : {
1502                                                                                 pohead_id : pohead_id,
1503                                                                                 _recv_fix : 1
1504                                                                                 
1505                                                                             },
1506                                                                             success : function(res) {
1507                                                                                 Roo.MessageBox.alert('Notice', 'DONE');
1508                                                                             }
1509                                                                         });
1510                                                                     
1511                                                                     
1512                                                                     
1513                                                                     
1514                                                                     
1515                                                                 }
1516                                                             },
1517                                                             cls : 'x-btn-text-icon',
1518                                                             text : "Repost goods reciept",
1519                                                             icon : rootURL + '/Pman/templates/images/trash.gif'
1520                                                         },
1521                                                         {
1522                                                             xtype: 'Separator',
1523                                                             xns: Roo.menu
1524                                                         },
1525                                                         {
1526                                                             xtype: 'Item',
1527                                                             xns: Roo.menu,
1528                                                             listeners : {
1529                                                                 click : function()
1530                                                                 {
1531                                                                     var pohead_number = _this.form.findField('pohead_number').getValue();
1532                                                                     var pohead_id = _this.form.findField('pohead_id').getValue();
1533                                                                         
1534                                                                     var fixit = function(){
1535                                                                         new Pman.Request({
1536                                                                             url : baseURL + '/Roo/pohead.php',
1537                                                                             method :'POST',
1538                                                                             params : {
1539                                                                                 pohead_id : pohead_id,
1540                                                                                 _unitcost : 1
1541                                                                                 
1542                                                                             },
1543                                                                             success : function(res) {
1544                                                                                 Roo.MessageBox.alert('Notice', 'DONE');
1545                                                                             }
1546                                                                         });
1547                                                                     }
1548                                                                     
1549                                                                     Roo.MessageBox.confirm(
1550                                                                         "Confirm",
1551                                                                         "Are you sure to fix the unit cost of " + pohead_number + " ?",
1552                                                                         function(r) {
1553                                                                             if (r != 'yes') {
1554                                                                                 return;
1555                                                                             }
1556                                                                 
1557                                                                             fixit();
1558                                                                             return;
1559                                                                         }
1560                                                                     ); 
1561                                                                     
1562                                                                     
1563                                                                 }
1564                                                             },
1565                                                             cls : 'x-btn-text-icon',
1566                                                             text : "Fix Unit Cost",
1567                                                             icon : rootURL + '/Pman/templates/images/trash.gif'
1568                                                         },
1569                                                         {
1570                                                             xtype: 'Separator',
1571                                                             xns: Roo.menu
1572                                                         },
1573                                                         {
1574                                                             xtype: 'Item',
1575                                                             xns: Roo.menu,
1576                                                             listeners : {
1577                                                                 click : function()
1578                                                                 {
1579                                                                     var pohead_number = _this.form.findField('pohead_number').getValue();
1580                                                                     var pohead_id = _this.form.findField('pohead_id').getValue();
1581                                                                         
1582                                                                     var addv = function(){
1583                                                                         new Pman.Request({
1584                                                                             url : baseURL + '/Roo/pohead.php',
1585                                                                             method :'POST',
1586                                                                             params : {
1587                                                                                 pohead_id : pohead_id,
1588                                                                                 _variance : 1
1589                                                                                 
1590                                                                             },
1591                                                                             success : function(res) {
1592                                                                                 Roo.MessageBox.alert('Notice', 'DONE');
1593                                                                             }
1594                                                                         });
1595                                                                     }
1596                                                                     
1597                                                                     Roo.MessageBox.confirm(
1598                                                                         "Confirm",
1599                                                                         "Are you sure to add all the variance for " + pohead_number + " ?",
1600                                                                         function(r) {
1601                                                                             if (r != 'yes') {
1602                                                                                 return;
1603                                                                             }
1604                                                                 
1605                                                                             addv();
1606                                                                             return;
1607                                                                         }
1608                                                                     ); 
1609                                                                     
1610                                                                     
1611                                                                 }
1612                                                             },
1613                                                             cls : 'x-btn-text-icon',
1614                                                             text : "Add All Variance",
1615                                                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
1616                                                         },
1617                                                         {
1618                                                             xtype: 'Item',
1619                                                             xns: Roo.menu,
1620                                                             listeners : {
1621                                                                 click : function()
1622                                                                 {
1623                                                                     var s = _this.gltransgrid.getSelectionModel().getSelected();
1624                                                                     
1625                                                                     if(!s){
1626                                                                         Roo.MessageBox.alert('Error','Please select a transaction');
1627                                                                         return;
1628                                                                     }
1629                                                                     
1630                                                                     if(s.data.gltrans_misc_id != -1){
1631                                                                         Roo.MessageBox.alert('Error','Just allow to delete the variance');
1632                                                                         return;
1633                                                                     }
1634                                                                     
1635                                                                     var delit = function(){
1636                                                                         new Pman.Request({
1637                                                                             url : baseURL + '/Roo/Gltrans.php',
1638                                                                             method :'POST',
1639                                                                             params : {
1640                                                                                 gltrans_id : s.data.gltrans_id,
1641                                                                                 _del : 1
1642                                                                                 
1643                                                                             },
1644                                                                             success : function(res) {
1645                                                                                 _this.gltransgrid.footer.onClick('refresh');
1646                                                                                 
1647                                                                             }
1648                                                                         });
1649                                                                     }
1650                                                                     
1651                                                                     Roo.MessageBox.confirm(
1652                                                                         "Confirm",
1653                                                                         "Are you sure to delete ?",
1654                                                                         function(r) {
1655                                                                             if (r != 'yes') {
1656                                                                                 return;
1657                                                                             }
1658                                                                 
1659                                                                             delit();
1660                                                                             return;
1661                                                                         }
1662                                                                     ); 
1663                                                                     
1664                                                                     
1665                                                                 }
1666                                                             },
1667                                                             cls : 'x-btn-text-icon',
1668                                                             text : "Delete Variance",
1669                                                             icon : rootURL + '/Pman/templates/images/trash.gif'
1670                                                         },
1671                                                         {
1672                                                             xtype: 'Item',
1673                                                             xns: Roo.menu,
1674                                                             listeners : {
1675                                                                 click : function()
1676                                                                 {
1677                                                                     var pohead_number = _this.form.findField('pohead_number').getValue();
1678                                                                     var pohead_id = _this.form.findField('pohead_id').getValue();
1679                                                                         
1680                                                                     var delv = function(){
1681                                                                         new Pman.Request({
1682                                                                             url : baseURL + '/Roo/pohead.php',
1683                                                                             method :'POST',
1684                                                                             params : {
1685                                                                                 pohead_id : pohead_id,
1686                                                                                 _del : 1
1687                                                                                 
1688                                                                             },
1689                                                                             success : function(res) {
1690                                                                                 Roo.MessageBox.alert('Notice', 'DONE');
1691                                                                             }
1692                                                                         });
1693                                                                     }
1694                                                                     
1695                                                                     Roo.MessageBox.confirm(
1696                                                                         "Confirm",
1697                                                                         "Are you sure to delete the variance on voucher of " + pohead_number + " ?",
1698                                                                         function(r) {
1699                                                                             if (r != 'yes') {
1700                                                                                 return;
1701                                                                             }
1702                                                                 
1703                                                                             delv();
1704                                                                             return;
1705                                                                         }
1706                                                                     ); 
1707                                                                     
1708                                                                     
1709                                                                 }
1710                                                             },
1711                                                             cls : 'x-btn-text-icon',
1712                                                             text : "Delete Varinace on voucher",
1713                                                             icon : rootURL + '/Pman/templates/images/trash.gif'
1714                                                         },
1715                                                         {
1716                                                             xtype: 'Separator',
1717                                                             xns: Roo.menu
1718                                                         },
1719                                                         {
1720                                                             xtype: 'Item',
1721                                                             xns: Roo.menu,
1722                                                             listeners : {
1723                                                                 click : function()
1724                                                                 {
1725                                                                     var pohead_number = _this.form.findField('pohead_number').getValue();
1726                                                                     var pohead_id = _this.form.findField('pohead_id').getValue();
1727                                                                         
1728                                                                     var addv = function(){
1729                                                                         new Pman.Request({
1730                                                                             url : baseURL + '/Roo/pohead.php',
1731                                                                             method :'POST',
1732                                                                             params : {
1733                                                                                 pohead_id : pohead_id,
1734                                                                                 _fix_voids : 1
1735                                                                                 
1736                                                                             },
1737                                                                             success : function(res) {
1738                                                                                 Roo.MessageBox.alert('Notice', 'DONE');
1739                                                                             }
1740                                                                         });
1741                                                                     }
1742                                                                     
1743                                                                     Roo.MessageBox.confirm(
1744                                                                         "Confirm",
1745                                                                         "Are you sure to add all the fix the voids for " + pohead_number + " ?",
1746                                                                         function(r) {
1747                                                                             if (r != 'yes') {
1748                                                                                 return;
1749                                                                             }
1750                                                                 
1751                                                                             addv();
1752                                                                             return;
1753                                                                         }
1754                                                                     ); 
1755                                                                     
1756                                                                     
1757                                                                 }
1758                                                             },
1759                                                             cls : 'x-btn-text-icon',
1760                                                             text : "Recalculate voids",
1761                                                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
1762                                                         }
1763                                                     ]
1764                                                 }
1765                                             },
1766                                             {
1767                                                 xtype: 'Button',
1768                                                 xns: Roo.Toolbar,
1769                                                 listeners : {
1770                                                     click : function()
1771                                                     {
1772                                                         var s = _this.gltransgrid.selModel.getSelected();
1773                                                         if (!s) {
1774                                                             Roo.MessageBox.alert("Error", "Select an item to reverse");
1775                                                             return;
1776                                                         }
1777                                                         
1778                                                         var fixit = function(){
1779                                                             new Pman.Request({
1780                                                                 url : baseURL + '/Roo/invdetail.php',
1781                                                                 method :'POST',
1782                                                                 params : {
1783                                                                    
1784                                                                     _reverse :  s.data.invdetail_id 
1785                                                                 },
1786                                                                 success : function(res) {
1787                                                                     Roo.MessageBox.alert('Notice', 'DONE');
1788                                                                 }
1789                                                             });
1790                                                         }
1791                                                         
1792                                                         Roo.MessageBox.confirm(
1793                                                             "Confirm",
1794                                                             "Are you sure to reverse that line",
1795                                                             function(r) {
1796                                                                 if (r != 'yes') {
1797                                                                     return;
1798                                                                 }
1799                                                     
1800                                                                 fixit();
1801                                                                 return;
1802                                                             }
1803                                                         ); 
1804                                                         
1805                                                         
1806                                                     }
1807                                                 },
1808                                                 cls : 'x-btn-text-icon',
1809                                                 text : "Reverse",
1810                                                 icon : rootURL + '/Pman/templates/images/trash.gif'
1811                                             }
1812                                         ]
1813                                     },
1814                                     colModel : [
1815                                         {
1816                                             xtype: 'ColumnModel',
1817                                             xns: Roo.grid,
1818                                             dataIndex : 'gltrans_id',
1819                                             header : 'ID',
1820                                             width : 50,
1821                                             renderer : function(v) { return String.format('{0}', v); }
1822                                         },
1823                                         {
1824                                             xtype: 'ColumnModel',
1825                                             xns: Roo.grid,
1826                                             dataIndex : 'gltrans_date',
1827                                             header : 'Date',
1828                                             width : 75,
1829                                             renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
1830                                         },
1831                                         {
1832                                             xtype: 'ColumnModel',
1833                                             xns: Roo.grid,
1834                                             dataIndex : 'gltrans_docnumber',
1835                                             header : 'doc #',
1836                                             width : 80,
1837                                             renderer : function(v) { return String.format('{0}', v); }
1838                                         },
1839                                         {
1840                                             xtype: 'ColumnModel',
1841                                             xns: Roo.grid,
1842                                             align : 'right',
1843                                             dataIndex : 'location_name',
1844                                             header : 'Location',
1845                                             width : 60,
1846                                             renderer : function(v,x,r) {
1847                                               
1848                                                
1849                                                 return String.format('{0}', v); 
1850                                             
1851                                             }
1852                                         },
1853                                         {
1854                                             xtype: 'ColumnModel',
1855                                             xns: Roo.grid,
1856                                             align : 'right',
1857                                             dataIndex : 'gltrans_amount',
1858                                             header : 'Amount',
1859                                             width : 100,
1860                                             renderer : function(v,x,r) { 
1861                                              return String.format('{0}', v); 
1862                                             
1863                                             }
1864                                         },
1865                                         {
1866                                             xtype: 'ColumnModel',
1867                                             xns: Roo.grid,
1868                                             align : 'right',
1869                                             dataIndex : 'invdetail_qty',
1870                                             header : 'Qty',
1871                                             width : 60,
1872                                             renderer : function(v,x,r) {
1873                                                var f = r.data.invfifo_void * 1 ? '<s>{0}</s>' : '{0}';
1874                                                
1875                                                 return String.format(f, (v*1).toFixed(0)); 
1876                                             
1877                                             }
1878                                         },
1879                                         {
1880                                             xtype: 'ColumnModel',
1881                                             xns: Roo.grid,
1882                                             dataIndex : 'gltrans_notes',
1883                                             header : 'Notes',
1884                                             width : 100,
1885                                             renderer : function(v) { return String.format('{0}', v); }
1886                                         }
1887                                     ]
1888                                 }
1889                             }
1890                         ],
1891                         center : {
1892                             xtype: 'LayoutRegion',
1893                             xns: Roo
1894                         },
1895                         east : {
1896                             xtype: 'LayoutRegion',
1897                             xns: Roo,
1898                             split : true,
1899                             width : 550
1900                         }
1901                     }
1902                 },
1903                 {
1904                     xtype: 'NestedLayoutPanel',
1905                     xns: Roo,
1906                     region : 'center',
1907                     title : "GL Tx",
1908                     layout : {
1909                         xtype: 'BorderLayout',
1910                         xns: Roo,
1911                         items : [
1912                             {
1913                                 xtype: 'GridPanel',
1914                                 xns: Roo,
1915                                 listeners : {
1916                                     activate : function() {
1917                                         _this.gltxpanel = this;
1918                                         if (_this.gltxgrid) {
1919                                             _this.gltxgrid.footer.onClick('first');
1920                                         }
1921                                     }
1922                                 },
1923                                 background : false,
1924                                 fitContainer : true,
1925                                 fitToframe : true,
1926                                 region : 'center',
1927                                 tableName : 'invdetail',
1928                                 title : "invdetail",
1929                                 grid : {
1930                                     xtype: 'Grid',
1931                                     xns: Roo.grid,
1932                                     listeners : {
1933                                         render : function() 
1934                                         {
1935                                             _this.gltxgrid = this; 
1936                                             //_this.dialog = Pman.Dialog.FILL_IN
1937                                             if (_this.gltxpanel.active) {
1938                                                this.footer.onClick('first');
1939                                             }
1940                                         },
1941                                         cellclick : function (_self, rowIndex, columnIndex, e)
1942                                         {
1943                                             if (columnIndex > 0) {
1944                                                 return;
1945                                             }
1946                                             var rec = this.ds.getAt(rowIndex);
1947                                             rec.set('gltrans_as_summary', rec.data.gltrans_as_summary *1 ? 0 : 1);
1948                                             _this.gltxdgrid.footer.onClick('first');
1949                                         }
1950                                     },
1951                                     autoExpandColumn : 'gltrans_accnt_id_accnt_descrip',
1952                                     loadMask : true,
1953                                     sm : {
1954                                         xtype: 'RowSelectionModel',
1955                                         xns: Roo.grid,
1956                                         listeners : {
1957                                             selectionchange : function (_self)
1958                                             {
1959                                                 _this.gltxdgrid.footer.onClick('first');;
1960                                             }
1961                                         },
1962                                         singleSelect : true
1963                                     },
1964                                     dataSource : {
1965                                         xtype: 'Store',
1966                                         xns: Roo.data,
1967                                         listeners : {
1968                                             beforeload : function (_self, o)
1969                                             {
1970                                                 o.params.pohead_id = _this.form.findField('pohead_id').getValue();
1971                                                 if (! o.params.pohead_id ) {
1972                                                     this.removeAll();
1973                                                     return false;
1974                                                 }
1975                                                 o.params._split_sales = _this.glsalesbtn.pressed ? 1 : 0;
1976                                             },
1977                                             load : function (_self, records, options)
1978                                             {
1979                                              _this.gltxdgrid.footer.onClick('first');
1980                                             }
1981                                         },
1982                                         remoteSort : true,
1983                                         sortInfo : { field : 'item_number', direction: 'ASC' },
1984                                         proxy : {
1985                                             xtype: 'HttpProxy',
1986                                             xns: Roo.data,
1987                                             method : 'GET',
1988                                             url : baseURL + '/Roo/gltrans.php'
1989                                         },
1990                                         reader : {
1991                                             xtype: 'JsonReader',
1992                                             xns: Roo.data,
1993                                             totalProperty : 'total',
1994                                             root : 'data',
1995                                             id : 'id',
1996                                             fields : [
1997                                                 {
1998                                                     'name': 'invdetail_id',
1999                                                     'type': 'int'
2000                                                 },
2001                                                 {
2002                                                     'name': 'invdetail_transtype',
2003                                                     'type': 'string'
2004                                                 },
2005                                                 {
2006                                                     'name': 'invdetail_invhist_id',
2007                                                     'type': 'int'
2008                                                 },
2009                                                 {
2010                                                     'name': 'invdetail_location_id',
2011                                                     'type': 'int'
2012                                                 },
2013                                                 {
2014                                                     'name': 'invdetail_qty',
2015                                                     'type': 'float'
2016                                                 },
2017                                                 {
2018                                                     'name': 'invdetail_comments',
2019                                                     'type': 'string'
2020                                                 },
2021                                                 {
2022                                                     'name': 'invdetail_qty_before',
2023                                                     'type': 'float'
2024                                                 },
2025                                                 {
2026                                                     'name': 'invdetail_qty_after',
2027                                                     'type': 'float'
2028                                                 },
2029                                                 {
2030                                                     'name': 'invdetail_invcitem_id',
2031                                                     'type': 'int'
2032                                                 },
2033                                                 {
2034                                                     'name': 'invdetail_expiration',
2035                                                     'type': 'date',
2036                                                     'dateFormat': 'Y-m-d'
2037                                                 },
2038                                                 {
2039                                                     'name': 'invdetail_warrpurc',
2040                                                     'type': 'date',
2041                                                     'dateFormat': 'Y-m-d'
2042                                                 },
2043                                                 {
2044                                                     'name': 'invdetail_ls_id',
2045                                                     'type': 'int'
2046                                                 }
2047                                             ]
2048                                         }
2049                                     },
2050                                     footer : {
2051                                         xtype: 'PagingToolbar',
2052                                         xns: Roo,
2053                                         displayInfo : true,
2054                                         displayMsg : "Displaying invdetail{0} - {1} of {2}",
2055                                         emptyMsg : "No invdetail found",
2056                                         pageSize : 9999,
2057                                         items : [
2058                                             {
2059                                                 xtype: 'Button',
2060                                                 xns: Roo.Toolbar,
2061                                                 listeners : {
2062                                                     render : function (_self)
2063                                                     {
2064                                                         _this.glsalesbtn = _self;
2065                                                     },
2066                                                     click : function (_self, e)
2067                                                     {
2068                                                         (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
2069                                                     }
2070                                                 },
2071                                                 enableToggle : true,
2072                                                 pressed : true,
2073                                                 text : "Split sales"
2074                                             }
2075                                         ]
2076                                     },
2077                                     colModel : [
2078                                         {
2079                                             xtype: 'ColumnModel',
2080                                             xns: Roo.grid,
2081                                             dataIndex : 'gltrans_as_summary',
2082                                             header : 'Summary',
2083                                             width : 50,
2084                                             renderer : function(v,x,r) { 
2085                                                 
2086                                                 var state = v*1   ?  '-checked' : '';
2087                                                                                 
2088                                                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
2089                                              }
2090                                         },
2091                                         {
2092                                             xtype: 'ColumnModel',
2093                                             xns: Roo.grid,
2094                                             dataIndex : 'gltrans_accnt_id_accnt_descrip',
2095                                             header : 'Account',
2096                                             width : 75,
2097                                             renderer : function(v) { return String.format('{0}', v); }
2098                                         },
2099                                         {
2100                                             xtype: 'ColumnModel',
2101                                             xns: Roo.grid,
2102                                             align : 'right',
2103                                             dataIndex : 'gltrans_amount_credit',
2104                                             header : 'Credit',
2105                                             width : 75,
2106                                             renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); }
2107                                         },
2108                                         {
2109                                             xtype: 'ColumnModel',
2110                                             xns: Roo.grid,
2111                                             align : 'right',
2112                                             dataIndex : 'gltrans_amount_debit',
2113                                             header : 'Debit',
2114                                             width : 75,
2115                                             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }
2116                                         },
2117                                         {
2118                                             xtype: 'ColumnModel',
2119                                             xns: Roo.grid,
2120                                             align : 'right',
2121                                             dataIndex : 'gltrans_amount_total',
2122                                             header : 'Sum',
2123                                             width : 75,
2124                                             renderer : function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); }
2125                                         },
2126                                         {
2127                                             xtype: 'ColumnModel',
2128                                             xns: Roo.grid,
2129                                             align : 'right',
2130                                             dataIndex : 'gltrans_amount_total_unposted',
2131                                             header : 'Unposted',
2132                                             width : 75,
2133                                             renderer : function(v) { return String.format('<span style="color:red">{0}</span>', Roo.util.Format.number(v,3)); }
2134                                         }
2135                                     ]
2136                                 }
2137                             },
2138                             {
2139                                 xtype: 'GridPanel',
2140                                 xns: Roo,
2141                                 listeners : {
2142                                     activate : function() {
2143                                         _this.gltxdpanel = this;
2144                                         if (_this.gltxdgrid) {
2145                                             _this.gltxdgrid.footer.onClick('first');
2146                                         }
2147                                     }
2148                                 },
2149                                 background : false,
2150                                 fitContainer : true,
2151                                 fitToframe : true,
2152                                 region : 'east',
2153                                 tableName : 'invdetail',
2154                                 title : "invdetail",
2155                                 grid : {
2156                                     xtype: 'Grid',
2157                                     xns: Roo.grid,
2158                                     listeners : {
2159                                         render : function() 
2160                                         {
2161                                             _this.gltxdgrid = this; 
2162                                             //_this.dialog = Pman.Dialog.FILL_IN
2163                                             if (_this.gltxdpanel.active) {
2164                                                this.footer.onClick('first');
2165                                             }
2166                                         },
2167                                         cellclick : function (_self, ri, ci, e)
2168                                         {
2169                                             
2170                                               var deleteSel = function() {
2171                                             
2172                                                 new Pman.Request({
2173                                                     mask : "Reversing",
2174                                                     url : baseURL + '/Roo/gltrans',
2175                                                     method : 'POST',
2176                                                     params : {  
2177                                                         _void : 1,
2178                                                         gltrans_id : rec.data.gltrans_id
2179                                                         
2180                                                     }, 
2181                                                     success : function() {
2182                                                         rec.set('gltrans_posted', false);
2183                                                         rec.set('gltrans_deleted', true);
2184                                                         rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
2185                                                        _this.gltxgrid.footer.onClick('first');
2186                                                     }
2187                                                 });
2188                                             
2189                                             }
2190                                             var undeleteSel = function() {
2191                                             
2192                                                 new Pman.Request({
2193                                                     mask : "Reversing",
2194                                                     url : baseURL + '/Roo/gltrans',
2195                                                     method : 'POST',
2196                                                     params : {  
2197                                                         _unvoid : 1,
2198                                                         gltrans_id : rec.data.gltrans_id
2199                                                         
2200                                                     }, 
2201                                                     success : function() {
2202                                                         rec.set('gltrans_posted', true);
2203                                                         rec.set('gltrans_deleted', false);
2204                                                         rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
2205                                                        _this.gltxgrid.footer.onClick('first');
2206                                                     }
2207                                                 });
2208                                             
2209                                             }
2210                                             
2211                                             var di = this.colModel.config[ci].dataIndex;
2212                                             if (di != 'gltrans_posted') {
2213                                                 return;
2214                                             }
2215                                             
2216                                             
2217                                             
2218                                             var rec = this.ds.getAt(ri);
2219                                             if (rec.data.gltrans_deleted) {
2220                                             
2221                                                  Roo.MessageBox.confirm(
2222                                                     "Confirm", 
2223                                                     "This should only be used by System Administrators - are you sure you know what you are doing!",
2224                                                     function(x) {
2225                                                         if (x != 'yes') {
2226                                                             return;
2227                                                         }
2228                                                         undeleteSel();
2229                                                     }
2230                                                 );
2231                                             
2232                                                 return false;
2233                                             }
2234                                         
2235                                             
2236                                             
2237                                             if (!rec.data.gltrans_posted) {
2238                                         
2239                                                 
2240                                                 
2241                                                 new Pman.Request({
2242                                                     method : 'POST',
2243                                                     url : baseURL + '/Roo/gltrans',
2244                                                     mask : "Posting",
2245                                                     params : {
2246                                                         _post : 1,
2247                                                         gltrans_id : rec.data.gltrans_id
2248                                                     },
2249                                                     success : function (res)
2250                                                     {
2251                                                         rec.set('gltrans_posted', true);
2252                                                         _this.gltxgrid.footer.onClick('first');
2253                                                     
2254                                                     }
2255                                                 
2256                                                 
2257                                                 });
2258                                                 return;
2259                                             }
2260                                             
2261                                             // we have a posted transaction.
2262                                             // only allow recalled to be deleted..
2263                                             if (!rec.data.gltrans_notes.match(/(Recall|Ship Order)/)) {
2264                                                 return false;
2265                                             }
2266                                             
2267                                             
2268                                          
2269                                             
2270                                             
2271                                         
2272                                             Roo.MessageBox.confirm(
2273                                                 "Confirm", 
2274                                                 "This should only be used by System Administrators - are you sure you know what you are doing!",
2275                                                 function(x) {
2276                                                     if (x != 'yes') {
2277                                                         return;
2278                                                     }
2279                                                     deleteSel();
2280                                                 }
2281                                             );
2282                                                   
2283                                             
2284                                             
2285                                         }
2286                                     },
2287                                     autoExpandColumn : 'gltrans_notes',
2288                                     loadMask : true,
2289                                     toolbar : {
2290                                         xtype: 'Toolbar',
2291                                         xns: Roo,
2292                                         items : [
2293                                             {
2294                                                 xtype: 'Button',
2295                                                 xns: Roo.Toolbar,
2296                                                 listeners : {
2297                                                     render : function (_self)
2298                                                     {
2299                                                         _this.glvoidshow = _self;
2300                                                     },
2301                                                     click : function (_self, e)
2302                                                     {
2303                                                         (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
2304                                                     }
2305                                                 },
2306                                                 enableToggle : true,
2307                                                 pressed : true,
2308                                                 text : "Hide Void"
2309                                             },
2310                                             {
2311                                                 xtype: 'Fill',
2312                                                 xns: Roo.Toolbar
2313                                             },
2314                                             {
2315                                                 xtype: 'Button',
2316                                                 xns: Roo.Toolbar,
2317                                                 listeners : {
2318                                                     click : function (_self, e)
2319                                                     {
2320                                                         new Pman.Request( {
2321                                                             url : baseURL + '/Roo/Gltrans',
2322                                                             method : 'GET',
2323                                                             mask:  'sending',
2324                                                             params : {
2325                                                                 pohead_id : _this.form.findField('pohead_id').getValue(),
2326                                                                 _autovoid : 1
2327                                                             },
2328                                                             success : function() {
2329                                                                 _this.gltxpanel.footer.onClick('first');
2330                                                             }
2331                                                                 
2332                                                         
2333                                                         });
2334                                                     }
2335                                                 },
2336                                                 text : "AutoVoid"
2337                                             }
2338                                         ]
2339                                     },
2340                                     dataSource : {
2341                                         xtype: 'Store',
2342                                         xns: Roo.data,
2343                                         listeners : {
2344                                             beforeload : function (_self, o)
2345                                             {
2346                                                 o.params.pohead_id = _this.form.findField('pohead_id').getValue();
2347                                                 var s = _this.gltxgrid.selModel.getSelected();
2348                                                 if (!s) { 
2349                                                     this.removeAll();
2350                                                     return false;
2351                                                 }
2352                                                 o.params.gltrans_accnt_id = s.data.gltrans_accnt_id;
2353                                                 o.params.gltrans_is_ship = s.data.gltrans_is_ship;
2354                                                 o.params.gltrans_as_summary =     s.data.gltrans_as_summary;
2355                                                  o.params._hide_void = _this.glvoidshow.pressed ? 1 : 0;
2356                                                 //glvoidshow
2357                                                 
2358                                             }
2359                                         },
2360                                         remoteSort : true,
2361                                         sortInfo : { field : 'gltrans_docnumber', direction: 'ASC' },
2362                                         proxy : {
2363                                             xtype: 'HttpProxy',
2364                                             xns: Roo.data,
2365                                             method : 'GET',
2366                                             url : baseURL + '/Roo/gltrans.php'
2367                                         },
2368                                         reader : {
2369                                             xtype: 'JsonReader',
2370                                             xns: Roo.data,
2371                                             totalProperty : 'total',
2372                                             root : 'data',
2373                                             id : 'id',
2374                                             fields : [
2375                                                 {
2376                                                     'name': 'invdetail_id',
2377                                                     'type': 'int'
2378                                                 },
2379                                                 {
2380                                                     'name': 'invdetail_transtype',
2381                                                     'type': 'string'
2382                                                 },
2383                                                 {
2384                                                     'name': 'invdetail_invhist_id',
2385                                                     'type': 'int'
2386                                                 },
2387                                                 {
2388                                                     'name': 'invdetail_location_id',
2389                                                     'type': 'int'
2390                                                 },
2391                                                 {
2392                                                     'name': 'invdetail_qty',
2393                                                     'type': 'float'
2394                                                 },
2395                                                 {
2396                                                     'name': 'invdetail_comments',
2397                                                     'type': 'string'
2398                                                 },
2399                                                 {
2400                                                     'name': 'invdetail_qty_before',
2401                                                     'type': 'float'
2402                                                 },
2403                                                 {
2404                                                     'name': 'invdetail_qty_after',
2405                                                     'type': 'float'
2406                                                 },
2407                                                 {
2408                                                     'name': 'invdetail_invcitem_id',
2409                                                     'type': 'int'
2410                                                 },
2411                                                 {
2412                                                     'name': 'invdetail_expiration',
2413                                                     'type': 'date',
2414                                                     'dateFormat': 'Y-m-d'
2415                                                 },
2416                                                 {
2417                                                     'name': 'invdetail_warrpurc',
2418                                                     'type': 'date',
2419                                                     'dateFormat': 'Y-m-d'
2420                                                 },
2421                                                 {
2422                                                     'name': 'invdetail_ls_id',
2423                                                     'type': 'int'
2424                                                 }
2425                                             ]
2426                                         }
2427                                     },
2428                                     footer : {
2429                                         xtype: 'PagingToolbar',
2430                                         xns: Roo,
2431                                         displayInfo : true,
2432                                         displayMsg : "Displaying invdetail{0} - {1} of {2}",
2433                                         emptyMsg : "No invdetail found",
2434                                         pageSize : 9999,
2435                                         items : [
2436                                             {
2437                                                 xtype: 'Button',
2438                                                 xns: Roo.Toolbar,
2439                                                 listeners : {
2440                                                     click : function (_self, e)
2441                                                     {
2442                                                         new Pman.Download( {
2443                                                             grid : _this.gltxdgrid
2444                                                         
2445                                                         });
2446                                                     }
2447                                                 },
2448                                                 text : "Download"
2449                                             }
2450                                         ]
2451                                     },
2452                                     colModel : [
2453                                         {
2454                                             xtype: 'ColumnModel',
2455                                             xns: Roo.grid,
2456                                             dataIndex : 'gltrans_id',
2457                                             header : 'Ref#',
2458                                             sortable : true,
2459                                             width : 75,
2460                                             renderer : function(v) { return String.format('{0}', v ); }
2461                                         },
2462                                         {
2463                                             xtype: 'ColumnModel',
2464                                             xns: Roo.grid,
2465                                             dataIndex : 'gltrans_date',
2466                                             header : 'Date',
2467                                             width : 75,
2468                                             renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
2469                                         },
2470                                         {
2471                                             xtype: 'ColumnModel',
2472                                             xns: Roo.grid,
2473                                             dataIndex : 'gltrans_docnumber',
2474                                             header : 'Doc#',
2475                                             width : 75,
2476                                             renderer : function(v,x,r) { 
2477                                             
2478                                                 var style = '';
2479                                                 if (r.data.gltrans_misc_id > 0 && (r.data.invdetail_id *1) < 1) {
2480                                                     style = ' style="color:red;font-weight:bold"';
2481                                                }
2482                                                 if (r.data.gltrans_deleted) {
2483                                                    return String.format('<s'+style+'>{0}</s>', v);     
2484                                                 }
2485                                                 return String.format('<span' + style + '>{0}</span>', v); 
2486                                             }
2487                                         },
2488                                         {
2489                                             xtype: 'ColumnModel',
2490                                             xns: Roo.grid,
2491                                             dataIndex : 'gltrans_source',
2492                                             header : 'Source',
2493                                             width : 50,
2494                                             renderer : function(v) { return String.format('{0}', v); }
2495                                         },
2496                                         {
2497                                             xtype: 'ColumnModel',
2498                                             xns: Roo.grid,
2499                                             dataIndex : 'gltrans_notes',
2500                                             header : 'Notes',
2501                                             width : 75,
2502                                             renderer : function(v) { return String.format('{0}', v); }
2503                                         },
2504                                         {
2505                                             xtype: 'ColumnModel',
2506                                             xns: Roo.grid,
2507                                             align : 'right',
2508                                             dataIndex : 'gltrans_amount',
2509                                             header : 'Amount',
2510                                             width : 75,
2511                                             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }
2512                                         },
2513                                         {
2514                                             xtype: 'ColumnModel',
2515                                             xns: Roo.grid,
2516                                             dataIndex : 'gltrans_posted',
2517                                             header : 'Posted',
2518                                             width : 50,
2519                                             renderer : function(v,x,r) { 
2520                                                 
2521                                                 var state = v   ?  '-checked' : '';
2522                                                                                 
2523                                                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
2524                                              }
2525                                         }
2526                                     ]
2527                                 }
2528                             }
2529                         ],
2530                         center : {
2531                             xtype: 'LayoutRegion',
2532                             xns: Roo
2533                         },
2534                         east : {
2535                             xtype: 'LayoutRegion',
2536                             xns: Roo,
2537                             split : true,
2538                             width : 500
2539                         }
2540                     }
2541                 }
2542             ],
2543             center : {
2544                 xtype: 'LayoutRegion',
2545                 xns: Roo,
2546                 alwaysShowTabs : true,
2547                 tabPosition : 'top',
2548                 toolbar : {
2549                     xtype: 'Toolbar',
2550                     xns: Roo,
2551                     items : [
2552                         {
2553                             xtype: 'Fill',
2554                             xns: Roo.Toolbar
2555                         },
2556                         {
2557                             xtype: 'Button',
2558                             xns: Roo.Toolbar,
2559                             listeners : {
2560                                 click : function ()
2561                                 {
2562                                     var hid = _this.form.findField('pohead_id').getValue();
2563                                 
2564                                     if(!hid.length){
2565                                         Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2566                                         return false;
2567                                     }
2568                                 
2569                                     
2570                                     if (!_this.grid) {
2571                                         _dialog.layout.showPanel(1);
2572                                         doit.defer(500);
2573                                         return;
2574                                     }
2575                                     
2576                                     
2577                                     
2578                                     var doit = function () { 
2579                                         new Pman.Download({
2580                                             grid : _this.grid
2581                                         });
2582                                     }
2583                                     doit();
2584                                             
2585                                    
2586                                 }
2587                             },
2588                             cls : 'x-btn-text-icon',
2589                             text : "Download Purchase Order Items (Excel)",
2590                             icon : rootURL + '/Pman/templates/images/save.gif'
2591                         },
2592                         {
2593                             xtype: 'Button',
2594                             xns: Roo.Toolbar,
2595                             listeners : {
2596                                 render : function (_self)
2597                                 {
2598                                     _this.uploadBtn = _self;
2599                                 }
2600                             },
2601                             text : "Upload Purchase Order",
2602                             menu : {
2603                                 xtype: 'Menu',
2604                                 xns: Roo.menu,
2605                                 items : [
2606                                     {
2607                                         xtype: 'Item',
2608                                         xns: Roo.menu,
2609                                         listeners : {
2610                                             click : function (_self, e)
2611                                             {
2612                                                 var hid = _this.form.findField('pohead_id').getValue();
2613                                                 
2614                                                 if(!hid.length){
2615                                                     Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2616                                                     return false;
2617                                                 }
2618                                                 Pman.Dialog.Image.show(
2619                                                    {
2620                                                         timeout : 60000,
2621                                                         _url : baseURL+'/Xtuple/Import/PurchaseOrder?' + Roo.urlEncode({'pohead_id' : hid})
2622                                                     
2623                                                    },
2624                                                    function () {
2625                                                         if(_this.grid){
2626                                                             _this.grid.footer.onClick('first');
2627                                                         }
2628                                                         Roo.MessageBox.alert("Notice", 'UPLOADED');
2629                                                    }
2630                                                );
2631                                             }
2632                                         },
2633                                         text : "Upload Standard Excel"
2634                                     },
2635                                     {
2636                                         xtype: 'Item',
2637                                         xns: Roo.menu,
2638                                         listeners : {
2639                                             click : function (_self, e)
2640                                             {
2641                                             
2642                                                 var hid = _this.form.findField('pohead_id').getValue();
2643                                                 
2644                                                 if(!hid.length){
2645                                                     Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2646                                                     return false;
2647                                                 }
2648                                                 
2649                                                Pman.Dialog.Image.show(
2650                                                {
2651                                                     _url : baseURL+'/Xtuple/Import/AUPurchaseOrder?' + Roo.urlEncode({'pohead_id' :hid})
2652                                                     
2653                                                },
2654                                                function (data) {
2655                                                    if(_this.grid){
2656                                                         _this.grid.footer.onClick('first');
2657                                                    }
2658                                                    Roo.MessageBox.alert("Notice", 'IMPORTED');
2659                                             
2660                                                });
2661                                             }
2662                                         },
2663                                         text : "Upload AU Import Excel"
2664                                     }
2665                                 ]
2666                             }
2667                         }
2668                     ]
2669                 }
2670             },
2671             buttons : [
2672                 {
2673                     xtype: 'Button',
2674                     xns: Roo,
2675                     listeners : {
2676                         click : function (_self, e)
2677                         {
2678                             _this.dialog.hide();
2679                         }
2680                     },
2681                     text : "Cancel"
2682                 },
2683                 {
2684                     xtype: 'Button',
2685                     xns: Roo,
2686                     listeners : {
2687                         click : function (_self, e)
2688                         {
2689                             if(_this.grid){
2690                                 var ar = [];
2691                                 var err = false;
2692                                 _this.grid.ds.each(function(r) {
2693                                     if(r.data.poitem_unitprice < 1){
2694                                         err = true;
2695                                         return;
2696                                     }
2697                                     ar.push({
2698                                         poitem_id : r.data.poitem_id,
2699                                         poitem_itemsite_id : r.data.poitem_itemsite_id,
2700                                         poitem_unitprice : r.data.poitem_unitprice,
2701                                         poitem_qty_ordered : r.data.poitem_qty_ordered
2702                                     });
2703                                         
2704                                 });
2705                          
2706                                 if(err){
2707                                     Roo.MessageBox.alert('Error','Unit Price does not allow $0' );
2708                                     return;
2709                                 }   
2710                                        
2711                                 _this.form.findField('items').setValue(JSON.stringify(ar));
2712                             }
2713                                 
2714                             _this.form.doAction("submit");
2715                         
2716                         },
2717                         render : function (_self)
2718                         {
2719                             _this.saveBtn = _self;
2720                         }
2721                     },
2722                     text : "Save"
2723                 }
2724             ]
2725         });
2726     }
2727 };