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