Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleShipment.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.XtupleShipment = {
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             closable : true,
34             collapsible : false,
35             height : 620,
36             modal : true,
37             resizable : false,
38             title : "Edit Shipment / Delivery",
39             width : 800,
40             items : [
41                 {
42                     xtype: 'ContentPanel',
43                     xns: Roo,
44                     region : 'north',
45                     items : [
46                         {
47                             xtype: 'Form',
48                             xns: Roo.form,
49                             listeners : {
50                                 actioncomplete : function(_self,action)
51                                 {
52                                     if (action.type == 'setdata') {
53                                 
54                                         if (_this.data.shiphead_id) {
55                                             this.load({ method: 'GET', params: { '_id' : _this.data.shiphead_id }});
56                                            return;
57                                        }
58                                        _this.grid.ds.load({});
59                                             _this.saveBtn.show();       
60                                        
61                                     }
62                                     if (action.type == 'load') {
63                                         var d = action.result.data;
64                                         
65                                 
66                                         if (d.shiphead_shipped *1 > 0) {
67                                                 Roo.MessageBox.alert(
68                                                         "Warning", "This shipment has been confirmed, you must unconfirm it before you can edit it"
69                                                     );
70                                 
71                                                 _this.saveBtn.hide();
72                                             
73                                         } else {
74                                             _this.saveBtn.show();
75                                         }
76                                         _this.grid.ds.load({});
77                                          
78                                         return;
79                                     }
80                                     if (action.type =='submit') {
81                                     
82                                         _this.dialog.hide();
83                                     
84                                          if (_this.callback) {
85                                             _this.callback.call(_this, _this.form.getValues());
86                                          }
87                                          _this.form.reset();
88                                          return;
89                                     }
90                                 },
91                                 rendered : function (form)
92                                 {
93                                     _this.form= form;
94                                 }
95                             },
96                             method : 'POST',
97                             style : 'margin:10px;',
98                             timeout : 60000,
99                             url : baseURL + '/Roo/shiphead.php',
100                             items : [
101                                 {
102                                     xtype: 'Column',
103                                     xns: Roo.form,
104                                     width : 370,
105                                     items : [
106                                         {
107                                             xtype: 'FieldSet',
108                                             xns: Roo.form,
109                                             legend : "Details",
110                                             style : 'width:350px;height:193px;',
111                                             items : [
112                                                 {
113                                                     xtype: 'Row',
114                                                     xns: Roo.form,
115                                                     labelAlign : 'right',
116                                                     labelWidth : 60,
117                                                     width : 340,
118                                                     items : [
119                                                         {
120                                                             xtype: 'TextField',
121                                                             xns: Roo.form,
122                                                             fieldLabel : 'Number#',
123                                                             name : 'shiphead_number',
124                                                             readOnly : true,
125                                                             value : "Automatic",
126                                                             width : 100
127                                                         }
128                                                     ]
129                                                 },
130                                                 {
131                                                     xtype: 'Column',
132                                                     xns: Roo.form,
133                                                     labelAlign : 'right',
134                                                     labelWidth : 60,
135                                                     width : 340,
136                                                     items : [
137                                                         {
138                                                             xtype: 'DateField',
139                                                             xns: Roo.form,
140                                                             allowBlank : false,
141                                                             fieldLabel : 'Date',
142                                                             format : 'Y-m-d',
143                                                             name : 'shiphead_shipdate',
144                                                             width : 100
145                                                         },
146                                                         {
147                                                             xtype: 'TextField',
148                                                             xns: Roo.form,
149                                                             fieldLabel : 'From',
150                                                             name : 'shiphead_location_id_location_name',
151                                                             readOnly : true,
152                                                             width : 270
153                                                         },
154                                                         {
155                                                             xtype: 'TextField',
156                                                             xns: Roo.form,
157                                                             fieldLabel : 'To',
158                                                             name : 'shiphead_shipto_id_shipto_name',
159                                                             width : 270
160                                                         },
161                                                         {
162                                                             xtype: 'TextField',
163                                                             xns: Roo.form,
164                                                             fieldLabel : 'Via',
165                                                             name : 'shiphead_shipvia',
166                                                             width : 270
167                                                         },
168                                                         {
169                                                             xtype: 'TextField',
170                                                             xns: Roo.form,
171                                                             fieldLabel : 'Tracking',
172                                                             name : 'shiphead_tracknum',
173                                                             width : 270
174                                                         }
175                                                     ]
176                                                 }
177                                             ]
178                                         }
179                                     ]
180                                 },
181                                 {
182                                     xtype: 'Column',
183                                     xns: Roo.form,
184                                     width : 350,
185                                     items : [
186                                         {
187                                             xtype: 'FieldSet',
188                                             xns: Roo.form,
189                                             hideLabels : true,
190                                             legend : "Delivery Notes",
191                                             style : 'width:330px',
192                                             items : [
193                                                 {
194                                                     xtype: 'TextArea',
195                                                     xns: Roo.form,
196                                                     fieldLabel : 'Delivery Notes',
197                                                     name : 'shiphead_delivery_note',
198                                                     width : 320
199                                                 }
200                                             ]
201                                         },
202                                         {
203                                             xtype: 'FieldSet',
204                                             xns: Roo.form,
205                                             hideLabels : true,
206                                             legend : "Shipment Notes",
207                                             style : 'width:330px',
208                                             items : [
209                                                 {
210                                                     xtype: 'TextArea',
211                                                     xns: Roo.form,
212                                                     fieldLabel : 'Shipment Notes',
213                                                     name : 'shiphead_notes',
214                                                     width : 320
215                                                 }
216                                             ]
217                                         }
218                                     ]
219                                 },
220                                 {
221                                     xtype: 'Hidden',
222                                     xns: Roo.form,
223                                     name : 'shiphead_order_id'
224                                 },
225                                 {
226                                     xtype: 'Hidden',
227                                     xns: Roo.form,
228                                     name : 'shiphead_sfstatus',
229                                     value : "N"
230                                 },
231                                 {
232                                     xtype: 'Hidden',
233                                     xns: Roo.form,
234                                     name : 'shiphead_location_id'
235                                 },
236                                 {
237                                     xtype: 'Hidden',
238                                     xns: Roo.form,
239                                     name : 'shiphead_shipto_id'
240                                 },
241                                 {
242                                     xtype: 'Hidden',
243                                     xns: Roo.form,
244                                     name : 'shiphead_id',
245                                     width : 100
246                                 },
247                                 {
248                                     xtype: 'Hidden',
249                                     xns: Roo.form,
250                                     name : 'shipitems',
251                                     width : 100
252                                 }
253                             ]
254                         }
255                     ]
256                 },
257                 {
258                     xtype: 'GridPanel',
259                     xns: Roo,
260                     listeners : {
261                         activate : function() {
262                             _this.panel = this;
263                             
264                             if (_this.isBuilder) {
265                                 return;
266                             }
267                             
268                            
269                             if (_this.grid) {
270                                 _this.grid.ds.load({});
271                             }
272                         }
273                     },
274                     fitContainer : true,
275                     fitToframe : true,
276                     region : 'center',
277                     tableName : 'coitem',
278                     title : "Order Items",
279                     grid : {
280                         xtype: 'EditorGrid',
281                         xns: Roo.grid,
282                         listeners : {
283                             render : function() 
284                             {
285                                 _this.grid = this; 
286                                 //_this.dialog = Pman.Dialog.FILL_IN
287                                 if (_this.panel.active) {
288                                    this.ds.load({});
289                                 }
290                             },
291                             rowdblclick : function (_self, rowIndex, e)
292                             {
293                                 
294                             },
295                             afteredit : function (e)
296                             {
297                                 //Roo.log('afteredit');
298                                // Roo.log(e);
299                                 if (e.field == 'item_number') {
300                                     // afterselect handles this...
301                                     return;
302                                 }
303                                 e.record.commit();
304                             }
305                         },
306                         autoExpandColumn : 'item_descrip1',
307                         clicksToEdit : 1,
308                         loadMask : true,
309                         sm : {
310                             xtype: 'CellSelectionModel',
311                             xns: Roo.grid,
312                             listeners : {
313                                 tabend : function (_self)
314                                 {
315                                     _this.addItemBtn.fireEvent('click', _this.addItemBtn);
316                                 }
317                             },
318                             enter_is_tab : true
319                         },
320                         dataSource : {
321                             xtype: 'Store',
322                             xns: Roo.data,
323                             listeners : {
324                                 beforeload : function (_self,o) {
325                                     if (! _this.form.findField('shiphead_order_id').getValue()) {
326                                         return false;
327                                     }
328                                     o.params = o.params || {};
329                                     
330                                     o.params.coitem_cohead_id = _this.form.findField('shiphead_order_id').getValue();
331                                     o.params.limit = 999;
332                                     o.params._stocked_only = 1;
333                                     o.params.shiphead_id = _this.form.findField('shiphead_id').getValue();
334                                     o.params.coitem_shipto_id = _this.form.findField('shiphead_shipto_id').getValue();
335                                     o.params['query[coitem_location_src]'] = _this.form.findField('shiphead_location_id').getValue();
336                                      
337                                     
338                                 }
339                             },
340                             remoteSort : true,
341                             sortInfo : { field : 'coitem_linenumber', direction: 'ASC' },
342                             proxy : {
343                                 xtype: 'HttpProxy',
344                                 xns: Roo.data,
345                                 method : 'GET',
346                                 url : baseURL + '/Roo/coitem.php'
347                             },
348                             reader : {
349                                 xtype: 'JsonReader',
350                                 xns: Roo.data,
351                                 totalProperty : 'total',
352                                 root : 'data',
353                                 id : 'id',
354                                 fields : [
355                                     {
356                                         'name': 'coitem_linenumber',
357                                         'type': 'int'
358                                     },
359                                     {
360                                         'name': 'coitem_itemsite_id',
361                                         'type': 'int'
362                                     },
363                                     {
364                                         'name': 'coitem_qtyord'
365                                     },
366                                     {
367                                         'name': 'coitem_unitcost'
368                                     },
369                                     {
370                                         'name': 'coitem_price'
371                                     },
372                                     {
373                                         'name': 'coitem_custprice'
374                                     },
375                                     {
376                                         'name': 'coitem_qtyreturned'
377                                     },
378                                     {
379                                         'name': 'coitem_prcost'
380                                     },
381                                     {
382                                         'name': 'coitem_price_uom_id',
383                                         'type': 'int'
384                                     },
385                                     {
386                                         'name': 'coitem_qtyreserved'
387                                     }
388                                 ]
389                             }
390                         },
391                         toolbar : {
392                             xtype: 'Toolbar',
393                             xns: Roo,
394                             items : [
395                                 {
396                                     xtype: 'Button',
397                                     xns: Roo.Toolbar,
398                                     listeners : {
399                                         click : function (_self, e)
400                                         {
401                                             _this.grid.ds.each(function(r) {
402                                                 r.set('shipitem_qty', Math.max(r.data.coitem_qtyord - r.data.shipitem_shipped));
403                                             });
404                                         }
405                                     },
406                                     text : "Fullfill all"
407                                 },
408                                 {
409                                     xtype: 'Separator',
410                                     xns: Roo.Toolbar
411                                 },
412                                 {
413                                     xtype: 'TextItem',
414                                     xns: Roo.Toolbar,
415                                     text : "Restore From"
416                                 },
417                                 {
418                                     xtype: 'ComboBox',
419                                     xns: Roo.form,
420                                     listeners : {
421                                         select : function (combo, record, index)
422                                         {
423                                           //_this.grid.footer.onClick('first');
424                                           
425                                            (function() { 
426                                             combo.setValue('');
427                                            }).defer(100);
428                                            var data = record.json.data;
429                                            
430                                            _this.grid.ds.each(function (r) {
431                                                 if (typeof(data[r.data.coitem_itemsite_id+'']) == 'undefined') {
432                                                     return;
433                                                 }
434                                                 r.set('shipitem_qty', parseInt(data[r.data.coitem_itemsite_id+'']));
435                                            
436                                            });
437                                            
438                                            
439                                            
440                                           
441                                         }
442                                     },
443                                     allowBlank : true,
444                                     displayField : 'name',
445                                     editable : false,
446                                     emptyText : "Restore from",
447                                     forceSelection : true,
448                                     listWidth : 300,
449                                     loadingText : "Searching...",
450                                     name : 'name',
451                                     pageSize : 20,
452                                     qtip : "Select Action",
453                                     queryParam : 'query[action]',
454                                     selectOnFocus : true,
455                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
456                                     triggerAction : 'all',
457                                     typeAhead : true,
458                                     valueField : 'name',
459                                     width : 300,
460                                     store : {
461                                         xtype: 'Store',
462                                         xns: Roo.data,
463                                         listeners : {
464                                             beforeload : function (_self, o)
465                                             {
466                                                 o.params = o.params || {};
467                                                 // staff can see all logs, other companies can only see their own.
468                                                  
469                                                 o.params._stash = _this.form.findField('shiphead_order_id').getValue();
470                                             
471                                             }
472                                         },
473                                         remoteSort : true,
474                                         sortInfo : { field : 'action' , direction : 'ASC' },
475                                         proxy : {
476                                             xtype: 'HttpProxy',
477                                             xns: Roo.data,
478                                             method : 'GET',
479                                             url : baseURL + '/Roo/Shiphead.php'
480                                         },
481                                         reader : {
482                                             xtype: 'JsonReader',
483                                             xns: Roo.data,
484                                             id : 'name',
485                                             root : 'data',
486                                             totalProperty : 'total',
487                                             fields : [
488                                                 {
489                                                     'name': 'name',
490                                                     'type': 'string'
491                                                 }
492                                              
493                                             ]
494                                         }
495                                     }
496                                 },
497                                 {
498                                     xtype: 'Fill',
499                                     xns: Roo.Toolbar
500                                 },
501                                 {
502                                     xtype: 'Button',
503                                     xns: Roo.Toolbar,
504                                     listeners : {
505                                         click : function()
506                                         {
507                                              _this.grid.ds.each(function(r) {
508                                                 r.set('shipitem_qty', 0);
509                                             });
510                                         }
511                                     },
512                                     text : "Reset"
513                                 }
514                             ]
515                         },
516                         colModel : [
517                             {
518                                 xtype: 'ColumnModel',
519                                 xns: Roo.grid,
520                                 dataIndex : 'coitem_linenumber',
521                                 header : 'Item#',
522                                 sortable : true,
523                                 width : 75,
524                                 renderer : function(v,x,r) {
525                                     if (r.data.coitem_subnumber * 1 > 0)  {
526                                          return String.format('{0}.{1}', v, r.data.coitem_subnumber ); 
527                                      }
528                                      return String.format('{0}', v); 
529                                  }
530                             },
531                             {
532                                 xtype: 'ColumnModel',
533                                 xns: Roo.grid,
534                                 dataIndex : 'item_number',
535                                 header : 'Item Code',
536                                 sortable : true,
537                                 width : 75,
538                                 renderer : function(v) { return String.format('{0}', v); }
539                             },
540                             {
541                                 xtype: 'ColumnModel',
542                                 xns: Roo.grid,
543                                 dataIndex : 'item_descrip1',
544                                 header : 'Item Description',
545                                 width : '150.00',
546                                 renderer : function(v, x, r) {
547                                 
548                                     var vv = v;
549                                     if (r.data.coitem_memo && r.data.coitem_memo.length) {
550                                         vv = r.data.coitem_memo;
551                                     }
552                                     return String.format('{0}', vv); 
553                                  
554                                  }
555                             },
556                             {
557                                 xtype: 'ColumnModel',
558                                 xns: Roo.grid,
559                                 align : 'right',
560                                 dataIndex : 'coitem_qtyord',
561                                 header : 'Ordered Qty',
562                                 width : 100,
563                                 renderer : function(v) { return String.format('{0}', v); }
564                             },
565                             {
566                                 xtype: 'ColumnModel',
567                                 xns: Roo.grid,
568                                 align : 'right',
569                                 dataIndex : 'shipitem_shipped',
570                                 header : 'Remaining Qty',
571                                 width : 100,
572                                 renderer : function(v,x,r) {
573                                 
574                                      return String.format('{0}', r.data.coitem_qtyord - v); 
575                                  }
576                             },
577                             {
578                                 xtype: 'ColumnModel',
579                                 xns: Roo.grid,
580                                 align : 'right',
581                                 dataIndex : 'shipitem_qty',
582                                 header : 'Ship Qty',
583                                 width : 100,
584                                 renderer : function(v,x,r) { 
585                                     
586                                     var vv = parseInt(v);
587                                     vv = isNaN(vv) ? 0 : vv;
588                                     r.data.shipitem_qty = vv; // get rid of decimal.
589                                     if (r.data.shipitem_shipped + vv > r.data.coitem_qtyord) {
590                                             return String.format('<b style="background-color:red;color:yellow">{0}</b>', vv); 
591                                     }
592                                     // not fully fullfilled
593                                     if (r.data.shipitem_shipped + vv != r.data.coitem_qtyord) {
594                                             return String.format('<b style="background-color:blue;color:yellow">{0}</b>', vv); 
595                                     }   
596                                     return String.format('{0}', vv); 
597                                     
598                                 },
599                                 editor : {
600                                     xtype: 'GridEditor',
601                                     xns: Roo.grid,
602                                     field : {
603                                         xtype: 'NumberField',
604                                         xns: Roo.form,
605                                         allowDecimals : true,
606                                         allowNegative : false,
607                                         decimalPrecision : 0,
608                                         minValue : 0,
609                                         style : 'text-align:right'
610                                     }
611                                 }
612                             }
613                         ]
614                     }
615                 }
616             ],
617             center : {
618                 xtype: 'LayoutRegion',
619                 xns: Roo
620             },
621             north : {
622                 xtype: 'LayoutRegion',
623                 xns: Roo,
624                 height : 230
625             },
626             buttons : [
627                 {
628                     xtype: 'Button',
629                     xns: Roo,
630                     listeners : {
631                         click : function (_self, e)
632                         {
633                             _this.dialog.hide();
634                         }
635                     },
636                     text : "Cancel"
637                 },
638                 {
639                     xtype: 'Button',
640                     xns: Roo,
641                     listeners : {
642                         click : function (_self, e)
643                         {
644                             // do some checks?
645                              Roo.Ajax.timeout = 120000; // 2 minutes timeout..
646                              var ar = [];
647                         
648                             _this.grid.ds.each(function(r) {
649                                 ar.push({
650                                     shipitem_orderitem_id : r.data.coitem_id,
651                                     shipitem_qty : r.data.shipitem_qty 
652                                 });
653                                 
654                             });
655                             
656                             _this.form.findField('shipitems').setValue(JSON.stringify(ar));
657                             _this.form.doAction("submit");
658                             
659                         },
660                         render : function (_self)
661                         {
662                          _this.saveBtn = _self;
663                         }
664                     },
665                     text : "Save"
666                 }
667             ]
668         });
669     }
670 };