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