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                             
74                         }
75                     },
76                     remoteSort : true,
77                     sortInfo : { field : 'metric_name', direction: 'ASC' },
78                     proxy : {
79                         xtype: 'HttpProxy',
80                         xns: Roo.data,
81                         method : 'GET',
82                         timeout : 90000,
83                         url : baseURL + '/Xtuple/Roo/Poitem.php'
84                     },
85                     reader : {
86                         xtype: 'JsonReader',
87                         xns: Roo.data,
88                         id : 'poitem_id',
89                         root : 'data',
90                         totalProperty : 'total',
91                         fields : [
92                             {
93                                 'name': 'poitem_id',
94                                 'type': 'int'
95                             }
96                         ]
97                     }
98                 },
99                 toolbar : {
100                     xtype: 'Toolbar',
101                     xns: Roo,
102                     items : [
103                         {
104                             xtype: 'Button',
105                             xns: Roo.Toolbar,
106                             listeners : {
107                                 click : function()
108                                 {
109                                     var status = _this.form.findField('pohead_status').getValue();
110                                     
111                                     if(status == 'C'){
112                                         Roo.MessageBox.alert("Error", "This PO has been closed");
113                                         return;
114                                     }
115                                     
116                                     var ct  =    _this.grid.ds.getCount();
117                                     
118                                     var last = ct ? _this.grid.ds.getAt(ct-1).data.poitem_linenumber * 1 + 1 : 1;
119                                     
120                                     var dt = _this.form.findField('pohead_orderdate').getValue();
121                                     
122                                     var nr = _this.grid.ds.reader.newRow({
123                                         poitem_id : 0,
124                                         poitem_linenumber : last,
125                                         item_number : '',
126                                         item_descrip1 : '',
127                                         poitem_duedate : dt,
128                                         poitem_qty_ordered : 1,
129                                         poitem_unitprice : 0
130                                     });
131                                     
132                                     _this.grid.stopEditing();
133                                     _this.grid.ds.insert(_this.grid.ds.getCount(), nr); 
134                                     _this.grid.startEditing(_this.grid.ds.getCount()-1, 1);
135                                 }
136                             },
137                             cls : 'x-btn-text-icon',
138                             text : "Add",
139                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
140                         },
141                         {
142                             xtype: 'Button',
143                             xns: Roo.Toolbar,
144                             listeners : {
145                                 click : function ()
146                                 {
147                                     var status = _this.form.findField('pohead_status').getValue();
148                                     
149                                     if(status == 'C'){
150                                         Roo.MessageBox.alert("Error", "This PO has been closed");
151                                         return;
152                                     }
153                                     
154                                     var cs = _this.grid.getSelectionModel().getSelectedCell();
155                                     if (!cs) {
156                                         Roo.MessageBox.alert("Error", "Select a cell");
157                                         return;
158                                     }
159                                     _this.grid.stopEditing();
160                                     var r = _this.grid.ds.getAt(cs[0]);
161                                     
162                                     if(r.data.poitem_qty_received * 1 > 0){
163                                         Roo.MessageBox.alert("Error", "This item has been receipted");
164                                         return;
165                                     }
166                                     
167                                     
168                                     _this.grid.ds.remove(r);
169                                    
170                                 }
171                             },
172                             cls : 'x-btn-text-icon',
173                             text : "Remove",
174                             icon : rootURL + '/Pman/templates/images/trash.gif'
175                         }
176                     ]
177                 },
178                 footer : {
179                     xtype: 'PagingToolbar',
180                     xns: Roo,
181                     displayInfo : true,
182                     emptyMsg : "No Item found",
183                     pageSize : 100,
184                     updateSummary : function() {
185                     \r
186                         var f = this;\r
187                         new Pman.Request({\r
188                             url : baseURL + '/Xtuple/Roo/Poitem',\r
189                             method : 'GET',\r
190                             params : {
191                                 _roo_office : _this.data.office ? _this.data.office : baseURL.split('/').pop().substr(0,2),\r
192                                 _totals : 1,\r
193                                 poitem_pohead_id : _this.form.findField('pohead_id').getValue()\r
194                             },\r
195                             success : function(d) {
196                                 Roo.log(d);\r
197                                 f.displayEl.update(String.format(\r
198                                     "{0} items | Total : {1} {2}",\r
199                                     d.data[0].count_item,\r
200                                     _this.form.findField('pohead_curr_id').el.dom.value,\r
201                                     d.data[0].totals\r
202                                 ));\r
203                                     \r
204                             }\r
205                         });\r
206                     
207                     }
208                 },
209                 colModel : [
210                     {
211                         xtype: 'ColumnModel',
212                         xns: Roo.grid,
213                         align : 'right',
214                         dataIndex : 'poitem_linenumber',
215                         header : 'Line#',
216                         width : 50,
217                         renderer : function(v) { return String.format('{0}', v); }
218                     },
219                     {
220                         xtype: 'ColumnModel',
221                         xns: Roo.grid,
222                         dataIndex : 'item_number',
223                         header : 'Item code',
224                         width : 100,
225                         renderer : function(v) { return String.format('{0}', v); },
226                         editor : {
227                             xtype: 'GridEditor',
228                             xns: Roo.grid,
229                             field : {
230                                 xtype: 'ComboBox',
231                                 xns: Roo.form,
232                                 listeners : {
233                                     beforeselect : function (combo, record, index)
234                                     {
235                                       var ar = _this.grid.activeEditor.record;
236                                       
237                                       (function() { 
238                                           ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
239                                           ar.set('poitem_itemsite_id', record.data.itemsite_id);
240                                       }).defer(100);
241                                       
242                                     }
243                                 },
244                                 allowBlank : false,
245                                 displayField : 'itemsite_item_id_item_number',
246                                 editable : true,
247                                 emptyText : "Select item",
248                                 forceSelection : true,
249                                 hiddenName : 'itemsite_item_id_item_number',
250                                 listWidth : 400,
251                                 loadingText : "Searching...",
252                                 minChars : 2,
253                                 name : 'item_number',
254                                 pageSize : 20,
255                                 qtip : "Select item",
256                                 queryParam : 'query[number]',
257                                 selectOnFocus : true,
258                                 tpl : '<div class="x-grid-cell-text x-btn button"><b>{itemsite_item_id_item_number}</b> - {itemsite_item_id_item_descrip1} </div>',
259                                 triggerAction : 'all',
260                                 typeAhead : false,
261                                 valueField : 'item_number',
262                                 store : {
263                                     xtype: 'Store',
264                                     xns: Roo.data,
265                                     listeners : {
266                                         beforeload : function (_self, o){
267                                             o.params = o.params || {}; 
268                                             o.params.itemsite_posupply = 1;
269                                         }
270                                     },
271                                     remoteSort : true,
272                                     sortInfo : { direction : 'ASC', field: 'item_number' },
273                                     proxy : {
274                                         xtype: 'HttpProxy',
275                                         xns: Roo.data,
276                                         method : 'GET',
277                                         url : baseURL + '/Roo/itemsite.php'
278                                     },
279                                     reader : {
280                                         xtype: 'JsonReader',
281                                         xns: Roo.data,
282                                         id : 'itemsite_id',
283                                         root : 'data',
284                                         totalProperty : 'total',
285                                         fields : [{"name":"item_id","type":"int"},"item_number"]
286                                     }
287                                 }
288                             }
289                         }
290                     },
291                     {
292                         xtype: 'ColumnModel',
293                         xns: Roo.grid,
294                         dataIndex : 'item_descrip1',
295                         header : 'Item description',
296                         width : 150,
297                         renderer : function(v) { return String.format('{0}', v); }
298                     },
299                     {
300                         xtype: 'ColumnModel',
301                         xns: Roo.grid,
302                         dataIndex : 'poitem_duedate',
303                         header : 'Due date',
304                         width : 100,
305                         renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
306                     },
307                     {
308                         xtype: 'ColumnModel',
309                         xns: Roo.grid,
310                         align : 'right',
311                         dataIndex : 'poitem_qty_ordered',
312                         header : 'Ordered',
313                         width : 75,
314                         renderer : function(v) { return String.format('{0}', v); },
315                         editor : {
316                             xtype: 'GridEditor',
317                             xns: Roo.grid,
318                             field : {
319                                 xtype: 'NumberField',
320                                 xns: Roo.form,
321                                 allowDecimals : false,
322                                 decimalPrecision : 0,
323                                 minValue : 1,
324                                 style : 'text-align:right'
325                             }
326                         }
327                     },
328                     {
329                         xtype: 'ColumnModel',
330                         xns: Roo.grid,
331                         align : 'right',
332                         dataIndex : 'poitem_qty_received',
333                         header : 'Received',
334                         width : 75,
335                         renderer : function(v,x,r) { 
336                             return String.format(
337                                 r.data.poitem_qty_ordered != (v-r.data.poitem_qty_returned) ? '<span style="color:red">{0}</span>':  '{0}',
338                                  v - r.data.poitem_qty_returned);
339                         }
340                     },
341                     {
342                         xtype: 'ColumnModel',
343                         xns: Roo.grid,
344                         align : 'right',
345                         dataIndex : 'poitem_qty_vouchered',
346                         header : 'Vouchered',
347                         width : 65,
348                         renderer : function(v,x,r) { 
349                             return String.format(
350                                 r.data.poitem_qty_ordered != v ? '<span style="color:red">{0}</span>':  '{0}',
351                                  v);
352                         }
353                     },
354                     {
355                         xtype: 'ColumnModel',
356                         xns: Roo.grid,
357                         align : 'right',
358                         dataIndex : 'poitem_unitprice',
359                         header : 'Unit price',
360                         width : 100,
361                         renderer : function(v) { return String.format('{0}', (v || v == 0) ? parseFloat(v).toFixed(3) : ''); },
362                         editor : {
363                             xtype: 'GridEditor',
364                             xns: Roo.grid,
365                             field : {
366                                 xtype: 'NumberField',
367                                 xns: Roo.form,
368                                 allowBlank : false,
369                                 allowDecimals : false,
370                                 decimalPrecision : 0,
371                                 minValue : 1,
372                                 style : 'text-align:right'
373                             }
374                         }
375                     }
376                 ]
377             }
378         };
379     }
380 });