Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleDiscountOfInvoice.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.XtupleDiscountOfInvoice = {
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('discount').focus();
37                 }
38             },
39             closable : false,
40             height : 150,
41             modal : true,
42             resizable : false,
43             title : "% Discount to Offer",
44             width : 400,
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                             labelWidth : 150,
61                             items : [
62                                 {
63                                     xtype: 'NumberField',
64                                     xns: Roo.form,
65                                     allowBlank : false,
66                                     allowDecimals : true,
67                                     allowNegative : false,
68                                     decimalPrecision : 2,
69                                     fieldLabel : '% Discount to Offer.',
70                                     name : 'discount',
71                                     width : 200
72                                 },
73                                 {
74                                     xtype: 'Hidden',
75                                     xns: Roo.form,
76                                     name : 'invchead_id'
77                                 }
78                             ]
79                         }
80                     ]
81                 }
82             ],
83             center : {
84                 xtype: 'LayoutRegion',
85                 xns: Roo
86             },
87             buttons : [
88                 {
89                     xtype: 'Button',
90                     xns: Roo,
91                     listeners : {
92                         click : function (_self, e)
93                         {
94                            _this.dialog.hide();
95                          
96                          }
97                     },
98                     text : "Cancel"
99                 },
100                 {
101                     xtype: 'Button',
102                     xns: Roo,
103                     listeners : {
104                         click : function (_self, e)
105                         {
106                            var data = _this.form.getFieldValues();
107                            
108                            if (data.invchead_id * 1 < 1) {
109                                 Roo.MessageBox.alert("Error", "Missing invchead_id");
110                                 return;
111                            }
112                            
113                            if(data.discount > 100){
114                                 Roo.MessageBox.alert("Error", "Maximum of discount value is 100");
115                                 return;
116                            }
117                            
118                            var discount = 100 - data.discount;
119                            
120                            var params  = {
121                                 template: 'Shipping-Invoice-' + baseURL.split('/').pop().split('.').shift(),
122                                 filename : 'Shipping-Invoice-' + data.invchead_id,
123                                 'param[0]':   "invchead_id:integer='" + data.invchead_id + "'",
124                                 'param[1]':   "discount:integer='" + discount + "'"
125                             };
126                             
127                            new Pman.Download({
128                                 url : baseURL + '/Xtuple/Print',
129                                 method : 'GET',
130                                 params : params,
131                                 success : function() {
132                         
133                                 }
134                             })
135                             _this.dialog.hide();
136                         }
137                     },
138                     text : "OK"
139                 }
140             ]
141         });
142     }
143 };