Pman.Dialog.XtuplePurchaseOrder.bjs
[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                                         allowDecimals : false,
919                                         decimalPrecision : 0,
920                                         minValue : 1,
921                                         style : 'text-align:right'
922                                     }
923                                 }
924                             }
925                         ]
926                     }
927                 },
928                 {
929                     xtype: 'NestedLayoutPanel',
930                     xns: Roo,
931                     region : 'center',
932                     title : "TX",
933                     layout : {
934                         xtype: 'BorderLayout',
935                         xns: Roo,
936                         items : [
937                             {
938                                 xtype: 'GridPanel',
939                                 xns: Roo,
940                                 listeners : {
941                                     activate : function() {
942                                         _this.itempanel = this;
943                                         
944                                         
945                                         if (_this.itemgrid) {
946                                             _this.itemgrid.footer.onClick('first');
947                                         }
948                                     }
949                                 },
950                                 background : false,
951                                 fitContainer : true,
952                                 fitToframe : true,
953                                 region : 'center',
954                                 tableName : 'poitem',
955                                 title : "Items",
956                                 grid : {
957                                     xtype: 'Grid',
958                                     xns: Roo.grid,
959                                     listeners : {
960                                         render : function() 
961                                         {
962                                             _this.itemgrid = this; 
963                                             //_this.dialog = Pman.Dialog.FILL_IN
964                                             if (_this.itempanel.active) {
965                                                this.footer.onClick('first');
966                                             }
967                                         },
968                                         rowclick : function (_self, rowIndex, e)
969                                         {
970                                             
971                                             _this.gltransgrid.footer.onClick('first');
972                                         }
973                                     },
974                                     autoExpandColumn : 'item_number',
975                                     loadMask : true,
976                                     toolbar : {
977                                         xtype: 'Toolbar',
978                                         xns: Roo,
979                                         items : [
980                                             {
981                                                 xtype: 'Button',
982                                                 xns: Roo.Toolbar,
983                                                 listeners : {
984                                                     click : function (_self, e)
985                                                     {
986                                                         
987                                                          new Pman.Download({
988                                                             url : baseURL + '/Roo/Metasql',
989                                                             method : 'GET',
990                                                             timeout: 600000,
991                                                             params : {
992                                                                 _group : 'gltrans_stock',
993                                                                 _name : 'byorder',
994                                                                 'pohead_number:text' : _this.form.findField('pohead_number').getValue(),
995                                                                 csvCols : '*',
996                                                                 csvTitles : '*', 
997                                                                 limit : 9999       
998                                                             }
999                                                         });
1000                                                     }
1001                                                 },
1002                                                 text : "PO analysis"
1003                                             }
1004                                         ]
1005                                     },
1006                                     sm : {
1007                                         xtype: 'RowSelectionModel',
1008                                         xns: Roo.grid,
1009                                         singleSelect : true
1010                                     },
1011                                     dataSource : {
1012                                         xtype: 'Store',
1013                                         xns: Roo.data,
1014                                         listeners : {
1015                                             beforeload : function (_self, o)
1016                                             {
1017                                                 o.params = o.params || {};
1018                                                 var hid = _this.form.findField('pohead_id').getValue();
1019                                                 
1020                                                 if(!hid.length){
1021                                                     return false;
1022                                                 }
1023                                                 
1024                                                 o.params.poitem_pohead_id = hid;
1025                                                 
1026                                                 o.params._with_item = 1;
1027                                                 
1028                                             },
1029                                             load : function (_self, records, options)
1030                                             {
1031                                                 _this.gltransgrid.footer.onClick('first');
1032                                             }
1033                                         },
1034                                         remoteSort : true,
1035                                         sortInfo : { field : 'poitem_id', direction: 'ASC' },
1036                                         proxy : {
1037                                             xtype: 'HttpProxy',
1038                                             xns: Roo.data,
1039                                             method : 'GET',
1040                                             url : baseURL + '/Roo/poitem.php'
1041                                         },
1042                                         reader : {
1043                                             xtype: 'JsonReader',
1044                                             xns: Roo.data,
1045                                             totalProperty : 'total',
1046                                             root : 'data',
1047                                             id : 'id',
1048                                             fields : [
1049                                                 {
1050                                                     'name': 'id',
1051                                                     'type': 'int'
1052                                                 },
1053                                                 {
1054                                                     'name': 'name',
1055                                                     'type': 'string'
1056                                                 },
1057                                                 {
1058                                                     'name': 'type',
1059                                                     'type': 'int'
1060                                                 },
1061                                                 {
1062                                                     'name': 'leader',
1063                                                     'type': 'int'
1064                                                 },
1065                                                 {
1066                                                     'name': 'leader_id',
1067                                                     'type': 'int'
1068                                                 },
1069                                                 {
1070                                                     'name': 'leader_office_id',
1071                                                     'type': 'int'
1072                                                 },
1073                                                 {
1074                                                     'name': 'leader_name',
1075                                                     'type': 'string'
1076                                                 },
1077                                                 {
1078                                                     'name': 'leader_phone',
1079                                                     'type': 'string'
1080                                                 },
1081                                                 {
1082                                                     'name': 'leader_fax',
1083                                                     'type': 'string'
1084                                                 },
1085                                                 {
1086                                                     'name': 'leader_email',
1087                                                     'type': 'string'
1088                                                 },
1089                                                 {
1090                                                     'name': 'leader_company_id',
1091                                                     'type': 'int'
1092                                                 },
1093                                                 {
1094                                                     'name': 'leader_role',
1095                                                     'type': 'string'
1096                                                 },
1097                                                 {
1098                                                     'name': 'leader_active',
1099                                                     'type': 'int'
1100                                                 },
1101                                                 {
1102                                                     'name': 'leader_remarks',
1103                                                     'type': 'string'
1104                                                 },
1105                                                 {
1106                                                     'name': 'leader_passwd',
1107                                                     'type': 'string'
1108                                                 },
1109                                                 {
1110                                                     'name': 'leader_owner_id',
1111                                                     'type': 'int'
1112                                                 },
1113                                                 {
1114                                                     'name': 'leader_lang',
1115                                                     'type': 'string'
1116                                                 },
1117                                                 {
1118                                                     'name': 'leader_no_reset_sent',
1119                                                     'type': 'int'
1120                                                 },
1121                                                 {
1122                                                     'name': 'leader_action_type',
1123                                                     'type': 'string'
1124                                                 },
1125                                                 {
1126                                                     'name': 'leader_project_id',
1127                                                     'type': 'int'
1128                                                 },
1129                                                 {
1130                                                     'name': 'leader_deleted_by',
1131                                                     'type': 'int'
1132                                                 },
1133                                                 {
1134                                                     'name': 'leader_deleted_dt',
1135                                                     'type': 'date'
1136                                                 },
1137                                                 {
1138                                                     'name': 'leader_firstname',
1139                                                     'type': 'string'
1140                                                 },
1141                                                 {
1142                                                     'name': 'leader_lastname',
1143                                                     'type': 'string'
1144                                                 },
1145                                                 {
1146                                                     'name': 'leader_name_facebook',
1147                                                     'type': 'string'
1148                                                 },
1149                                                 {
1150                                                     'name': 'leader_url_blog',
1151                                                     'type': 'string'
1152                                                 },
1153                                                 {
1154                                                     'name': 'leader_url_twitter',
1155                                                     'type': 'string'
1156                                                 },
1157                                                 {
1158                                                     'name': 'leader_url_linkedin',
1159                                                     'type': 'string'
1160                                                 },
1161                                                 {
1162                                                     'name': 'leader_crm_lead_percentage',
1163                                                     'type': 'int'
1164                                                 },
1165                                                 {
1166                                                     'name': 'leader_crm_industry_id',
1167                                                     'type': 'int'
1168                                                 },
1169                                                 {
1170                                                     'name': 'leader_crm_updated_action_id',
1171                                                     'type': 'int'
1172                                                 },
1173                                                 {
1174                                                     'name': 'leader_crm_created_action_id',
1175                                                     'type': 'int'
1176                                                 },
1177                                                 {
1178                                                     'name': 'leader_crm_type_id',
1179                                                     'type': 'int'
1180                                                 }
1181                                             ]
1182                                         }
1183                                     },
1184                                     footer : {
1185                                         xtype: 'PagingToolbar',
1186                                         xns: Roo,
1187                                         displayInfo : false,
1188                                         displayMsg : "Displaying poitem{0} - {1} of {2}",
1189                                         emptyMsg : "No item found",
1190                                         pageSize : 25
1191                                     },
1192                                     colModel : [
1193                                         {
1194                                             xtype: 'ColumnModel',
1195                                             xns: Roo.grid,
1196                                             dataIndex : 'poitem_linenumber',
1197                                             header : 'Line #',
1198                                             width : 25,
1199                                             renderer : function(v) { return String.format('{0}', v); }
1200                                         },
1201                                         {
1202                                             xtype: 'ColumnModel',
1203                                             xns: Roo.grid,
1204                                             dataIndex : 'item_number',
1205                                             header : 'Item #',
1206                                             width : 75,
1207                                             renderer : function(v) { return String.format('{0}', v); }
1208                                         },
1209                                         {
1210                                             xtype: 'ColumnModel',
1211                                             xns: Roo.grid,
1212                                             dataIndex : 'poitem_qty_ordered',
1213                                             header : 'Ordered',
1214                                             width : 50,
1215                                             renderer : function(v) { return String.format('{0}', v); }
1216                                         },
1217                                         {
1218                                             xtype: 'ColumnModel',
1219                                             xns: Roo.grid,
1220                                             dataIndex : 'poitem_qty_received',
1221                                             header : 'Received',
1222                                             width : 50,
1223                                             renderer : function(v,x,r) 
1224                                             {
1225                                                 
1226                                             
1227                                                 var recv = (v- r.data.poitem_qty_returned);
1228                                                 if (recv !=  r.data.tx_qty) {
1229                                                     return String.format('<s style="color:red;font-weight:bold">{0}</s>{1} ', recv, 
1230                                                         (r.data.tx_qty *1).toFixed(0)        ) ;      
1231                                                 }
1232                                                 return String.format('{0}', (v- r.data.poitem_qty_returned)) ;  
1233                                                 
1234                                             }
1235                                         },
1236                                         {
1237                                             xtype: 'ColumnModel',
1238                                             xns: Roo.grid,
1239                                             dataIndex : 'poitem_unitprice',
1240                                             header : 'Unit Price',
1241                                             width : 75,
1242                                             renderer : function(v,x,r) 
1243                                             {
1244                                                  
1245                                                 return String.format('{0}', (v- r.data.poitem_qty_returned) ? parseFloat(v- r.data.poitem_qty_returned).toFixed(3) : '') ;  
1246                                                 
1247                                             }
1248                                         }
1249                                     ]
1250                                 }
1251                             },
1252                             {
1253                                 xtype: 'GridPanel',
1254                                 xns: Roo,
1255                                 listeners : {
1256                                     activate : function() {
1257                                         _this.gltranspanel = this;
1258                                         //if (_this.gltransgrid) {
1259                                         //    _this.gltransgrid.footer.onClick('first');
1260                                         // }
1261                                     }
1262                                 },
1263                                 background : false,
1264                                 fitContainer : true,
1265                                 fitToframe : true,
1266                                 region : 'east',
1267                                 tableName : 'Gltrans',
1268                                 title : "Gltrans",
1269                                 grid : {
1270                                     xtype: 'Grid',
1271                                     xns: Roo.grid,
1272                                     listeners : {
1273                                         render : function() 
1274                                         {
1275                                             _this.gltransgrid = this; 
1276                                             //_this.dialog = Pman.Dialog.FILL_IN
1277                                           //  if (_this.gltranspanel.active) {
1278                                           //     this.footer.onClick('first');
1279                                           //  }
1280                                         }
1281                                     },
1282                                     autoExpandColumn : 'gltrans_notes',
1283                                     loadMask : true,
1284                                     sm : {
1285                                         xtype: 'RowSelectionModel',
1286                                         xns: Roo.grid,
1287                                         singleSelect : true
1288                                     },
1289                                     dataSource : {
1290                                         xtype: 'Store',
1291                                         xns: Roo.data,
1292                                         listeners : {
1293                                             beforeload : function (_self, o)
1294                                             {
1295                                                 o.params = o.params || {};
1296                                                 
1297                                                 var s = _this.itemgrid.getSelectionModel().getSelected();
1298                                                 if(!s){
1299                                                     this.removeAll();
1300                                                     return false;
1301                                                 }
1302                                                 
1303                                                 o.params._poview = 1;
1304                                                 o.params.gltrans_deleted = 0;
1305                                                 o.params.gltrans_doctype = 'PO';
1306                                                 o.params._linenumber = s.data.poitem_linenumber;
1307                                                 o.params._item = s.data.item_number;
1308                                                 o.params._ponumber = _this.form.findField('pohead_number').getValue();
1309                                                 
1310                                             }
1311                                         },
1312                                         remoteSort : true,
1313                                         sortInfo : { field : 'gltrans_id', direction: 'ASC' },
1314                                         proxy : {
1315                                             xtype: 'HttpProxy',
1316                                             xns: Roo.data,
1317                                             method : 'GET',
1318                                             url : baseURL + '/Roo/gltrans.php'
1319                                         },
1320                                         reader : {
1321                                             xtype: 'JsonReader',
1322                                             xns: Roo.data,
1323                                             totalProperty : 'total',
1324                                             root : 'data',
1325                                             id : 'id',
1326                                             fields : [
1327                                                 {
1328                                                     'name': 'id',
1329                                                     'type': 'int'
1330                                                 },
1331                                                 {
1332                                                     'name': 'name',
1333                                                     'type': 'string'
1334                                                 },
1335                                                 {
1336                                                     'name': 'type',
1337                                                     'type': 'int'
1338                                                 },
1339                                                 {
1340                                                     'name': 'leader',
1341                                                     'type': 'int'
1342                                                 },
1343                                                 {
1344                                                     'name': 'leader_id',
1345                                                     'type': 'int'
1346                                                 },
1347                                                 {
1348                                                     'name': 'leader_office_id',
1349                                                     'type': 'int'
1350                                                 },
1351                                                 {
1352                                                     'name': 'leader_name',
1353                                                     'type': 'string'
1354                                                 },
1355                                                 {
1356                                                     'name': 'leader_phone',
1357                                                     'type': 'string'
1358                                                 },
1359                                                 {
1360                                                     'name': 'leader_fax',
1361                                                     'type': 'string'
1362                                                 },
1363                                                 {
1364                                                     'name': 'leader_email',
1365                                                     'type': 'string'
1366                                                 },
1367                                                 {
1368                                                     'name': 'leader_company_id',
1369                                                     'type': 'int'
1370                                                 },
1371                                                 {
1372                                                     'name': 'leader_role',
1373                                                     'type': 'string'
1374                                                 },
1375                                                 {
1376                                                     'name': 'leader_active',
1377                                                     'type': 'int'
1378                                                 },
1379                                                 {
1380                                                     'name': 'leader_remarks',
1381                                                     'type': 'string'
1382                                                 },
1383                                                 {
1384                                                     'name': 'leader_passwd',
1385                                                     'type': 'string'
1386                                                 },
1387                                                 {
1388                                                     'name': 'leader_owner_id',
1389                                                     'type': 'int'
1390                                                 },
1391                                                 {
1392                                                     'name': 'leader_lang',
1393                                                     'type': 'string'
1394                                                 },
1395                                                 {
1396                                                     'name': 'leader_no_reset_sent',
1397                                                     'type': 'int'
1398                                                 },
1399                                                 {
1400                                                     'name': 'leader_action_type',
1401                                                     'type': 'string'
1402                                                 },
1403                                                 {
1404                                                     'name': 'leader_project_id',
1405                                                     'type': 'int'
1406                                                 },
1407                                                 {
1408                                                     'name': 'leader_deleted_by',
1409                                                     'type': 'int'
1410                                                 },
1411                                                 {
1412                                                     'name': 'leader_deleted_dt',
1413                                                     'type': 'date'
1414                                                 },
1415                                                 {
1416                                                     'name': 'leader_firstname',
1417                                                     'type': 'string'
1418                                                 },
1419                                                 {
1420                                                     'name': 'leader_lastname',
1421                                                     'type': 'string'
1422                                                 },
1423                                                 {
1424                                                     'name': 'leader_name_facebook',
1425                                                     'type': 'string'
1426                                                 },
1427                                                 {
1428                                                     'name': 'leader_url_blog',
1429                                                     'type': 'string'
1430                                                 },
1431                                                 {
1432                                                     'name': 'leader_url_twitter',
1433                                                     'type': 'string'
1434                                                 },
1435                                                 {
1436                                                     'name': 'leader_url_linkedin',
1437                                                     'type': 'string'
1438                                                 },
1439                                                 {
1440                                                     'name': 'leader_crm_lead_percentage',
1441                                                     'type': 'int'
1442                                                 },
1443                                                 {
1444                                                     'name': 'leader_crm_industry_id',
1445                                                     'type': 'int'
1446                                                 },
1447                                                 {
1448                                                     'name': 'leader_crm_updated_action_id',
1449                                                     'type': 'int'
1450                                                 },
1451                                                 {
1452                                                     'name': 'leader_crm_created_action_id',
1453                                                     'type': 'int'
1454                                                 },
1455                                                 {
1456                                                     'name': 'leader_crm_type_id',
1457                                                     'type': 'int'
1458                                                 }
1459                                             ]
1460                                         }
1461                                     },
1462                                     footer : {
1463                                         xtype: 'PagingToolbar',
1464                                         xns: Roo,
1465                                         displayInfo : true,
1466                                         displayMsg : "Displaying gltrans{0} - {1} of {2}",
1467                                         emptyMsg : "No gltrans found",
1468                                         pageSize : 25
1469                                     },
1470                                     toolbar : {
1471                                         xtype: 'Toolbar',
1472                                         xns: Roo,
1473                                         items : [
1474                                             {
1475                                                 xtype: 'Fill',
1476                                                 xns: Roo.Toolbar
1477                                             },
1478                                             {
1479                                                 xtype: 'Button',
1480                                                 xns: Roo.Toolbar,
1481                                                 text : "Apply fixes",
1482                                                 menu : {
1483                                                     xtype: 'Menu',
1484                                                     xns: Roo.menu,
1485                                                     items : [
1486                                                         {
1487                                                             xtype: 'Item',
1488                                                             xns: Roo.menu,
1489                                                             listeners : {
1490                                                                 click : function()
1491                                                                 {
1492                                                                    var pohead_number = _this.form.findField('pohead_number').getValue();
1493                                                                     var pohead_id = _this.form.findField('pohead_id').getValue();
1494                                                                         
1495                                                                     
1496                                                                         new Pman.Request({
1497                                                                             url : baseURL + '/Roo/pohead.php',
1498                                                                             mask : 'sending',
1499                                                                             method :'POST',
1500                                                                             params : {
1501                                                                                 pohead_id : pohead_id,
1502                                                                                 _recv_fix : 1
1503                                                                                 
1504                                                                             },
1505                                                                             success : function(res) {
1506                                                                                 Roo.MessageBox.alert('Notice', 'DONE');
1507                                                                             }
1508                                                                         });
1509                                                                     
1510                                                                     
1511                                                                     
1512                                                                     
1513                                                                     
1514                                                                 }
1515                                                             },
1516                                                             cls : 'x-btn-text-icon',
1517                                                             text : "Repost goods reciept",
1518                                                             icon : rootURL + '/Pman/templates/images/trash.gif'
1519                                                         },
1520                                                         {
1521                                                             xtype: 'Separator',
1522                                                             xns: Roo.menu
1523                                                         },
1524                                                         {
1525                                                             xtype: 'Item',
1526                                                             xns: Roo.menu,
1527                                                             listeners : {
1528                                                                 click : function()
1529                                                                 {
1530                                                                     var pohead_number = _this.form.findField('pohead_number').getValue();
1531                                                                     var pohead_id = _this.form.findField('pohead_id').getValue();
1532                                                                         
1533                                                                     var fixit = function(){
1534                                                                         new Pman.Request({
1535                                                                             url : baseURL + '/Roo/pohead.php',
1536                                                                             method :'POST',
1537                                                                             params : {
1538                                                                                 pohead_id : pohead_id,
1539                                                                                 _unitcost : 1
1540                                                                                 
1541                                                                             },
1542                                                                             success : function(res) {
1543                                                                                 Roo.MessageBox.alert('Notice', 'DONE');
1544                                                                             }
1545                                                                         });
1546                                                                     }
1547                                                                     
1548                                                                     Roo.MessageBox.confirm(
1549                                                                         "Confirm",
1550                                                                         "Are you sure to fix the unit cost of " + pohead_number + " ?",
1551                                                                         function(r) {
1552                                                                             if (r != 'yes') {
1553                                                                                 return;
1554                                                                             }
1555                                                                 
1556                                                                             fixit();
1557                                                                             return;
1558                                                                         }
1559                                                                     ); 
1560                                                                     
1561                                                                     
1562                                                                 }
1563                                                             },
1564                                                             cls : 'x-btn-text-icon',
1565                                                             text : "Fix Unit Cost",
1566                                                             icon : rootURL + '/Pman/templates/images/trash.gif'
1567                                                         },
1568                                                         {
1569                                                             xtype: 'Separator',
1570                                                             xns: Roo.menu
1571                                                         },
1572                                                         {
1573                                                             xtype: 'Item',
1574                                                             xns: Roo.menu,
1575                                                             listeners : {
1576                                                                 click : function()
1577                                                                 {
1578                                                                     var pohead_number = _this.form.findField('pohead_number').getValue();
1579                                                                     var pohead_id = _this.form.findField('pohead_id').getValue();
1580                                                                         
1581                                                                     var addv = function(){
1582                                                                         new Pman.Request({
1583                                                                             url : baseURL + '/Roo/pohead.php',
1584                                                                             method :'POST',
1585                                                                             params : {
1586                                                                                 pohead_id : pohead_id,
1587                                                                                 _variance : 1
1588                                                                                 
1589                                                                             },
1590                                                                             success : function(res) {
1591                                                                                 Roo.MessageBox.alert('Notice', 'DONE');
1592                                                                             }
1593                                                                         });
1594                                                                     }
1595                                                                     
1596                                                                     Roo.MessageBox.confirm(
1597                                                                         "Confirm",
1598                                                                         "Are you sure to add all the variance for " + pohead_number + " ?",
1599                                                                         function(r) {
1600                                                                             if (r != 'yes') {
1601                                                                                 return;
1602                                                                             }
1603                                                                 
1604                                                                             addv();
1605                                                                             return;
1606                                                                         }
1607                                                                     ); 
1608                                                                     
1609                                                                     
1610                                                                 }
1611                                                             },
1612                                                             cls : 'x-btn-text-icon',
1613                                                             text : "Add All Variance",
1614                                                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
1615                                                         },
1616                                                         {
1617                                                             xtype: 'Item',
1618                                                             xns: Roo.menu,
1619                                                             listeners : {
1620                                                                 click : function()
1621                                                                 {
1622                                                                     var s = _this.gltransgrid.getSelectionModel().getSelected();
1623                                                                     
1624                                                                     if(!s){
1625                                                                         Roo.MessageBox.alert('Error','Please select a transaction');
1626                                                                         return;
1627                                                                     }
1628                                                                     
1629                                                                     if(s.data.gltrans_misc_id != -1){
1630                                                                         Roo.MessageBox.alert('Error','Just allow to delete the variance');
1631                                                                         return;
1632                                                                     }
1633                                                                     
1634                                                                     var delit = function(){
1635                                                                         new Pman.Request({
1636                                                                             url : baseURL + '/Roo/Gltrans.php',
1637                                                                             method :'POST',
1638                                                                             params : {
1639                                                                                 gltrans_id : s.data.gltrans_id,
1640                                                                                 _del : 1
1641                                                                                 
1642                                                                             },
1643                                                                             success : function(res) {
1644                                                                                 _this.gltransgrid.footer.onClick('refresh');
1645                                                                                 
1646                                                                             }
1647                                                                         });
1648                                                                     }
1649                                                                     
1650                                                                     Roo.MessageBox.confirm(
1651                                                                         "Confirm",
1652                                                                         "Are you sure to delete ?",
1653                                                                         function(r) {
1654                                                                             if (r != 'yes') {
1655                                                                                 return;
1656                                                                             }
1657                                                                 
1658                                                                             delit();
1659                                                                             return;
1660                                                                         }
1661                                                                     ); 
1662                                                                     
1663                                                                     
1664                                                                 }
1665                                                             },
1666                                                             cls : 'x-btn-text-icon',
1667                                                             text : "Delete Variance",
1668                                                             icon : rootURL + '/Pman/templates/images/trash.gif'
1669                                                         },
1670                                                         {
1671                                                             xtype: 'Item',
1672                                                             xns: Roo.menu,
1673                                                             listeners : {
1674                                                                 click : function()
1675                                                                 {
1676                                                                     var pohead_number = _this.form.findField('pohead_number').getValue();
1677                                                                     var pohead_id = _this.form.findField('pohead_id').getValue();
1678                                                                         
1679                                                                     var delv = function(){
1680                                                                         new Pman.Request({
1681                                                                             url : baseURL + '/Roo/pohead.php',
1682                                                                             method :'POST',
1683                                                                             params : {
1684                                                                                 pohead_id : pohead_id,
1685                                                                                 _del : 1
1686                                                                                 
1687                                                                             },
1688                                                                             success : function(res) {
1689                                                                                 Roo.MessageBox.alert('Notice', 'DONE');
1690                                                                             }
1691                                                                         });
1692                                                                     }
1693                                                                     
1694                                                                     Roo.MessageBox.confirm(
1695                                                                         "Confirm",
1696                                                                         "Are you sure to delete the variance on voucher of " + pohead_number + " ?",
1697                                                                         function(r) {
1698                                                                             if (r != 'yes') {
1699                                                                                 return;
1700                                                                             }
1701                                                                 
1702                                                                             delv();
1703                                                                             return;
1704                                                                         }
1705                                                                     ); 
1706                                                                     
1707                                                                     
1708                                                                 }
1709                                                             },
1710                                                             cls : 'x-btn-text-icon',
1711                                                             text : "Delete Varinace on voucher",
1712                                                             icon : rootURL + '/Pman/templates/images/trash.gif'
1713                                                         }
1714                                                     ]
1715                                                 }
1716                                             },
1717                                             {
1718                                                 xtype: 'Button',
1719                                                 xns: Roo.Toolbar,
1720                                                 listeners : {
1721                                                     click : function()
1722                                                     {
1723                                                         var s = _this.gltransgrid.selModel.getSelected();
1724                                                         if (!s) {
1725                                                             Roo.MessageBox.alert("Error", "Select an item to reverse");
1726                                                             return;
1727                                                         }
1728                                                         
1729                                                         var fixit = function(){
1730                                                             new Pman.Request({
1731                                                                 url : baseURL + '/Roo/invdetail.php',
1732                                                                 method :'POST',
1733                                                                 params : {
1734                                                                    
1735                                                                     _reverse :  s.data.invdetail_id 
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 reverse that line",
1746                                                             function(r) {
1747                                                                 if (r != 'yes') {
1748                                                                     return;
1749                                                                 }
1750                                                     
1751                                                                 fixit();
1752                                                                 return;
1753                                                             }
1754                                                         ); 
1755                                                         
1756                                                         
1757                                                     }
1758                                                 },
1759                                                 cls : 'x-btn-text-icon',
1760                                                 text : "Reverse",
1761                                                 icon : rootURL + '/Pman/templates/images/trash.gif'
1762                                             }
1763                                         ]
1764                                     },
1765                                     colModel : [
1766                                         {
1767                                             xtype: 'ColumnModel',
1768                                             xns: Roo.grid,
1769                                             dataIndex : 'gltrans_id',
1770                                             header : 'ID',
1771                                             width : 50,
1772                                             renderer : function(v) { return String.format('{0}', v); }
1773                                         },
1774                                         {
1775                                             xtype: 'ColumnModel',
1776                                             xns: Roo.grid,
1777                                             dataIndex : 'gltrans_date',
1778                                             header : 'Date',
1779                                             width : 75,
1780                                             renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
1781                                         },
1782                                         {
1783                                             xtype: 'ColumnModel',
1784                                             xns: Roo.grid,
1785                                             dataIndex : 'gltrans_docnumber',
1786                                             header : 'doc #',
1787                                             width : 80,
1788                                             renderer : function(v) { return String.format('{0}', v); }
1789                                         },
1790                                         {
1791                                             xtype: 'ColumnModel',
1792                                             xns: Roo.grid,
1793                                             align : 'right',
1794                                             dataIndex : 'invdetail_qty',
1795                                             header : 'Qty',
1796                                             width : 60,
1797                                             renderer : function(v,x,r) {
1798                                                var f = r.data.invfifo_void * 1 ? '<s>{0}</s>' : '{0}';
1799                                                
1800                                                 return String.format(f, (v*1).toFixed(0)); 
1801                                             
1802                                             }
1803                                         },
1804                                         {
1805                                             xtype: 'ColumnModel',
1806                                             xns: Roo.grid,
1807                                             align : 'right',
1808                                             dataIndex : 'gltrans_amount',
1809                                             header : 'Amount',
1810                                             width : 100,
1811                                             renderer : function(v,x,r) { 
1812                                              return String.format('{0}', v); 
1813                                             
1814                                             }
1815                                         },
1816                                         {
1817                                             xtype: 'ColumnModel',
1818                                             xns: Roo.grid,
1819                                             align : 'right',
1820                                             dataIndex : 'invdetail_qty',
1821                                             header : 'Qty',
1822                                             width : 60,
1823                                             renderer : function(v,x,r) {
1824                                                var f = r.data.invfifo_void * 1 ? '<s>{0}</s>' : '{0}';
1825                                                
1826                                                 return String.format(f, (v*1).toFixed(0)); 
1827                                             
1828                                             }
1829                                         },
1830                                         {
1831                                             xtype: 'ColumnModel',
1832                                             xns: Roo.grid,
1833                                             dataIndex : 'gltrans_notes',
1834                                             header : 'Notes',
1835                                             width : 100,
1836                                             renderer : function(v) { return String.format('{0}', v); }
1837                                         }
1838                                     ]
1839                                 }
1840                             }
1841                         ],
1842                         center : {
1843                             xtype: 'LayoutRegion',
1844                             xns: Roo
1845                         },
1846                         east : {
1847                             xtype: 'LayoutRegion',
1848                             xns: Roo,
1849                             split : true,
1850                             width : 550
1851                         }
1852                     }
1853                 },
1854                 {
1855                     xtype: 'NestedLayoutPanel',
1856                     xns: Roo,
1857                     region : 'center',
1858                     title : "GL Tx",
1859                     layout : {
1860                         xtype: 'BorderLayout',
1861                         xns: Roo,
1862                         items : [
1863                             {
1864                                 xtype: 'GridPanel',
1865                                 xns: Roo,
1866                                 listeners : {
1867                                     activate : function() {
1868                                         _this.gltxpanel = this;
1869                                         if (_this.gltxgrid) {
1870                                             _this.gltxgrid.footer.onClick('first');
1871                                         }
1872                                     }
1873                                 },
1874                                 background : false,
1875                                 fitContainer : true,
1876                                 fitToframe : true,
1877                                 region : 'center',
1878                                 tableName : 'invdetail',
1879                                 title : "invdetail",
1880                                 grid : {
1881                                     xtype: 'Grid',
1882                                     xns: Roo.grid,
1883                                     listeners : {
1884                                         render : function() 
1885                                         {
1886                                             _this.gltxgrid = this; 
1887                                             //_this.dialog = Pman.Dialog.FILL_IN
1888                                             if (_this.gltxpanel.active) {
1889                                                this.footer.onClick('first');
1890                                             }
1891                                         },
1892                                         cellclick : function (_self, rowIndex, columnIndex, e)
1893                                         {
1894                                             if (columnIndex > 0) {
1895                                                 return;
1896                                             }
1897                                             var rec = this.ds.getAt(rowIndex);
1898                                             rec.set('gltrans_as_summary', rec.data.gltrans_as_summary *1 ? 0 : 1);
1899                                             _this.gltxdgrid.footer.onClick('first');
1900                                         }
1901                                     },
1902                                     autoExpandColumn : 'gltrans_accnt_id_accnt_descrip',
1903                                     loadMask : true,
1904                                     sm : {
1905                                         xtype: 'RowSelectionModel',
1906                                         xns: Roo.grid,
1907                                         listeners : {
1908                                             selectionchange : function (_self)
1909                                             {
1910                                                 _this.gltxdgrid.footer.onClick('first');;
1911                                             }
1912                                         },
1913                                         singleSelect : true
1914                                     },
1915                                     dataSource : {
1916                                         xtype: 'Store',
1917                                         xns: Roo.data,
1918                                         listeners : {
1919                                             beforeload : function (_self, o)
1920                                             {
1921                                                 o.params.pohead_id = _this.form.findField('pohead_id').getValue();
1922                                                 if (! o.params.pohead_id ) {
1923                                                     this.removeAll();
1924                                                     return false;
1925                                                 }
1926                                                 o.params._split_sales = _this.glsalesbtn.pressed ? 1 : 0;
1927                                             },
1928                                             load : function (_self, records, options)
1929                                             {
1930                                              _this.gltxdgrid.footer.onClick('first');
1931                                             }
1932                                         },
1933                                         remoteSort : true,
1934                                         sortInfo : { field : 'item_number', direction: 'ASC' },
1935                                         proxy : {
1936                                             xtype: 'HttpProxy',
1937                                             xns: Roo.data,
1938                                             method : 'GET',
1939                                             url : baseURL + '/Roo/gltrans.php'
1940                                         },
1941                                         reader : {
1942                                             xtype: 'JsonReader',
1943                                             xns: Roo.data,
1944                                             totalProperty : 'total',
1945                                             root : 'data',
1946                                             id : 'id',
1947                                             fields : [
1948                                                 {
1949                                                     'name': 'invdetail_id',
1950                                                     'type': 'int'
1951                                                 },
1952                                                 {
1953                                                     'name': 'invdetail_transtype',
1954                                                     'type': 'string'
1955                                                 },
1956                                                 {
1957                                                     'name': 'invdetail_invhist_id',
1958                                                     'type': 'int'
1959                                                 },
1960                                                 {
1961                                                     'name': 'invdetail_location_id',
1962                                                     'type': 'int'
1963                                                 },
1964                                                 {
1965                                                     'name': 'invdetail_qty',
1966                                                     'type': 'float'
1967                                                 },
1968                                                 {
1969                                                     'name': 'invdetail_comments',
1970                                                     'type': 'string'
1971                                                 },
1972                                                 {
1973                                                     'name': 'invdetail_qty_before',
1974                                                     'type': 'float'
1975                                                 },
1976                                                 {
1977                                                     'name': 'invdetail_qty_after',
1978                                                     'type': 'float'
1979                                                 },
1980                                                 {
1981                                                     'name': 'invdetail_invcitem_id',
1982                                                     'type': 'int'
1983                                                 },
1984                                                 {
1985                                                     'name': 'invdetail_expiration',
1986                                                     'type': 'date',
1987                                                     'dateFormat': 'Y-m-d'
1988                                                 },
1989                                                 {
1990                                                     'name': 'invdetail_warrpurc',
1991                                                     'type': 'date',
1992                                                     'dateFormat': 'Y-m-d'
1993                                                 },
1994                                                 {
1995                                                     'name': 'invdetail_ls_id',
1996                                                     'type': 'int'
1997                                                 }
1998                                             ]
1999                                         }
2000                                     },
2001                                     footer : {
2002                                         xtype: 'PagingToolbar',
2003                                         xns: Roo,
2004                                         displayInfo : true,
2005                                         displayMsg : "Displaying invdetail{0} - {1} of {2}",
2006                                         emptyMsg : "No invdetail found",
2007                                         pageSize : 9999,
2008                                         items : [
2009                                             {
2010                                                 xtype: 'Button',
2011                                                 xns: Roo.Toolbar,
2012                                                 listeners : {
2013                                                     render : function (_self)
2014                                                     {
2015                                                         _this.glsalesbtn = _self;
2016                                                     },
2017                                                     click : function (_self, e)
2018                                                     {
2019                                                         (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
2020                                                     }
2021                                                 },
2022                                                 enableToggle : true,
2023                                                 pressed : true,
2024                                                 text : "Split sales"
2025                                             }
2026                                         ]
2027                                     },
2028                                     colModel : [
2029                                         {
2030                                             xtype: 'ColumnModel',
2031                                             xns: Roo.grid,
2032                                             dataIndex : 'gltrans_as_summary',
2033                                             header : 'Summary',
2034                                             width : 50,
2035                                             renderer : function(v,x,r) { 
2036                                                 
2037                                                 var state = v*1   ?  '-checked' : '';
2038                                                                                 
2039                                                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
2040                                              }
2041                                         },
2042                                         {
2043                                             xtype: 'ColumnModel',
2044                                             xns: Roo.grid,
2045                                             dataIndex : 'gltrans_accnt_id_accnt_descrip',
2046                                             header : 'Account',
2047                                             width : 75,
2048                                             renderer : function(v) { return String.format('{0}', v); }
2049                                         },
2050                                         {
2051                                             xtype: 'ColumnModel',
2052                                             xns: Roo.grid,
2053                                             align : 'right',
2054                                             dataIndex : 'gltrans_amount_credit',
2055                                             header : 'Credit',
2056                                             width : 75,
2057                                             renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); }
2058                                         },
2059                                         {
2060                                             xtype: 'ColumnModel',
2061                                             xns: Roo.grid,
2062                                             align : 'right',
2063                                             dataIndex : 'gltrans_amount_debit',
2064                                             header : 'Debit',
2065                                             width : 75,
2066                                             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }
2067                                         },
2068                                         {
2069                                             xtype: 'ColumnModel',
2070                                             xns: Roo.grid,
2071                                             align : 'right',
2072                                             dataIndex : 'gltrans_amount_total',
2073                                             header : 'Sum',
2074                                             width : 75,
2075                                             renderer : function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); }
2076                                         },
2077                                         {
2078                                             xtype: 'ColumnModel',
2079                                             xns: Roo.grid,
2080                                             align : 'right',
2081                                             dataIndex : 'gltrans_amount_total_unposted',
2082                                             header : 'Unposted',
2083                                             width : 75,
2084                                             renderer : function(v) { return String.format('<span style="color:red">{0}</span>', Roo.util.Format.number(v,3)); }
2085                                         }
2086                                     ]
2087                                 }
2088                             },
2089                             {
2090                                 xtype: 'GridPanel',
2091                                 xns: Roo,
2092                                 listeners : {
2093                                     activate : function() {
2094                                         _this.gltxdpanel = this;
2095                                         if (_this.gltxdgrid) {
2096                                             _this.gltxdgrid.footer.onClick('first');
2097                                         }
2098                                     }
2099                                 },
2100                                 background : false,
2101                                 fitContainer : true,
2102                                 fitToframe : true,
2103                                 region : 'east',
2104                                 tableName : 'invdetail',
2105                                 title : "invdetail",
2106                                 grid : {
2107                                     xtype: 'Grid',
2108                                     xns: Roo.grid,
2109                                     listeners : {
2110                                         render : function() 
2111                                         {
2112                                             _this.gltxdgrid = this; 
2113                                             //_this.dialog = Pman.Dialog.FILL_IN
2114                                             if (_this.gltxdpanel.active) {
2115                                                this.footer.onClick('first');
2116                                             }
2117                                         },
2118                                         cellclick : function (_self, ri, ci, e)
2119                                         {
2120                                             
2121                                               var deleteSel = function() {
2122                                             
2123                                                 new Pman.Request({
2124                                                     mask : "Reversing",
2125                                                     url : baseURL + '/Roo/gltrans',
2126                                                     method : 'POST',
2127                                                     params : {  
2128                                                         _void : 1,
2129                                                         gltrans_id : rec.data.gltrans_id
2130                                                         
2131                                                     }, 
2132                                                     success : function() {
2133                                                         rec.set('gltrans_posted', false);
2134                                                         rec.set('gltrans_deleted', true);
2135                                                         rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
2136                                                        _this.gltxgrid.footer.onClick('first');
2137                                                     }
2138                                                 });
2139                                             
2140                                             }
2141                                             var undeleteSel = function() {
2142                                             
2143                                                 new Pman.Request({
2144                                                     mask : "Reversing",
2145                                                     url : baseURL + '/Roo/gltrans',
2146                                                     method : 'POST',
2147                                                     params : {  
2148                                                         _unvoid : 1,
2149                                                         gltrans_id : rec.data.gltrans_id
2150                                                         
2151                                                     }, 
2152                                                     success : function() {
2153                                                         rec.set('gltrans_posted', true);
2154                                                         rec.set('gltrans_deleted', false);
2155                                                         rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
2156                                                        _this.gltxgrid.footer.onClick('first');
2157                                                     }
2158                                                 });
2159                                             
2160                                             }
2161                                             
2162                                             var di = this.colModel.config[ci].dataIndex;
2163                                             if (di != 'gltrans_posted') {
2164                                                 return;
2165                                             }
2166                                             
2167                                             
2168                                             
2169                                             var rec = this.ds.getAt(ri);
2170                                             if (rec.data.gltrans_deleted) {
2171                                             
2172                                                  Roo.MessageBox.confirm(
2173                                                     "Confirm", 
2174                                                     "This should only be used by System Administrators - are you sure you know what you are doing!",
2175                                                     function(x) {
2176                                                         if (x != 'yes') {
2177                                                             return;
2178                                                         }
2179                                                         undeleteSel();
2180                                                     }
2181                                                 );
2182                                             
2183                                                 return false;
2184                                             }
2185                                         
2186                                             
2187                                             
2188                                             if (!rec.data.gltrans_posted) {
2189                                         
2190                                                 
2191                                                 
2192                                                 new Pman.Request({
2193                                                     method : 'POST',
2194                                                     url : baseURL + '/Roo/gltrans',
2195                                                     mask : "Posting",
2196                                                     params : {
2197                                                         _post : 1,
2198                                                         gltrans_id : rec.data.gltrans_id
2199                                                     },
2200                                                     success : function (res)
2201                                                     {
2202                                                         rec.set('gltrans_posted', true);
2203                                                         _this.gltxgrid.footer.onClick('first');
2204                                                     
2205                                                     }
2206                                                 
2207                                                 
2208                                                 });
2209                                                 return;
2210                                             }
2211                                             
2212                                             // we have a posted transaction.
2213                                             // only allow recalled to be deleted..
2214                                             if (!rec.data.gltrans_notes.match(/(Recall|Ship Order)/)) {
2215                                                 return false;
2216                                             }
2217                                             
2218                                             
2219                                          
2220                                             
2221                                             
2222                                         
2223                                             Roo.MessageBox.confirm(
2224                                                 "Confirm", 
2225                                                 "This should only be used by System Administrators - are you sure you know what you are doing!",
2226                                                 function(x) {
2227                                                     if (x != 'yes') {
2228                                                         return;
2229                                                     }
2230                                                     deleteSel();
2231                                                 }
2232                                             );
2233                                                   
2234                                             
2235                                             
2236                                         }
2237                                     },
2238                                     autoExpandColumn : 'gltrans_notes',
2239                                     loadMask : true,
2240                                     toolbar : {
2241                                         xtype: 'Toolbar',
2242                                         xns: Roo,
2243                                         items : [
2244                                             {
2245                                                 xtype: 'Button',
2246                                                 xns: Roo.Toolbar,
2247                                                 listeners : {
2248                                                     render : function (_self)
2249                                                     {
2250                                                         _this.glvoidshow = _self;
2251                                                     },
2252                                                     click : function (_self, e)
2253                                                     {
2254                                                         (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
2255                                                     }
2256                                                 },
2257                                                 enableToggle : true,
2258                                                 pressed : true,
2259                                                 text : "Hide Void"
2260                                             },
2261                                             {
2262                                                 xtype: 'Fill',
2263                                                 xns: Roo.Toolbar
2264                                             },
2265                                             {
2266                                                 xtype: 'Button',
2267                                                 xns: Roo.Toolbar,
2268                                                 listeners : {
2269                                                     click : function (_self, e)
2270                                                     {
2271                                                         new Pman.Request( {
2272                                                             url : baseURL + '/Roo/Gltrans',
2273                                                             method : 'GET',
2274                                                             mask:  'sending',
2275                                                             params : {
2276                                                                 pohead_id : _this.form.findField('pohead_id').getValue(),
2277                                                                 _autovoid : 1
2278                                                             },
2279                                                             success : function() {
2280                                                                 _this.gltxpanel.footer.onClick('first');
2281                                                             }
2282                                                                 
2283                                                         
2284                                                         });
2285                                                     }
2286                                                 },
2287                                                 text : "AutoVoid"
2288                                             }
2289                                         ]
2290                                     },
2291                                     dataSource : {
2292                                         xtype: 'Store',
2293                                         xns: Roo.data,
2294                                         listeners : {
2295                                             beforeload : function (_self, o)
2296                                             {
2297                                                 o.params.pohead_id = _this.form.findField('pohead_id').getValue();
2298                                                 var s = _this.gltxgrid.selModel.getSelected();
2299                                                 if (!s) { 
2300                                                     this.removeAll();
2301                                                     return false;
2302                                                 }
2303                                                 o.params.gltrans_accnt_id = s.data.gltrans_accnt_id;
2304                                                 o.params.gltrans_is_ship = s.data.gltrans_is_ship;
2305                                                 o.params.gltrans_as_summary =     s.data.gltrans_as_summary;
2306                                                  o.params._hide_void = _this.glvoidshow.pressed ? 1 : 0;
2307                                                 //glvoidshow
2308                                                 
2309                                             }
2310                                         },
2311                                         remoteSort : true,
2312                                         sortInfo : { field : 'gltrans_docnumber', direction: 'ASC' },
2313                                         proxy : {
2314                                             xtype: 'HttpProxy',
2315                                             xns: Roo.data,
2316                                             method : 'GET',
2317                                             url : baseURL + '/Roo/gltrans.php'
2318                                         },
2319                                         reader : {
2320                                             xtype: 'JsonReader',
2321                                             xns: Roo.data,
2322                                             totalProperty : 'total',
2323                                             root : 'data',
2324                                             id : 'id',
2325                                             fields : [
2326                                                 {
2327                                                     'name': 'invdetail_id',
2328                                                     'type': 'int'
2329                                                 },
2330                                                 {
2331                                                     'name': 'invdetail_transtype',
2332                                                     'type': 'string'
2333                                                 },
2334                                                 {
2335                                                     'name': 'invdetail_invhist_id',
2336                                                     'type': 'int'
2337                                                 },
2338                                                 {
2339                                                     'name': 'invdetail_location_id',
2340                                                     'type': 'int'
2341                                                 },
2342                                                 {
2343                                                     'name': 'invdetail_qty',
2344                                                     'type': 'float'
2345                                                 },
2346                                                 {
2347                                                     'name': 'invdetail_comments',
2348                                                     'type': 'string'
2349                                                 },
2350                                                 {
2351                                                     'name': 'invdetail_qty_before',
2352                                                     'type': 'float'
2353                                                 },
2354                                                 {
2355                                                     'name': 'invdetail_qty_after',
2356                                                     'type': 'float'
2357                                                 },
2358                                                 {
2359                                                     'name': 'invdetail_invcitem_id',
2360                                                     'type': 'int'
2361                                                 },
2362                                                 {
2363                                                     'name': 'invdetail_expiration',
2364                                                     'type': 'date',
2365                                                     'dateFormat': 'Y-m-d'
2366                                                 },
2367                                                 {
2368                                                     'name': 'invdetail_warrpurc',
2369                                                     'type': 'date',
2370                                                     'dateFormat': 'Y-m-d'
2371                                                 },
2372                                                 {
2373                                                     'name': 'invdetail_ls_id',
2374                                                     'type': 'int'
2375                                                 }
2376                                             ]
2377                                         }
2378                                     },
2379                                     footer : {
2380                                         xtype: 'PagingToolbar',
2381                                         xns: Roo,
2382                                         displayInfo : true,
2383                                         displayMsg : "Displaying invdetail{0} - {1} of {2}",
2384                                         emptyMsg : "No invdetail found",
2385                                         pageSize : 9999,
2386                                         items : [
2387                                             {
2388                                                 xtype: 'Button',
2389                                                 xns: Roo.Toolbar,
2390                                                 listeners : {
2391                                                     click : function (_self, e)
2392                                                     {
2393                                                         new Pman.Download( {
2394                                                             grid : _this.gltxdgrid
2395                                                         
2396                                                         });
2397                                                     }
2398                                                 },
2399                                                 text : "Download"
2400                                             }
2401                                         ]
2402                                     },
2403                                     colModel : [
2404                                         {
2405                                             xtype: 'ColumnModel',
2406                                             xns: Roo.grid,
2407                                             dataIndex : 'gltrans_id',
2408                                             header : 'Ref#',
2409                                             sortable : true,
2410                                             width : 75,
2411                                             renderer : function(v) { return String.format('{0}', v ); }
2412                                         },
2413                                         {
2414                                             xtype: 'ColumnModel',
2415                                             xns: Roo.grid,
2416                                             dataIndex : 'gltrans_date',
2417                                             header : 'Date',
2418                                             width : 75,
2419                                             renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
2420                                         },
2421                                         {
2422                                             xtype: 'ColumnModel',
2423                                             xns: Roo.grid,
2424                                             dataIndex : 'gltrans_docnumber',
2425                                             header : 'Doc#',
2426                                             width : 75,
2427                                             renderer : function(v,x,r) { 
2428                                             
2429                                                 var style = '';
2430                                                 if (r.data.gltrans_misc_id > 0 && (r.data.invdetail_id *1) < 1) {
2431                                                     style = ' style="color:red;font-weight:bold"';
2432                                                }
2433                                                 if (r.data.gltrans_deleted) {
2434                                                    return String.format('<s'+style+'>{0}</s>', v);     
2435                                                 }
2436                                                 return String.format('<span' + style + '>{0}</span>', v); 
2437                                             }
2438                                         },
2439                                         {
2440                                             xtype: 'ColumnModel',
2441                                             xns: Roo.grid,
2442                                             dataIndex : 'gltrans_source',
2443                                             header : 'Source',
2444                                             width : 50,
2445                                             renderer : function(v) { return String.format('{0}', v); }
2446                                         },
2447                                         {
2448                                             xtype: 'ColumnModel',
2449                                             xns: Roo.grid,
2450                                             dataIndex : 'gltrans_notes',
2451                                             header : 'Notes',
2452                                             width : 75,
2453                                             renderer : function(v) { return String.format('{0}', v); }
2454                                         },
2455                                         {
2456                                             xtype: 'ColumnModel',
2457                                             xns: Roo.grid,
2458                                             align : 'right',
2459                                             dataIndex : 'gltrans_amount',
2460                                             header : 'Amount',
2461                                             width : 75,
2462                                             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }
2463                                         },
2464                                         {
2465                                             xtype: 'ColumnModel',
2466                                             xns: Roo.grid,
2467                                             dataIndex : 'gltrans_posted',
2468                                             header : 'Posted',
2469                                             width : 50,
2470                                             renderer : function(v,x,r) { 
2471                                                 
2472                                                 var state = v   ?  '-checked' : '';
2473                                                                                 
2474                                                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
2475                                              }
2476                                         }
2477                                     ]
2478                                 }
2479                             }
2480                         ],
2481                         center : {
2482                             xtype: 'LayoutRegion',
2483                             xns: Roo
2484                         },
2485                         east : {
2486                             xtype: 'LayoutRegion',
2487                             xns: Roo,
2488                             split : true,
2489                             width : 500
2490                         }
2491                     }
2492                 }
2493             ],
2494             center : {
2495                 xtype: 'LayoutRegion',
2496                 xns: Roo,
2497                 alwaysShowTabs : true,
2498                 tabPosition : 'top',
2499                 toolbar : {
2500                     xtype: 'Toolbar',
2501                     xns: Roo,
2502                     items : [
2503                         {
2504                             xtype: 'Fill',
2505                             xns: Roo.Toolbar
2506                         },
2507                         {
2508                             xtype: 'Button',
2509                             xns: Roo.Toolbar,
2510                             listeners : {
2511                                 click : function ()
2512                                 {
2513                                     var hid = _this.form.findField('pohead_id').getValue();
2514                                 
2515                                     if(!hid.length){
2516                                         Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2517                                         return false;
2518                                     }
2519                                 
2520                                     
2521                                     if (!_this.grid) {
2522                                         _dialog.layout.showPanel(1);
2523                                         doit.defer(500);
2524                                         return;
2525                                     }
2526                                     
2527                                     
2528                                     
2529                                     var doit = function () { 
2530                                         new Pman.Download({
2531                                             grid : _this.grid
2532                                         });
2533                                     }
2534                                     doit();
2535                                             
2536                                    
2537                                 }
2538                             },
2539                             cls : 'x-btn-text-icon',
2540                             text : "Download Purchase Order Items (Excel)",
2541                             icon : rootURL + '/Pman/templates/images/save.gif'
2542                         },
2543                         {
2544                             xtype: 'Button',
2545                             xns: Roo.Toolbar,
2546                             listeners : {
2547                                 render : function (_self)
2548                                 {
2549                                     _this.uploadBtn = _self;
2550                                 }
2551                             },
2552                             text : "Upload Purchase Order",
2553                             menu : {
2554                                 xtype: 'Menu',
2555                                 xns: Roo.menu,
2556                                 items : [
2557                                     {
2558                                         xtype: 'Item',
2559                                         xns: Roo.menu,
2560                                         listeners : {
2561                                             click : function (_self, e)
2562                                             {
2563                                                 var hid = _this.form.findField('pohead_id').getValue();
2564                                                 
2565                                                 if(!hid.length){
2566                                                     Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2567                                                     return false;
2568                                                 }
2569                                                 Pman.Dialog.Image.show(
2570                                                    {
2571                                                         timeout : 60000,
2572                                                         _url : baseURL+'/Xtuple/Import/PurchaseOrder?' + Roo.urlEncode({'pohead_id' : hid})
2573                                                     
2574                                                    },
2575                                                    function () {
2576                                                         if(_this.grid){
2577                                                             _this.grid.footer.onClick('first');
2578                                                         }
2579                                                         Roo.MessageBox.alert("Notice", 'UPLOADED');
2580                                                    }
2581                                                );
2582                                             }
2583                                         },
2584                                         text : "Upload Standard Excel"
2585                                     },
2586                                     {
2587                                         xtype: 'Item',
2588                                         xns: Roo.menu,
2589                                         listeners : {
2590                                             click : function (_self, e)
2591                                             {
2592                                             
2593                                                 var hid = _this.form.findField('pohead_id').getValue();
2594                                                 
2595                                                 if(!hid.length){
2596                                                     Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2597                                                     return false;
2598                                                 }
2599                                                 
2600                                                Pman.Dialog.Image.show(
2601                                                {
2602                                                     _url : baseURL+'/Xtuple/Import/AUPurchaseOrder?' + Roo.urlEncode({'pohead_id' :hid})
2603                                                     
2604                                                },
2605                                                function (data) {
2606                                                    if(_this.grid){
2607                                                         _this.grid.footer.onClick('first');
2608                                                    }
2609                                                    Roo.MessageBox.alert("Notice", 'IMPORTED');
2610                                             
2611                                                });
2612                                             }
2613                                         },
2614                                         text : "Upload AU Import Excel"
2615                                     }
2616                                 ]
2617                             }
2618                         }
2619                     ]
2620                 }
2621             },
2622             buttons : [
2623                 {
2624                     xtype: 'Button',
2625                     xns: Roo,
2626                     listeners : {
2627                         click : function (_self, e)
2628                         {
2629                             _this.dialog.hide();
2630                         }
2631                     },
2632                     text : "Cancel"
2633                 },
2634                 {
2635                     xtype: 'Button',
2636                     xns: Roo,
2637                     listeners : {
2638                         click : function (_self, e)
2639                         {
2640                             if(_this.grid){
2641                                 var ar = [];
2642                         
2643                                 _this.grid.ds.each(function(r) {
2644                                     ar.push({
2645                                         poitem_id : r.data.poitem_id,
2646                                         poitem_itemsite_id : r.data.poitem_itemsite_id,
2647                                         poitem_unitprice : r.data.poitem_unitprice,
2648                                         poitem_qty_ordered : r.data.poitem_qty_ordered
2649                                     });
2650                                         
2651                                 });
2652                                 
2653                                 _this.form.findField('items').setValue(JSON.stringify(ar));
2654                             }
2655                                 
2656                             _this.form.doAction("submit");
2657                         
2658                         },
2659                         render : function (_self)
2660                         {
2661                             _this.saveBtn = _self;
2662                         }
2663                     },
2664                     text : "Save"
2665                 }
2666             ]
2667         });
2668     }
2669 };