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