Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleSalesOrderNew.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.XtupleSalesOrderNew = {
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             listeners : {
34                 show : function (_self)
35                 {
36                     _this.form.findField('cohead_cust_id').focus();
37                 }
38             },
39             closable : false,
40             height : 180,
41             modal : true,
42             resizable : false,
43             title : "Create new Sales Order",
44             width : 500,
45             items : [
46                 {
47                     xtype: 'ContentPanel',
48                     xns: Roo,
49                     region : 'center',
50                     items : [
51                         {
52                             xtype: 'Form',
53                             xns: Roo.form,
54                             listeners : {
55                                 rendered : function (form)
56                                 {
57                                   _this.form = form;
58                                 }
59                             },
60                             items : [
61                                 {
62                                     xtype: 'ComboBox',
63                                     xns: Roo.form,
64                                     listeners : {
65                                         add : function (combo)
66                                         {
67                                          
68                                             Pman.Dialog.XtupleCustomer.show( { id : 0 } , function(res) {
69                                                 Roo.log(res);
70                                                 // fill in customer
71                                                 _this.form.setValues({
72                                                     cohead_cust_id: res.cust_id,
73                                                     cohead_cust_id_cust_name : res.cust_name,
74                                                     cohead_curr_id : res.cust_curr_id,
75                                                     cohead_curr_id_curr_name : res.cust_curr_id_curr_name
76                                                 });
77                                                 
78                                                 
79                                             })
80                                             
81                                         },
82                                         select : function (combo, record, index)
83                                         {
84                                            
85                                            Roo.log(record);
86                                             _this.form.setValues({
87                                                 cohead_curr_id : record.data.cust_curr_id,
88                                                 cohead_curr_id_curr_name : record.data.cust_curr_id_curr_name
89                                             
90                                             });
91                                         }
92                                     },
93                                     allowBlank : false,
94                                     displayField : 'cust_name',
95                                     editable : true,
96                                     fieldLabel : 'Select Customer',
97                                     forceSelection : true,
98                                     hiddenName : 'cohead_cust_id',
99                                     listWidth : 400,
100                                     loadingText : "Searching...",
101                                     minChars : 2,
102                                     name : 'cohead_cust_id_cust_name',
103                                     pageSize : 20,
104                                     qtip : "Select custinfo",
105                                     queryParam : 'query[cust_name_begin]',
106                                     selectOnFocus : true,
107                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{cust_name}</b>  ({cust_number})</div>',
108                                     triggerAction : 'all',
109                                     typeAhead : true,
110                                     valueField : 'cust_id',
111                                     width : 300,
112                                     store : {
113                                         xtype: 'Store',
114                                         xns: Roo.data,
115                                         listeners : {
116                                             beforeload : function (_self, o){
117                                                 o.params = o.params || {};
118                                             
119                                               //  o.params['search[with_location]'] = 1;
120                                             }
121                                         },
122                                         remoteSort : true,
123                                         sortInfo : { direction : 'ASC', field: 'cust_name' },
124                                         proxy : {
125                                             xtype: 'HttpProxy',
126                                             xns: Roo.data,
127                                             method : 'GET',
128                                             url : baseURL + '/Roo/custinfo.php'
129                                         },
130                                         reader : {
131                                             xtype: 'JsonReader',
132                                             xns: Roo.data,
133                                             id : 'cust_id',
134                                             root : 'data',
135                                             totalProperty : 'total',
136                                             fields : [{"name":"cust_id","type":"int"},"cust_name"]
137                                         }
138                                     }
139                                 },
140                                 {
141                                     xtype: 'ComboBox',
142                                     xns: Roo.form,
143                                     allowBlank : false,
144                                     displayField : 'curr_name',
145                                     editable : false,
146                                     emptyText : "Select Currency",
147                                     fieldLabel : 'Currency',
148                                     forceSelection : true,
149                                     hiddenName : 'cohead_curr_id',
150                                     listWidth : 400,
151                                     loadingText : "Searching...",
152                                     minChars : 2,
153                                     name : 'cohead_curr_id_curr_name',
154                                     pageSize : 20,
155                                     qtip : "Select Currency",
156                                     queryParam : 'query[curr_name]',
157                                     selectOnFocus : true,
158                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{curr_name}</b> </div>',
159                                     triggerAction : 'all',
160                                     typeAhead : true,
161                                     valueField : 'curr_id',
162                                     width : 285,
163                                     store : {
164                                         xtype: 'Store',
165                                         xns: Roo.data,
166                                         listeners : {
167                                             beforeload : function (_self, o){
168                                                 o.params = o.params || {};
169                                                 
170                                             }
171                                         },
172                                         remoteSort : true,
173                                         sortInfo : { direction : 'ASC', field: 'curr_symbol' },
174                                         proxy : {
175                                             xtype: 'HttpProxy',
176                                             xns: Roo.data,
177                                             method : 'GET',
178                                             url : baseURL + '/Roo/curr_symbol.php'
179                                         },
180                                         reader : {
181                                             xtype: 'JsonReader',
182                                             xns: Roo.data,
183                                             id : 'curr_id',
184                                             root : 'data',
185                                             totalProperty : 'total',
186                                             fields : [{"name":"curr_id","type":"int"},"curr_symbol"]
187                                         }
188                                     }
189                                 }
190                             ]
191                         }
192                     ]
193                 }
194             ],
195             center : {
196                 xtype: 'LayoutRegion',
197                 xns: Roo
198             },
199             buttons : [
200                 {
201                     xtype: 'Button',
202                     xns: Roo,
203                     listeners : {
204                         click : function (_self, e)
205                         {
206                            _this.dialog.hide();
207                          
208                          }
209                     },
210                     text : "Cancel"
211                 },
212                 {
213                     xtype: 'Button',
214                     xns: Roo,
215                     listeners : {
216                         click : function (_self, e)
217                         {
218                            //_this.findField('cuinfo_
219                            
220                            // check if customer is filled in.
221                            if (_this.form.findField('cohead_cust_id').getValue() < 1) {
222                                 Roo.MessageBox.alert("Error", "Select a customer");
223                                 return;
224                            }
225                            
226                            var data = _this.form.getFieldValues();
227                            var c = _this.form.findField('cohead_cust_id').lastData;
228                         
229                            var cur = _this.form.findField('cohead_curr_id').lastData;   
230                            
231                            data.cohead_curr_id      = cur.curr_id;
232                         //   data.cohead_curr_id_curr_name = cur.cust_curr_id_curr_name;
233                            data.cohead_curr_id_curr_name = cur.curr_name;
234                            
235                            data.cohead_terms_id      = c.cust_terms_id;
236                            data.cohead_terms_id_terms_descrip = c.cust_terms_id_terms_descrip;
237                            
238                            // fill in staff in/c..
239                            
240                            data.cohead_salesrep_id =  Pman.Login.authUser.salesrep.salesrep_id;
241                            data.cohead_salesrep_id_salesrep_name =  Pman.Login.authUser.salesrep.salesrep_name;
242                            
243                            data.cohead_display_salesrep_id = c.cust_salesrep_id;
244                            data.cohead_display_salesrep_id_salesrep_name = c.cust_salesrep_id_salesrep_name;
245                            
246                            data.cohead_orderdate = new Date();
247                            
248                            
249                            data.cohead_location_src = c.default_location_id;
250                            data.cohead_location_src_location_name = c.default_location_name;
251                            
252                            data.cohead_taxzone_id = c.cust_taxzone_id_taxzone_id;
253                            data.cohead_taxzone_id_taxzone_descrip = c.cust_taxzone_id_taxzone_descrip;
254                            
255                            // if customer is online .. .then do not fill this stuff in..
256                            
257                            if (c.cust_custtype_id_custtype_code == 'ONLINE') {
258                                  Pman.Dialog.XtupleSalesOrder.show(data, function() {
259                                     _this.dialog.hide();
260                                     _this.callback()
261                                  });    
262                                  return;
263                              }
264                            
265                            new Pman.Request({
266                                 url : baseURL + '/Roo/cntct.php',
267                                 method : 'GET',
268                                 params : {
269                                     '_id' : c.cust_cntct_id
270                                 },
271                                 success : function (res){
272                                     if(res.data){
273                                         for(var i in res.data) {
274                                             data['cohead_billto_cntct_id_' + i] = res.data[i];
275                                         }
276                                      }
277                                      Pman.Dialog.XtupleSalesOrder.show(data, function() {
278                                         _this.dialog.hide();
279                                         _this.callback()
280                                      }); 
281                                 }
282                             });
283                            
284                            
285                            
286                         }
287                     },
288                     text : "OK"
289                 }
290             ]
291         });
292     }
293 };