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