Pman.Tab.XtupleMetric.bjs
[Pman.Xtuple] / Pman.Tab.XtupleMetric.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Tab.XtupleMetric = new Roo.XComponent({
6     part     :  ["Xtuple","Metric"],
7     order    : '900-Pman.Tab.XtupleMetric',
8     region   : 'center',
9     parent   : 'Pman.Admin',
10     name     : "unnamed module",
11     disabled : false, 
12     permname : '', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'GridPanel',
19             xns: Roo,
20             listeners : {
21                 activate : function() {
22                     _this.panel = this;
23                     if (_this.grid) {
24                         _this.grid.footer.onClick('first');
25                     }
26                 }
27             },
28             background : true,
29             fitContainer : true,
30             fitToframe : true,
31             region : 'center',
32             tableName : 'metric',
33             title : "Metric",
34             grid : {
35                 xtype: 'EditorGrid',
36                 xns: Roo.grid,
37                 listeners : {
38                     render : function() 
39                     {
40                         _this.grid = this; 
41                         if (_this.panel.active) {
42                            this.footer.onClick('first');
43                         }
44                     },
45                     beforeedit : function (e)
46                     {
47                         var r = e.record.data.poitem_qty_received * 1;
48                         
49                         if(r > 0){
50                             Roo.MessageBox.alert("Error", "This item has been receipted");
51                             return false;
52                         }
53                         
54                         var status = _this.form.findField('pohead_status').getValue();
55                         
56                         if(status == 'C'){
57                             Roo.MessageBox.alert("Error", "This PO has been closed");
58                             return false;
59                         }
60                         
61                         
62                     }
63                 },
64                 autoExpandColumn : 'metric_value',
65                 clicksToEdit : 1,
66                 loadMask : true,
67                 dataSource : {
68                     xtype: 'Store',
69                     xns: Roo.data,
70                     listeners : {
71                         beforeload : function (_self, o){
72                             o.params = o.params || {};
73                             var hid = _this.form.findField('pohead_id').getValue();
74                             
75                             if(!hid.length){
76                                 return false;
77                             }
78                             
79                             o.params.poitem_pohead_id = hid;
80                             o.params._with_item = 1;
81                             o.params._roo_office = _this.data.office ? _this.data.office : baseURL.split('/').pop().substr(0,2);
82                         
83                         },
84                         load : function (_self, records, options)
85                         {
86                             _this.grid.footer.updateSummary();
87                         }
88                     },
89                     remoteSort : true,
90                     sortInfo : { field : 'poitem_linenumber', direction: 'ASC' },
91                     proxy : {
92                         xtype: 'HttpProxy',
93                         xns: Roo.data,
94                         method : 'GET',
95                         timeout : 90000,
96                         url : baseURL + '/Xtuple/Roo/Poitem.php'
97                     },
98                     reader : {
99                         xtype: 'JsonReader',
100                         xns: Roo.data,
101                         id : 'poitem_id',
102                         root : 'data',
103                         totalProperty : 'total',
104                         fields : [
105                             {
106                                 'name': 'poitem_id',
107                                 'type': 'int'
108                             }
109                         ]
110                     }
111                 },
112                 toolbar : {
113                     xtype: 'Toolbar',
114                     xns: Roo,
115                     items : [
116                         {
117                             xtype: 'Button',
118                             xns: Roo.Toolbar,
119                             listeners : {
120                                 click : function()
121                                 {
122                                     var status = _this.form.findField('pohead_status').getValue();
123                                     
124                                     if(status == 'C'){
125                                         Roo.MessageBox.alert("Error", "This PO has been closed");
126                                         return;
127                                     }
128                                     
129                                     var ct  =    _this.grid.ds.getCount();
130                                     
131                                     var last = ct ? _this.grid.ds.getAt(ct-1).data.poitem_linenumber * 1 + 1 : 1;
132                                     
133                                     var dt = _this.form.findField('pohead_orderdate').getValue();
134                                     
135                                     var nr = _this.grid.ds.reader.newRow({
136                                         poitem_id : 0,
137                                         poitem_linenumber : last,
138                                         item_number : '',
139                                         item_descrip1 : '',
140                                         poitem_duedate : dt,
141                                         poitem_qty_ordered : 1,
142                                         poitem_unitprice : 0
143                                     });
144                                     
145                                     _this.grid.stopEditing();
146                                     _this.grid.ds.insert(_this.grid.ds.getCount(), nr); 
147                                     _this.grid.startEditing(_this.grid.ds.getCount()-1, 1);
148                                 }
149                             },
150                             cls : 'x-btn-text-icon',
151                             text : "Add",
152                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
153                         },
154                         {
155                             xtype: 'Button',
156                             xns: Roo.Toolbar,
157                             listeners : {
158                                 click : function ()
159                                 {
160                                     var status = _this.form.findField('pohead_status').getValue();
161                                     
162                                     if(status == 'C'){
163                                         Roo.MessageBox.alert("Error", "This PO has been closed");
164                                         return;
165                                     }
166                                     
167                                     var cs = _this.grid.getSelectionModel().getSelectedCell();
168                                     if (!cs) {
169                                         Roo.MessageBox.alert("Error", "Select a cell");
170                                         return;
171                                     }
172                                     _this.grid.stopEditing();
173                                     var r = _this.grid.ds.getAt(cs[0]);
174                                     
175                                     if(r.data.poitem_qty_received * 1 > 0){
176                                         Roo.MessageBox.alert("Error", "This item has been receipted");
177                                         return;
178                                     }
179                                     
180                                     
181                                     _this.grid.ds.remove(r);
182                                    
183                                 }
184                             },
185                             cls : 'x-btn-text-icon',
186                             text : "Remove",
187                             icon : rootURL + '/Pman/templates/images/trash.gif'
188                         }
189                     ]
190                 },
191                 footer : {
192                     xtype: 'PagingToolbar',
193                     xns: Roo,
194                     displayInfo : true,
195                     emptyMsg : "No Item found",
196                     pageSize : 100,
197                     updateSummary : function() {
198                     \r
199                         var f = this;\r
200                         new Pman.Request({\r
201                             url : baseURL + '/Xtuple/Roo/Poitem',\r
202                             method : 'GET',\r
203                             params : {
204                                 _roo_office : _this.data.office ? _this.data.office : baseURL.split('/').pop().substr(0,2),\r
205                                 _totals : 1,\r
206                                 poitem_pohead_id : _this.form.findField('pohead_id').getValue()\r
207                             },\r
208                             success : function(d) {
209                                 Roo.log(d);\r
210                                 f.displayEl.update(String.format(\r
211                                     "{0} items | Total : {1} {2}",\r
212                                     d.data[0].count_item,\r
213                                     _this.form.findField('pohead_curr_id').el.dom.value,\r
214                                     d.data[0].totals\r
215                                 ));\r
216                                     \r
217                             }\r
218                         });\r
219                     
220                     }
221                 },
222                 colModel : [
223                     {
224                         xtype: 'ColumnModel',
225                         xns: Roo.grid,
226                         align : 'right',
227                         dataIndex : 'poitem_linenumber',
228                         header : 'Line#',
229                         width : 50,
230                         renderer : function(v) { return String.format('{0}', v); }
231                     },
232                     {
233                         xtype: 'ColumnModel',
234                         xns: Roo.grid,
235                         dataIndex : 'item_number',
236                         header : 'Item code',
237                         width : 100,
238                         renderer : function(v) { return String.format('{0}', v); },
239                         editor : {
240                             xtype: 'GridEditor',
241                             xns: Roo.grid,
242                             field : {
243                                 xtype: 'ComboBox',
244                                 xns: Roo.form,
245                                 listeners : {
246                                     beforeselect : function (combo, record, index)
247                                     {
248                                       var ar = _this.grid.activeEditor.record;
249                                       
250                                       (function() { 
251                                           ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
252                                           ar.set('poitem_itemsite_id', record.data.itemsite_id);
253                                       }).defer(100);
254                                       
255                                     }
256                                 },
257                                 allowBlank : false,
258                                 displayField : 'itemsite_item_id_item_number',
259                                 editable : true,
260                                 emptyText : "Select item",
261                                 forceSelection : true,
262                                 hiddenName : 'itemsite_item_id_item_number',
263                                 listWidth : 400,
264                                 loadingText : "Searching...",
265                                 minChars : 2,
266                                 name : 'item_number',
267                                 pageSize : 20,
268                                 qtip : "Select item",
269                                 queryParam : 'query[number]',
270                                 selectOnFocus : true,
271                                 tpl : '<div class="x-grid-cell-text x-btn button"><b>{itemsite_item_id_item_number}</b> - {itemsite_item_id_item_descrip1} </div>',
272                                 triggerAction : 'all',
273                                 typeAhead : false,
274                                 valueField : 'item_number',
275                                 store : {
276                                     xtype: 'Store',
277                                     xns: Roo.data,
278                                     listeners : {
279                                         beforeload : function (_self, o){
280                                             o.params = o.params || {}; 
281                                             o.params.itemsite_posupply = 1;
282                                         }
283                                     },
284                                     remoteSort : true,
285                                     sortInfo : { direction : 'ASC', field: 'item_number' },
286                                     proxy : {
287                                         xtype: 'HttpProxy',
288                                         xns: Roo.data,
289                                         method : 'GET',
290                                         url : baseURL + '/Roo/itemsite.php'
291                                     },
292                                     reader : {
293                                         xtype: 'JsonReader',
294                                         xns: Roo.data,
295                                         id : 'itemsite_id',
296                                         root : 'data',
297                                         totalProperty : 'total',
298                                         fields : [{"name":"item_id","type":"int"},"item_number"]
299                                     }
300                                 }
301                             }
302                         }
303                     },
304                     {
305                         xtype: 'ColumnModel',
306                         xns: Roo.grid,
307                         dataIndex : 'item_descrip1',
308                         header : 'Item description',
309                         width : 150,
310                         renderer : function(v) { return String.format('{0}', v); }
311                     },
312                     {
313                         xtype: 'ColumnModel',
314                         xns: Roo.grid,
315                         dataIndex : 'poitem_duedate',
316                         header : 'Due date',
317                         width : 100,
318                         renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
319                     },
320                     {
321                         xtype: 'ColumnModel',
322                         xns: Roo.grid,
323                         align : 'right',
324                         dataIndex : 'poitem_qty_ordered',
325                         header : 'Ordered',
326                         width : 75,
327                         renderer : function(v) { return String.format('{0}', v); },
328                         editor : {
329                             xtype: 'GridEditor',
330                             xns: Roo.grid,
331                             field : {
332                                 xtype: 'NumberField',
333                                 xns: Roo.form,
334                                 allowDecimals : false,
335                                 decimalPrecision : 0,
336                                 minValue : 1,
337                                 style : 'text-align:right'
338                             }
339                         }
340                     },
341                     {
342                         xtype: 'ColumnModel',
343                         xns: Roo.grid,
344                         align : 'right',
345                         dataIndex : 'poitem_qty_received',
346                         header : 'Received',
347                         width : 75,
348                         renderer : function(v,x,r) { 
349                             return String.format(
350                                 r.data.poitem_qty_ordered != (v-r.data.poitem_qty_returned) ? '<span style="color:red">{0}</span>':  '{0}',
351                                  v - r.data.poitem_qty_returned);
352                         }
353                     },
354                     {
355                         xtype: 'ColumnModel',
356                         xns: Roo.grid,
357                         align : 'right',
358                         dataIndex : 'poitem_qty_vouchered',
359                         header : 'Vouchered',
360                         width : 65,
361                         renderer : function(v,x,r) { 
362                             return String.format(
363                                 r.data.poitem_qty_ordered != v ? '<span style="color:red">{0}</span>':  '{0}',
364                                  v);
365                         }
366                     },
367                     {
368                         xtype: 'ColumnModel',
369                         xns: Roo.grid,
370                         align : 'right',
371                         dataIndex : 'poitem_unitprice',
372                         header : 'Unit price',
373                         width : 100,
374                         renderer : function(v) { return String.format('{0}', (v || v == 0) ? parseFloat(v).toFixed(3) : ''); },
375                         editor : {
376                             xtype: 'GridEditor',
377                             xns: Roo.grid,
378                             field : {
379                                 xtype: 'NumberField',
380                                 xns: Roo.form,
381                                 allowBlank : false,
382                                 allowDecimals : false,
383                                 decimalPrecision : 0,
384                                 minValue : 1,
385                                 style : 'text-align:right'
386                             }
387                         }
388                     }
389                 ]
390             }
391         };
392     }
393 });