Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleCreditMemoNew.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.XtupleCreditMemoNew = {
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('cmhead_cust_id').focus();
37                 }
38             },
39             closable : false,
40             height : 120,
41             modal : true,
42             resizable : false,
43             title : "Create new Credit Memo",
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.findField('cmhed_cust_id_cust_name').setValue(res.cust_id);
72                                                 _this.form.findField('cmhed_cust_id_cust_name').el.dom.value = res.cust_name;
73                                                 
74                                             })
75                                             
76                                         }
77                                     },
78                                     allowBlank : false,
79                                     displayField : 'cust_name',
80                                     editable : true,
81                                     fieldLabel : 'Select Customer',
82                                     forceSelection : true,
83                                     hiddenName : 'cmhead_cust_id',
84                                     listWidth : 400,
85                                     loadingText : "Searching...",
86                                     minChars : 2,
87                                     name : 'cmhead_cust_id_cust_name',
88                                     pageSize : 20,
89                                     qtip : "Select custinfo",
90                                     queryParam : 'query[cust_name]',
91                                     selectOnFocus : true,
92                                     tpl : '<div class="x-grid-cell-text x-btn button">{cust_number}: <b>{cust_name}</b> </div>',
93                                     triggerAction : 'all',
94                                     typeAhead : true,
95                                     valueField : 'cust_id',
96                                     width : 300,
97                                     store : {
98                                         xtype: 'Store',
99                                         xns: Roo.data,
100                                         listeners : {
101                                             beforeload : function (_self, o){
102                                                 o.params = o.params || {};
103                                                 // set more here
104                                                // o.params._with_last_location = 1;
105                                             }
106                                         },
107                                         remoteSort : true,
108                                         sortInfo : { direction : 'ASC', field: 'cust_name' },
109                                         proxy : {
110                                             xtype: 'HttpProxy',
111                                             xns: Roo.data,
112                                             method : 'GET',
113                                             url : baseURL + '/Roo/custinfo.php'
114                                         },
115                                         reader : {
116                                             xtype: 'JsonReader',
117                                             xns: Roo.data,
118                                             id : 'cust_id',
119                                             root : 'data',
120                                             totalProperty : 'total',
121                                             fields : [{"name":"cust_id","type":"int"},"cust_name"]
122                                         }
123                                     }
124                                 }
125                             ]
126                         }
127                     ]
128                 }
129             ],
130             center : {
131                 xtype: 'LayoutRegion',
132                 xns: Roo
133             },
134             buttons : [
135                 {
136                     xtype: 'Button',
137                     xns: Roo,
138                     listeners : {
139                         click : function (_self, e)
140                         {
141                            _this.dialog.hide();
142                          
143                          }
144                     },
145                     text : "Cancel"
146                 },
147                 {
148                     xtype: 'Button',
149                     xns: Roo,
150                     listeners : {
151                         click : function (_self, e)
152                         {
153                            //_this.findField('cuinfo_
154                            
155                            // check if customer is filled in.
156                            if (_this.form.findField('cmhead_cust_id').getValue() < 1) {
157                                 Roo.MessageBox.alert("Error", "Select a customer");
158                                 return;
159                            }
160                            
161                            var data = _this.form.getFieldValues();
162                            var c = _this.form.findField('cmhead_cust_id').lastData;
163                            
164                            data.cmhead_curr_id      = c.cust_curr_id;
165                            data.cmhead_curr_id_curr_name = c.cust_curr_id_curr_name;
166                            
167                            data.cmhead_terms_id      = c.cust_terms_id;
168                            data.cmhead_terms_id_terms_descrip = c.cust_terms_id_terms_descrip;
169                            
170                            // fill in staff in/c..
171                            
172                            data.cmhead_salesrep_id =  Pman.Login.authUser.salesrep.salesrep_id;
173                            data.cmhead_salesrep_id_salesrep_name =  Pman.Login.authUser.salesrep.salesrep_name;
174                            
175                            data.cmhead_docdate = new Date();
176                            
177                            data.cmhead_taxzone_id = c.cust_taxzone_id;
178                            data.cmhead_taxzone_id_taxzone_descrip = c.cust_taxzone_id_taxzone_descrip;
179                            data.cmhead_location_id = c.default_location_id,
180                            data.cmhead_location_id_location_name = c.default_location_name;
181                         
182                            Pman.Dialog.XtupleCreditMemo.show(data, function() {
183                             _this.dialog.hide();
184                             _this.callback();
185                            }); 
186                            
187                         }
188                     },
189                     text : "OK"
190                 }
191             ]
192         });
193     }
194 };