Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleCustomer.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Pman.Dialog');
6
7 Pman.Dialog.XtupleCustomer = {
8
9     dialog : false,
10     callback:  false,
11
12     show : function(data, cb)
13     {
14         if (!this.dialog) {
15             this.create();
16         }
17
18         this.callback = cb;
19         this.data = data;
20         this.dialog.show(this.data._el);
21         if (this.form) {
22            this.form.reset();
23            this.form.setValues(data);
24            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
25         }
26
27     },
28
29     create : function()
30     {
31         var _this = this;
32         this.dialog = Roo.factory({
33             center : {
34                 toolbar : {
35                     '|xns' : 'Roo',
36                     xtype : 'Toolbar',
37                     xns : Roo,
38                     items : [
39                         {
40                             '|xns' : 'Roo.Toolbar',
41                             xtype : 'Fill',
42                             xns : Roo.Toolbar
43                         },
44                         {
45                             '|xns' : 'Roo.Toolbar',
46                             text : "Change Customer Code",
47                             xtype : 'Button',
48                             xns : Roo.Toolbar,
49                             listeners : {
50                                 click : function (_self, e)
51                                    {
52                                        var cid = _this.form.findField('cust_id').getValue();
53                                        if(!cid){
54                                            Roo.Msg.alert('Error','please save the customer first');
55                                            return;
56                                        }
57                                        
58                                        Pman.Dialog.XtupleCustomerCode.show({cust_id : cid}, function(res){
59                                            _this.form.reset();
60                                           _this.form.fireEvent('actioncomplete', _this.form,  { type: 'setdata', data: {cust_id : res.cust_id} });
61                                        
62                                        });
63                                        
64                                    }
65                             }
66                         }
67                     ]
68
69                 },
70                 '|xns' : 'Roo',
71                 alwaysShowTabs : true,
72                 xtype : 'LayoutRegion',
73                 xns : Roo,
74                 tabPosition : 'top',
75                 items : [
76
77                 ]
78
79             },
80             '|xns' : 'Roo',
81             modal : true,
82             collapsible : false,
83             title : "Customer Information",
84             xtype : 'LayoutDialog',
85             width : 900,
86             xns : Roo,
87             closable : false,
88             resizable : true,
89             height : 670,
90             builderCfg : '{\"cols\":[{\"table\":\"custinfo\",\"column\":\"cust_custtype_id\",\"columnshort\":\"cust_custtype_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"custtype_id\",\"deps\":[{\"table\":\"custtype\",\"column\":\"cust_custtype_id_custtype_code\",\"columnshort\":\"custtype_code\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"custtype\",\"column\":\"cust_custtype_id_custtype_descrip\",\"columnshort\":\"custtype_descrip\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"custtype\",\"column\":\"cust_custtype_id_custtype_char\",\"columnshort\":\"custtype_char\",\"ctype\":\"bool\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Customer Type\",\"display\":\"cust_custtype_id_custtype_descrip\"},{\"table\":\"custinfo\",\"column\":\"cust_salesrep_id\",\"columnshort\":\"cust_salesrep_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"salesrep_id\",\"deps\":[{\"table\":\"salesrep\",\"column\":\"cust_salesrep_id_salesrep_active\",\"columnshort\":\"salesrep_active\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"salesrep\",\"column\":\"cust_salesrep_id_salesrep_number\",\"columnshort\":\"salesrep_number\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"salesrep\",\"column\":\"cust_salesrep_id_salesrep_name\",\"columnshort\":\"salesrep_name\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"salesrep\",\"column\":\"cust_salesrep_id_salesrep_commission\",\"columnshort\":\"salesrep_commission\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"salesrep\",\"column\":\"cust_salesrep_id_salesrep_method\",\"columnshort\":\"salesrep_method\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"salesrep\",\"column\":\"cust_salesrep_id_salesrep_emp_id\",\"columnshort\":\"salesrep_emp_id\",\"ctype\":\"int4\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Sales Rep\",\"display\":\"cust_salesrep_id_salesrep_name\"},{\"table\":\"custinfo\",\"column\":\"cust_commprcnt\",\"columnshort\":\"cust_commprcnt\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"cust_commprcnt\"},{\"table\":\"custinfo\",\"column\":\"cust_name\",\"columnshort\":\"cust_name\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Name\"},{\"table\":\"custinfo\",\"column\":\"cust_creditlmt\",\"columnshort\":\"cust_creditlmt\",\"ctype\":\"int4\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Credit Limit\",\"display\":\"cust_creditlmt_curr_id_curr_symbol\"},{\"table\":\"custinfo\",\"column\":\"cust_creditrating\",\"columnshort\":\"cust_creditrating\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Credit Rating\"},{\"table\":\"custinfo\",\"column\":\"cust_financecharge\",\"columnshort\":\"cust_financecharge\",\"ctype\":\"bool\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Apply Finance Charge\"},{\"table\":\"custinfo\",\"column\":\"cust_backorder\",\"columnshort\":\"cust_backorder\",\"ctype\":\"bool\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Allow Back Order\"},{\"table\":\"custinfo\",\"column\":\"cust_partialship\",\"columnshort\":\"cust_partialship\",\"ctype\":\"bool\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Allow Partial Shipment\"},{\"table\":\"custinfo\",\"column\":\"cust_terms_id\",\"columnshort\":\"cust_terms_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"terms_id\",\"deps\":[{\"table\":\"terms\",\"column\":\"cust_terms_id_terms_code\",\"columnshort\":\"terms_code\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"terms\",\"column\":\"cust_terms_id_terms_descrip\",\"columnshort\":\"terms_descrip\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"terms\",\"column\":\"cust_terms_id_terms_type\",\"columnshort\":\"terms_type\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"terms\",\"column\":\"cust_terms_id_terms_duedays\",\"columnshort\":\"terms_duedays\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"terms\",\"column\":\"cust_terms_id_terms_discdays\",\"columnshort\":\"terms_discdays\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"terms\",\"column\":\"cust_terms_id_terms_discprcnt\",\"columnshort\":\"terms_discprcnt\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"terms\",\"column\":\"cust_terms_id_terms_cutoffday\",\"columnshort\":\"terms_cutoffday\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"terms\",\"column\":\"cust_terms_id_terms_ap\",\"columnshort\":\"terms_ap\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"terms\",\"column\":\"cust_terms_id_terms_ar\",\"columnshort\":\"terms_ar\",\"ctype\":\"bool\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Terms\",\"display\":\"cust_terms_id_terms_descrip\"},{\"table\":\"custinfo\",\"column\":\"cust_discntprcnt\",\"columnshort\":\"cust_discntprcnt\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Discount Percent\"},{\"table\":\"custinfo\",\"column\":\"cust_balmethod\",\"columnshort\":\"cust_balmethod\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Balance Method\"},{\"table\":\"custinfo\",\"column\":\"cust_ffshipto\",\"columnshort\":\"cust_ffshipto\",\"ctype\":\"bool\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"is ff Ship To\"},{\"table\":\"custinfo\",\"column\":\"cust_shipform_id\",\"columnshort\":\"cust_shipform_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"shipform_id\",\"deps\":[{\"table\":\"shipform\",\"column\":\"cust_shipform_id_shipform_name\",\"columnshort\":\"shipform_name\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"shipform\",\"column\":\"cust_shipform_id_shipform_report_id\",\"columnshort\":\"shipform_report_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"shipform\",\"column\":\"cust_shipform_id_shipform_report_name\",\"columnshort\":\"shipform_report_name\",\"ctype\":\"text\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Shipment Form\",\"display\":\"cust_shipform_id_shipform_name\"},{\"table\":\"custinfo\",\"column\":\"cust_shipvia\",\"columnshort\":\"cust_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Ship Via\"},{\"table\":\"custinfo\",\"column\":\"cust_creditstatus\",\"columnshort\":\"cust_creditstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Credit Status\"},{\"table\":\"custinfo\",\"column\":\"cust_comments\",\"columnshort\":\"cust_comments\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Comments\"},{\"table\":\"custinfo\",\"column\":\"cust_ffbillto\",\"columnshort\":\"cust_ffbillto\",\"ctype\":\"bool\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"is ff Bill To\"},{\"table\":\"custinfo\",\"column\":\"cust_number\",\"columnshort\":\"cust_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Customer #\"},{\"table\":\"custinfo\",\"column\":\"cust_dateadded\",\"columnshort\":\"cust_dateadded\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Added\"},{\"table\":\"custinfo\",\"column\":\"cust_curr_id\",\"columnshort\":\"cust_curr_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"curr_id\",\"deps\":[{\"table\":\"curr_symbol\",\"column\":\"cust_curr_id_curr_base\",\"columnshort\":\"curr_base\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"curr_symbol\",\"column\":\"cust_curr_id_curr_name\",\"columnshort\":\"curr_name\",\"ctype\":\"varchar\",\"desc\":\"\"},{\"table\":\"curr_symbol\",\"column\":\"cust_curr_id_curr_symbol\",\"columnshort\":\"curr_symbol\",\"ctype\":\"varchar\",\"desc\":\"\"},{\"table\":\"curr_symbol\",\"column\":\"cust_curr_id_curr_abbr\",\"columnshort\":\"curr_abbr\",\"ctype\":\"varchar\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Currency\",\"display\":\"cust_curr_id_curr_symbol\"},{\"table\":\"custinfo\",\"column\":\"cust_creditlmt_curr_id\",\"columnshort\":\"cust_creditlmt_curr_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"curr_id\",\"deps\":[{\"table\":\"curr_symbol\",\"column\":\"cust_creditlmt_curr_id_curr_base\",\"columnshort\":\"curr_base\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"curr_symbol\",\"column\":\"cust_creditlmt_curr_id_curr_name\",\"columnshort\":\"curr_name\",\"ctype\":\"varchar\",\"desc\":\"\"},{\"table\":\"curr_symbol\",\"column\":\"cust_creditlmt_curr_id_curr_symbol\",\"columnshort\":\"curr_symbol\",\"ctype\":\"varchar\",\"desc\":\"\"},{\"table\":\"curr_symbol\",\"column\":\"cust_creditlmt_curr_id_curr_abbr\",\"columnshort\":\"curr_abbr\",\"ctype\":\"varchar\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Credit Limit Currency\",\"display\":\"cust_creditlmt_curr_id_curr_symbol\"},{\"table\":\"custinfo\",\"column\":\"cust_cntct_id\",\"columnshort\":\"cust_cntct_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"cntct_id\",\"deps\":[{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_crmacct_id\",\"columnshort\":\"cntct_crmacct_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_addr_id\",\"columnshort\":\"cntct_addr_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_first_name\",\"columnshort\":\"cntct_first_name\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_last_name\",\"columnshort\":\"cntct_last_name\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_honorific\",\"columnshort\":\"cntct_honorific\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_initials\",\"columnshort\":\"cntct_initials\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_active\",\"columnshort\":\"cntct_active\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_phone\",\"columnshort\":\"cntct_phone\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_phone2\",\"columnshort\":\"cntct_phone2\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_fax\",\"columnshort\":\"cntct_fax\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_email\",\"columnshort\":\"cntct_email\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_webaddr\",\"columnshort\":\"cntct_webaddr\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_notes\",\"columnshort\":\"cntct_notes\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_title\",\"columnshort\":\"cntct_title\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_number\",\"columnshort\":\"cntct_number\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_middle\",\"columnshort\":\"cntct_middle\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_suffix\",\"columnshort\":\"cntct_suffix\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_owner_username\",\"columnshort\":\"cntct_owner_username\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_cntct_id_cntct_name\",\"columnshort\":\"cntct_name\",\"ctype\":\"text\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Contact\",\"display\":\"cust_cntct_id_cntct_name\"},{\"table\":\"custinfo\",\"column\":\"cust_corrcntct_id\",\"columnshort\":\"cust_corrcntct_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"cntct_id\",\"deps\":[{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_crmacct_id\",\"columnshort\":\"cntct_crmacct_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_addr_id\",\"columnshort\":\"cntct_addr_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_first_name\",\"columnshort\":\"cntct_first_name\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_last_name\",\"columnshort\":\"cntct_last_name\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_honorific\",\"columnshort\":\"cntct_honorific\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_initials\",\"columnshort\":\"cntct_initials\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_active\",\"columnshort\":\"cntct_active\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_phone\",\"columnshort\":\"cntct_phone\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_phone2\",\"columnshort\":\"cntct_phone2\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_fax\",\"columnshort\":\"cntct_fax\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_email\",\"columnshort\":\"cntct_email\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_webaddr\",\"columnshort\":\"cntct_webaddr\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_notes\",\"columnshort\":\"cntct_notes\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_title\",\"columnshort\":\"cntct_title\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_number\",\"columnshort\":\"cntct_number\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_middle\",\"columnshort\":\"cntct_middle\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_suffix\",\"columnshort\":\"cntct_suffix\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_owner_username\",\"columnshort\":\"cntct_owner_username\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"cntct\",\"column\":\"cust_corrcntct_id_cntct_name\",\"columnshort\":\"cntct_name\",\"ctype\":\"text\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Corr? Contact\",\"display\":\"cust_corrcntct_id_cntct_name\"},{\"table\":\"custinfo\",\"column\":\"cust_taxzone_id\",\"columnshort\":\"cust_taxzone_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"taxzone_id\",\"deps\":[{\"table\":\"taxzone\",\"column\":\"cust_taxzone_id_taxzone_code\",\"columnshort\":\"taxzone_code\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"taxzone\",\"column\":\"cust_taxzone_id_taxzone_descrip\",\"columnshort\":\"taxzone_descrip\",\"ctype\":\"text\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Tax Zone\",\"display\":\"cust_taxzone_id_taxzone_descrip\"}],\"cols_ex\":[\"cust_custtype_id_custtype_descrip\",\"cust_salesrep_id_salesrep_name\",\"cust_terms_id_terms_descrip\",\"cust_shipform_id_shipform_name\",\"cust_curr_id_curr_symbol\",\"cust_creditlmt_curr_id_curr_symbol\",\"cust_cntct_id_cntct_name\",\"cust_corrcntct_id_cntct_name\",\"cust_taxzone_id_taxzone_descrip\"],\"table\":\"custinfo\",\"xtype\":\"LayoutDialog\",\"|xns\":\"Roo\"}',
91             buttons : [
92                  {
93                         '|xns' : 'Roo',
94                         text : "Cancel",
95                         xtype : 'Button',
96                         xns : Roo,
97                         listeners : {
98                                 click : function (_self, e)
99                                    {
100                                        _this.dialog.hide();
101                                    }
102                         }
103                     },
104 {
105                         '|xns' : 'Roo',
106                         text : "Save",
107                         xtype : 'Button',
108                         xns : Roo,
109                         listeners : {
110                                 click : function (_self, e)
111                                    {
112                                        // do some checks?
113                                         
114                                         var bg_comp = _this.form.findField('cust_char_internalcompany').getValue();
115                                         var ctype  = _this.form.findField('cust_custtype_id').el.dom.value;
116                                         if (bg_comp.length && !ctype.match(/internal/i)) {
117                                            Roo.MessageBox.alert("Error" ,
118                                                "BG Company should only be set for internal companies"
119                                            );
120                                            return;
121                                        }
122                                         
123                                         
124                                         
125                                         
126                                         
127                                        
128                                     
129                                        _this.form.doAction("submit");
130                                    
131                                    }
132                         }
133                     }
134             ],
135             items : [
136                 {
137                     layout : {
138                         center : {
139                             '|xns' : 'Roo',
140                             xtype : 'LayoutRegion',
141                             xns : Roo
142                         },
143                         east : {
144                             '|xns' : 'Roo',
145                             xtype : 'LayoutRegion',
146                             width : 300,
147                             xns : Roo
148                         },
149                         '|xns' : 'Roo',
150                         xtype : 'BorderLayout',
151                         xns : Roo,
152                         items : [
153                                 {
154                                 '|xns' : 'Roo',
155                                 region : 'center',
156                                 xtype : 'ContentPanel',
157                                 xns : Roo,
158                                 items : [
159                                         {
160                                         '|xns' : 'Roo.form',
161                                         url : baseURL + '/Roo/custinfo.php',
162                                         xtype : 'Form',
163                                         method : 'POST',
164                                         style : 'margin:10px;',
165                                         xns : Roo.form,
166                                         listeners : {
167                                                 actioncomplete : function(_self,action)
168                                                    {
169                                                        if (action.type == 'setdata') {
170                                                        
171                                                            _this.dialog.layout.getRegion('center').showPanel(0);
172                                                        
173                                                            if (_this.data.cust_id) {
174                                                               this.load({ method: 'GET', params: { '_id' : _this.data.cust_id, '_with_char' : true }});
175                                                               return;
176                                                           } 
177                                                           this.findField('cust_active').setValue(true);
178                                                          _this.grid.ds.load({});
179                                                          _this.dialog.setTitle("New Customer");
180                                                    
181                                                          
182                                                          
183                                                           return;
184                                                        }
185                                                        if (action.type == 'load') {
186                                                        
187                                                              _this.dialog.setTitle("Edit Customer (" + _this.data.cust_id +") " + _this.form.findField('cust_name').getValue() );
188                                                        
189                                                            _this.grid.ds.load({});
190                                                            
191                                                            
192                                                            return;
193                                                        }
194                                                        if (action.type =='submit') {
195                                                            
196                                                            
197                                                            if (_this.data.cust_id > 0 ) {
198                                                                
199                                                                
200                                                                _this.dialog.hide();
201                                                            
202                                                                 if (_this.callback) {
203                                                                    _this.callback.call(_this, _this.form.getValues());
204                                                                 }
205                                                                 _this.form.reset();
206                                                                 return;
207                                                             }
208                                                             // carry on editing.. and set data..
209                                                    
210                                                             _this.data.cust_id = action.result.data.cust_id;
211                                                             _this.form.fireEvent('actioncomplete', 
212                                                                    _this.form,  { type: 'setdata', data: _this.data });
213                                                             
214                                                             
215                                                        }
216                                                    },
217                                                 rendered : function (form)
218                                                    {
219                                                        _this.form= form;
220                                                    }
221                                         },
222                                         items : [
223                                                 {
224                                                 '|xns' : 'Roo.form',
225                                                 xtype : 'FieldSet',
226                                                 legend : "Basic Details",
227                                                 style : 'width:460px',
228                                                 xns : Roo.form,
229                                                 items : [
230                                                         {
231                                                         '|xns' : 'Roo.form',
232                                                         fieldLabel : 'Login Email',
233                                                         vtype : 'email',
234                                                         xtype : 'TextField',
235                                                         allowBlank : false,
236                                                         width : 300,
237                                                         xns : Roo.form,
238                                                         name : 'cust_login_email'
239                                                     },
240                                                         {
241                                                         '|xns' : 'Roo.form',
242                                                         fieldLabel : 'Name',
243                                                         xtype : 'TextField',
244                                                         allowBlank : false,
245                                                         width : 300,
246                                                         xns : Roo.form,
247                                                         name : 'cust_name',
248                                                         listeners : {
249                                                                 keyup : function (_self, e)
250                                                                    {
251                                                                        if (!(_this.form.findField('cust_id').getValue() * 1)) {
252                                                                        
253                                                                            _this.form.findField('cust_number').setValue(this.getValue().replace(/[^a-z0-9]/ig, '').toUpperCase());
254                                                                        
255                                                                        }
256                                                                    }
257                                                         }
258                                                     },
259                                                         {
260                                                         '|xns' : 'Roo.form',
261                                                         xtype : 'Row',
262                                                         xns : Roo.form,
263                                                         items : [
264                                                                 {
265                                                                 '|xns' : 'Roo.form',
266                                                                 fieldLabel : 'Customer #',
267                                                                 xtype : 'TextField',
268                                                                 allowBlank : false,
269                                                                 readOnly : true,
270                                                                 width : 150,
271                                                                 xns : Roo.form,
272                                                                 name : 'cust_number'
273                                                             },
274                                                                 {
275                                                                 store : {
276                                                                     proxy : {
277                                                                         '|xns' : 'Roo.data',
278                                                                         url : baseURL + '/Roo/charopt.php',
279                                                                         method : 'GET',
280                                                                         xtype : 'HttpProxy',
281                                                                         xns : Roo.data
282                                                                     },
283                                                                     reader : {
284                                                                         '|xns' : 'Roo.data',
285                                                                         id : 'id',
286                                                                         root : 'data',
287                                                                         xtype : 'JsonReader',
288                                                                         xns : Roo.data,
289                                                                         fields : [{"name":"id","type":"int"},{"name":"charopt_value","type":"string"}],
290                                                                         totalProperty : 'total'
291                                                                     },
292                                                                     '|xns' : 'Roo.data',
293                                                                     xtype : 'Store',
294                                                                     remoteSort : true,
295                                                                     sortInfo : { direction : 'ASC', field: 'id' },
296                                                                     xns : Roo.data,
297                                                                     listeners : {
298                                                                         beforeload : function (_self, o){
299                                                                                o.params = o.params || {};
300                                                                                // set more here
301                                                                                o.params.charopt_char_id_char_name = 'INTERNALCOMPANY';
302                                                                                o.params['!charopt_value'] = baseURL.split('/').pop().split('.').shift();
303                                                                                
304                                                                            }
305                                                                     },
306                                                                     items : [
307
308                                                                     ]
309
310                                                                 },
311                                                                 '|xns' : 'Roo.form',
312                                                                 listWidth : 250,
313                                                                 triggerAction : 'all',
314                                                                 fieldLabel : 'BG Company',
315                                                                 forceSelection : true,
316                                                                 selectOnFocus : true,
317                                                                 pageSize : 20,
318                                                                 displayField : 'charopt_value',
319                                                                 emptyText : "",
320                                                                 hiddenName : 'cust_char_internalcompany',
321                                                                 minChars : 2,
322                                                                 valueField : 'charopt_value',
323                                                                 xtype : 'ComboBox',
324                                                                 allowBlank : true,
325                                                                 typeAhead : true,
326                                                                 editable : false,
327                                                                 width : 70,
328                                                                 xns : Roo.form,
329                                                                 name : 'cust_char_internalcompany',
330                                                                 qtip : "Select charopt",
331                                                                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{charopt_value}</b> </div>',
332                                                                 loadingText : "Searching...",
333                                                                 items : [
334
335                                                                 ]
336
337                                                             }
338                                                         ]
339
340                                                     },
341                                                         {
342                                                         '|xns' : 'Roo.form',
343                                                         xtype : 'Row',
344                                                         xns : Roo.form,
345                                                         width : 500,
346                                                         items : [
347                                                                 {
348                                                                 '|xns' : 'Roo.form',
349                                                                 fieldLabel : 'Active',
350                                                                 inputValue : true,
351                                                                 xtype : 'Checkbox',
352                                                                 valueOff : 0,
353                                                                 width : 100,
354                                                                 xns : Roo.form,
355                                                                 name : 'cust_active'
356                                                             },
357                                                                 {
358                                                                 '|xns' : 'Roo.form',
359                                                                 labelAlign : 'right',
360                                                                 xtype : 'Row',
361                                                                 labelWidth : 50,
362                                                                 xns : Roo.form,
363                                                                 items : [
364                                                                         {
365                                                                         store : {
366                                                                             proxy : {
367                                                                                 '|xns' : 'Roo.data',
368                                                                                 url : baseURL + '/Roo/custtype.php',
369                                                                                 method : 'GET',
370                                                                                 xtype : 'HttpProxy',
371                                                                                 xns : Roo.data
372                                                                             },
373                                                                             reader : {
374                                                                                 '|xns' : 'Roo.data',
375                                                                                 id : 'id',
376                                                                                 root : 'data',
377                                                                                 xtype : 'JsonReader',
378                                                                                 xns : Roo.data,
379                                                                                 fields : [{"name":"id","type":"int"},{"name":"custtype_code","type":"string"}],
380                                                                                 totalProperty : 'total'
381                                                                             },
382                                                                             '|xns' : 'Roo.data',
383                                                                             xtype : 'Store',
384                                                                             remoteSort : true,
385                                                                             xns : Roo.data,
386                                                                             sortInfo : { direction : 'ASC', field: 'id' },
387                                                                             listeners : {
388                                                                                 beforeload : function (_self, o){
389                                                                                        o.params = o.params || {};
390                                                                                        // set more here
391                                                                                    }
392                                                                             },
393                                                                             items : [
394
395                                                                             ]
396
397                                                                         },
398                                                                         '|xns' : 'Roo.form',
399                                                                         listWidth : 400,
400                                                                         triggerAction : 'all',
401                                                                         fieldLabel : 'Type',
402                                                                         forceSelection : true,
403                                                                         selectOnFocus : true,
404                                                                         pageSize : 20,
405                                                                         displayField : 'custtype_descrip',
406                                                                         emptyText : "Select Type",
407                                                                         hiddenName : 'cust_custtype_id',
408                                                                         minChars : 2,
409                                                                         valueField : 'custtype_id',
410                                                                         xtype : 'ComboBox',
411                                                                         allowBlank : false,
412                                                                         typeAhead : true,
413                                                                         editable : false,
414                                                                         width : 160,
415                                                                         xns : Roo.form,
416                                                                         name : 'cust_custtype_id_custtype_descrip',
417                                                                         qtip : "Select custtype",
418                                                                         queryParam : 'q[cust_descript]',
419                                                                         tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{custtype_code}</b> {custtype_descrip}</div>',
420                                                                         loadingText : "Searching...",
421                                                                         items : [
422
423                                                                         ]
424
425                                                                     }
426                                                                 ]
427
428                                                             }
429                                                         ]
430
431                                                     },
432                                                         {
433                                                         '|xns' : 'Roo.form',
434                                                         fieldLabel : 'AU POST #',
435                                                         xtype : 'TextField',
436                                                         width : 150,
437                                                         xns : Roo.form,
438                                                         name : 'cust_char_au_post_accno'
439                                                     },
440                                                         {
441                                                         store : {
442                                                             proxy : {
443                                                                 '|xns' : 'Roo.data',
444                                                                 url : baseURL + '/Roo/charopt.php',
445                                                                 method : 'GET',
446                                                                 xtype : 'HttpProxy',
447                                                                 xns : Roo.data
448                                                             },
449                                                             reader : {
450                                                                 '|xns' : 'Roo.data',
451                                                                 id : 'id',
452                                                                 root : 'data',
453                                                                 xtype : 'JsonReader',
454                                                                 xns : Roo.data,
455                                                                 fields : [{"name":"id","type":"int"},{"name":"charopt_value","type":"string"}],
456                                                                 totalProperty : 'total'
457                                                             },
458                                                             '|xns' : 'Roo.data',
459                                                             xtype : 'Store',
460                                                             remoteSort : true,
461                                                             sortInfo : { direction : 'ASC', field: 'id' },
462                                                             xns : Roo.data,
463                                                             listeners : {
464                                                                 beforeload : function (_self, o){
465                                                                        o.params = o.params || {};
466                                                                        // set more here
467                                                                        o.params.charopt_char_id_char_name = 'SALESFORECAST';
468                                                                        
469                                                                    }
470                                                             },
471                                                             items : [
472
473                                                             ]
474
475                                                         },
476                                                         '|xns' : 'Roo.form',
477                                                         listWidth : 250,
478                                                         triggerAction : 'all',
479                                                         fieldLabel : 'Forecast Type',
480                                                         forceSelection : true,
481                                                         selectOnFocus : true,
482                                                         pageSize : 20,
483                                                         displayField : 'charopt_value',
484                                                         emptyText : "",
485                                                         hiddenName : 'cust_char_salesforecast',
486                                                         minChars : 2,
487                                                         valueField : 'charopt_value',
488                                                         xtype : 'ComboBox',
489                                                         allowBlank : true,
490                                                         typeAhead : true,
491                                                         editable : false,
492                                                         width : 150,
493                                                         xns : Roo.form,
494                                                         name : 'cust_char_salesforecast',
495                                                         qtip : "Select charopt",
496                                                         tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{charopt_value}</b> </div>',
497                                                         loadingText : "Searching...",
498                                                         items : [
499
500                                                         ]
501
502                                                     },
503                                                         {
504                                                         '|xns' : 'Roo.form',
505                                                         fieldLabel : 'Comments',
506                                                         xtype : 'TextArea',
507                                                         width : 300,
508                                                         xns : Roo.form,
509                                                         name : 'cust_comments',
510                                                         height : 50
511                                                     },
512                                                         {
513                                                         store : {
514                                                             proxy : {
515                                                                 '|xns' : 'Roo.data',
516                                                                 url : baseURL + '/Roo/curr_symbol.php',
517                                                                 method : 'GET',
518                                                                 xtype : 'HttpProxy',
519                                                                 xns : Roo.data
520                                                             },
521                                                             reader : {
522                                                                 '|xns' : 'Roo.data',
523                                                                 id : 'curr_id',
524                                                                 root : 'data',
525                                                                 xtype : 'JsonReader',
526                                                                 xns : Roo.data,
527                                                                 fields : [{"name":"curr_id","type":"int"},"curr_symbol"],
528                                                                 totalProperty : 'total'
529                                                             },
530                                                             '|xns' : 'Roo.data',
531                                                             xtype : 'Store',
532                                                             remoteSort : true,
533                                                             sortInfo : { direction : 'ASC', field: 'curr_symbol' },
534                                                             xns : Roo.data,
535                                                             listeners : {
536                                                                 beforeload : function (_self, o){
537                                                                        o.params = o.params || {};
538                                                                        // set more here
539                                                                    }
540                                                             },
541                                                             items : [
542
543                                                             ]
544
545                                                         },
546                                                         '|xns' : 'Roo.form',
547                                                         listWidth : 400,
548                                                         triggerAction : 'all',
549                                                         fieldLabel : 'Currency',
550                                                         forceSelection : true,
551                                                         selectOnFocus : true,
552                                                         pageSize : 20,
553                                                         displayField : 'curr_symbol',
554                                                         emptyText : "Select curr_symbol",
555                                                         hiddenName : 'cust_curr_id',
556                                                         minChars : 2,
557                                                         valueField : 'curr_id',
558                                                         xtype : 'ComboBox',
559                                                         allowBlank : false,
560                                                         typeAhead : true,
561                                                         editable : false,
562                                                         width : 100,
563                                                         xns : Roo.form,
564                                                         name : 'cust_curr_id_curr_symbol',
565                                                         qtip : "Select curr_symbol",
566                                                         queryParam : 'query[curr_symbol]',
567                                                         tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{curr_symbol}</b> </div>',
568                                                         loadingText : "Searching...",
569                                                         items : [
570
571                                                         ]
572
573                                                     },
574                                                         {
575                                                         store : {
576                                                             proxy : {
577                                                                 '|xns' : 'Roo.data',
578                                                                 url : baseURL + '/Roo/taxzone.php',
579                                                                 method : 'GET',
580                                                                 xtype : 'HttpProxy',
581                                                                 xns : Roo.data
582                                                             },
583                                                             reader : {
584                                                                 '|xns' : 'Roo.data',
585                                                                 id : 'taxzone_id',
586                                                                 root : 'data',
587                                                                 xtype : 'JsonReader',
588                                                                 xns : Roo.data,
589                                                                 fields : [{"name":"taxzone_id","type":"int"},"taxzone_descrip"],
590                                                                 totalProperty : 'total'
591                                                             },
592                                                             '|xns' : 'Roo.data',
593                                                             xtype : 'Store',
594                                                             remoteSort : true,
595                                                             sortInfo : { direction : 'ASC', field: 'taxzone_descrip' },
596                                                             xns : Roo.data,
597                                                             listeners : {
598                                                                 beforeload : function (_self, o){
599                                                                        o.params = o.params || {};
600                                                                        // set more here
601                                                                    }
602                                                             },
603                                                             items : [
604
605                                                             ]
606
607                                                         },
608                                                         '|xns' : 'Roo.form',
609                                                         listWidth : 400,
610                                                         triggerAction : 'all',
611                                                         forceSelection : true,
612                                                         selectOnFocus : true,
613                                                         fieldLabel : 'Tax Zone',
614                                                         pageSize : 20,
615                                                         xtype : 'ComboBox',
616                                                         emptyText : "Select taxzone",
617                                                         minChars : 2,
618                                                         valueField : 'taxzone_id',
619                                                         displayField : 'taxzone_descrip',
620                                                         hiddenName : 'cust_taxzone_id',
621                                                         allowBlank : false,
622                                                         typeAhead : true,
623                                                         editable : false,
624                                                         xns : Roo.form,
625                                                         width : 300,
626                                                         qtip : "Select taxzone",
627                                                         tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{taxzone_descrip}</b> </div>',
628                                                         queryParam : 'query[taxzone_descrip]',
629                                                         name : 'cust_taxzone_id_taxzone_descrip',
630                                                         loadingText : "Searching...",
631                                                         items : [
632
633                                                         ]
634
635                                                     },
636                                                         {
637                                                         store : {
638                                                             proxy : {
639                                                                 '|xns' : 'Roo.data',
640                                                                 url : baseURL + '/Roo/salesrep.php',
641                                                                 method : 'GET',
642                                                                 xtype : 'HttpProxy',
643                                                                 xns : Roo.data
644                                                             },
645                                                             reader : {
646                                                                 '|xns' : 'Roo.data',
647                                                                 id : 'salesrep_id',
648                                                                 root : 'data',
649                                                                 xtype : 'JsonReader',
650                                                                 xns : Roo.data,
651                                                                 fields : [{"name":"salesrep_id","type":"int"},"salesrep_name"],
652                                                                 totalProperty : 'total'
653                                                             },
654                                                             '|xns' : 'Roo.data',
655                                                             xtype : 'Store',
656                                                             remoteSort : true,
657                                                             sortInfo : { direction : 'ASC', field: 'salesrep_name' },
658                                                             xns : Roo.data,
659                                                             listeners : {
660                                                                 beforeload : function (_self, o){
661                                                                        o.params = o.params || {};
662                                                                        // set more here
663                                                                    }
664                                                             },
665                                                             items : [
666
667                                                             ]
668
669                                                         },
670                                                         '|xns' : 'Roo.form',
671                                                         listWidth : 400,
672                                                         triggerAction : 'all',
673                                                         forceSelection : true,
674                                                         selectOnFocus : true,
675                                                         fieldLabel : 'Sales Rep',
676                                                         pageSize : 20,
677                                                         xtype : 'ComboBox',
678                                                         emptyText : "Select salesrep",
679                                                         minChars : 2,
680                                                         valueField : 'salesrep_id',
681                                                         displayField : 'salesrep_name',
682                                                         hiddenName : 'cust_salesrep_id',
683                                                         allowBlank : false,
684                                                         typeAhead : true,
685                                                         editable : false,
686                                                         xns : Roo.form,
687                                                         width : 300,
688                                                         qtip : "Select salesrep",
689                                                         tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>',
690                                                         queryParam : 'query[salesrep_name]',
691                                                         name : 'cust_salesrep_id_salesrep_name',
692                                                         loadingText : "Searching...",
693                                                         items : [
694
695                                                         ]
696
697                                                     },
698                                                         {
699                                                         store : {
700                                                             proxy : {
701                                                                 '|xns' : 'Roo.data',
702                                                                 url : baseURL + '/Roo/ipshead.php',
703                                                                 method : 'GET',
704                                                                 xtype : 'HttpProxy',
705                                                                 xns : Roo.data
706                                                             },
707                                                             reader : {
708                                                                 '|xns' : 'Roo.data',
709                                                                 id : 'id',
710                                                                 root : 'data',
711                                                                 xtype : 'JsonReader',
712                                                                 xns : Roo.data,
713                                                                 fields : [{"name":"id","type":"int"},{"name":"ipshead_name","type":"string"}],
714                                                                 totalProperty : 'total'
715                                                             },
716                                                             '|xns' : 'Roo.data',
717                                                             xtype : 'Store',
718                                                             remoteSort : true,
719                                                             sortInfo : { direction : 'ASC', field: 'ipshead_id_name' },
720                                                             xns : Roo.data,
721                                                             listeners : {
722                                                                 beforeload : function (_self, o){
723                                                                        o.params = o.params || {};
724                                                                        o.params.ipshead_curr_id = _this.form.findField('cust_curr_id').getValue();
725                                                                        // set more here
726                                                                    }
727                                                             },
728                                                             items : [
729
730                                                             ]
731
732                                                         },
733                                                         '|xns' : 'Roo.form',
734                                                         alwaysQuery : true,
735                                                         listWidth : 400,
736                                                         triggerAction : 'all',
737                                                         fieldLabel : 'Price Level',
738                                                         forceSelection : true,
739                                                         selectOnFocus : true,
740                                                         pageSize : 50,
741                                                         displayField : 'ipshead_name',
742                                                         emptyText : "Select price level",
743                                                         hiddenName : 'ipshead_id',
744                                                         minChars : 2,
745                                                         valueField : 'ipshead_id',
746                                                         xtype : 'ComboBox',
747                                                         allowBlank : true,
748                                                         typeAhead : true,
749                                                         editable : false,
750                                                         width : 300,
751                                                         xns : Roo.form,
752                                                         name : 'ipshead_id_name',
753                                                         qtip : "Select ipshead",
754                                                         queryParam : 'q',
755                                                         tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{ipshead_name}</b> </div>',
756                                                         loadingText : "Searching...",
757                                                         items : [
758
759                                                         ]
760
761                                                     }
762                                                 ]
763
764                                             },
765                                                 {
766                                                 '|xns' : 'Roo.form',
767                                                 xtype : 'FieldSet',
768                                                 legend : "Financial",
769                                                 style : 'width:420px',
770                                                 xns : Roo.form,
771                                                 items : [
772                                                         {
773                                                         store : {
774                                                             proxy : {
775                                                                 '|xns' : 'Roo.data',
776                                                                 url : baseURL + '/Roo/terms.php',
777                                                                 method : 'GET',
778                                                                 xtype : 'HttpProxy',
779                                                                 xns : Roo.data
780                                                             },
781                                                             reader : {
782                                                                 '|xns' : 'Roo.data',
783                                                                 id : 'terms_id',
784                                                                 root : 'data',
785                                                                 xtype : 'JsonReader',
786                                                                 xns : Roo.data,
787                                                                 fields : [{"name":"terms_id","type":"int"},"terms_descrip"],
788                                                                 totalProperty : 'total'
789                                                             },
790                                                             '|xns' : 'Roo.data',
791                                                             xtype : 'Store',
792                                                             remoteSort : true,
793                                                             sortInfo : { direction : 'ASC', field: 'terms_descrip' },
794                                                             xns : Roo.data,
795                                                             listeners : {
796                                                                 beforeload : function (_self, o){
797                                                                        o.params = o.params || {};
798                                                                        // set more here
799                                                                    }
800                                                             },
801                                                             items : [
802
803                                                             ]
804
805                                                         },
806                                                         '|xns' : 'Roo.form',
807                                                         listWidth : 400,
808                                                         triggerAction : 'all',
809                                                         forceSelection : true,
810                                                         selectOnFocus : true,
811                                                         fieldLabel : 'Terms',
812                                                         pageSize : 20,
813                                                         xtype : 'ComboBox',
814                                                         emptyText : "Select terms",
815                                                         minChars : 2,
816                                                         valueField : 'terms_id',
817                                                         displayField : 'terms_descrip',
818                                                         hiddenName : 'cust_terms_id',
819                                                         allowBlank : false,
820                                                         typeAhead : true,
821                                                         editable : false,
822                                                         xns : Roo.form,
823                                                         width : 300,
824                                                         qtip : "Select terms",
825                                                         tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{terms_descrip}</b> </div>',
826                                                         queryParam : 'query[terms_descrip]',
827                                                         name : 'cust_terms_id_terms_descrip',
828                                                         loadingText : "Searching...",
829                                                         items : [
830
831                                                         ]
832
833                                                     },
834                                                         {
835                                                         '|xns' : 'Roo.form',
836                                                         fieldLabel : 'Credit Limit',
837                                                         align : 'right',
838                                                         xtype : 'NumberField',
839                                                         xns : Roo.form,
840                                                         width : 100,
841                                                         name : 'cust_creditlmt'
842                                                     }
843                                                 ]
844
845                                             },
846                                                 {
847                                                 '|xns' : 'Roo.form',
848                                                 xtype : 'FieldSet',
849                                                 legend : "Shipping",
850                                                 style : 'width:420px',
851                                                 xns : Roo.form,
852                                                 items : [
853                                                         {
854                                                         store : {
855                                                             proxy : {
856                                                                 '|xns' : 'Roo.data',
857                                                                 url : baseURL + '/Roo/shipform.php',
858                                                                 method : 'GET',
859                                                                 xtype : 'HttpProxy',
860                                                                 xns : Roo.data
861                                                             },
862                                                             reader : {
863                                                                 '|xns' : 'Roo.data',
864                                                                 id : 'shipform_id',
865                                                                 root : 'data',
866                                                                 xtype : 'JsonReader',
867                                                                 xns : Roo.data,
868                                                                 fields : [{"name":"shipform_id","type":"int"},"shipform_name"],
869                                                                 totalProperty : 'total'
870                                                             },
871                                                             '|xns' : 'Roo.data',
872                                                             xtype : 'Store',
873                                                             remoteSort : true,
874                                                             sortInfo : { direction : 'ASC', field: 'shipform_name' },
875                                                             xns : Roo.data,
876                                                             listeners : {
877                                                                 beforeload : function (_self, o){
878                                                                        o.params = o.params || {};
879                                                                        // set more here
880                                                                    }
881                                                             },
882                                                             items : [
883
884                                                             ]
885
886                                                         },
887                                                         '|xns' : 'Roo.form',
888                                                         listWidth : 400,
889                                                         triggerAction : 'all',
890                                                         forceSelection : true,
891                                                         selectOnFocus : true,
892                                                         fieldLabel : 'Shipment Form',
893                                                         pageSize : 20,
894                                                         xtype : 'ComboBox',
895                                                         emptyText : "Select shipform",
896                                                         minChars : 2,
897                                                         valueField : 'shipform_id',
898                                                         displayField : 'shipform_name',
899                                                         hiddenName : 'cust_shipform_id',
900                                                         allowBlank : false,
901                                                         typeAhead : true,
902                                                         editable : false,
903                                                         xns : Roo.form,
904                                                         width : 300,
905                                                         qtip : "Select shipform",
906                                                         tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{shipform_name}</b> </div>',
907                                                         queryParam : 'query[shipform_name]',
908                                                         name : 'cust_shipform_id_shipform_name',
909                                                         loadingText : "Searching...",
910                                                         items : [
911
912                                                         ]
913
914                                                     },
915                                                         {
916                                                         '|xns' : 'Roo.form',
917                                                         fieldLabel : 'Ship Via',
918                                                         xtype : 'TextField',
919                                                         xns : Roo.form,
920                                                         width : 300,
921                                                         name : 'cust_shipvia'
922                                                     }
923                                                 ]
924
925                                             },
926                                                 {
927                                                 '|xns' : 'Roo.form',
928                                                 xtype : 'FieldSet',
929                                                 legend : "Reference",
930                                                 style : 'width:420px',
931                                                 xns : Roo.form,
932                                                 items : [
933                                                         {
934                                                         '|xns' : 'Roo.form',
935                                                         fieldLabel : 'Date Added',
936                                                         format : 'Y-m-d',
937                                                         xtype : 'TextField',
938                                                         readOnly : true,
939                                                         width : 100,
940                                                         xns : Roo.form,
941                                                         name : 'cust_dateadded'
942                                                     }
943                                                 ]
944
945                                             },
946                                                 {
947                                                 '|xns' : 'Roo.form',
948                                                 xtype : 'Hidden',
949                                                 xns : Roo.form,
950                                                 name : 'cust_cntct_id'
951                                             },
952                                                 {
953                                                 '|xns' : 'Roo.form',
954                                                 xtype : 'Hidden',
955                                                 xns : Roo.form,
956                                                 name : 'cust_creditlmt_curr_id'
957                                             },
958                                                 {
959                                                 '|xns' : 'Roo.form',
960                                                 update : function() {
961                                                      var ship = [];
962                                                     _this.grid.ds.each(function(r) {
963                                                         if (r.data.is_ship * 1) {
964                                                             ship.push(r.data.cntct_id);
965                                                         }
966                                                     });
967                                                     this.setValue(ship.join(','));
968                                                 },
969                                                 xtype : 'Hidden',
970                                                 xns : Roo.form,
971                                                 name : 'shiplist'
972                                             },
973                                                 {
974                                                 '|xns' : 'Roo.form',
975                                                 xtype : 'Hidden',
976                                                 xns : Roo.form,
977                                                 name : 'cust_id'
978                                             }
979                                         ]
980
981                                     }
982                                 ]
983
984                             },
985                                 {
986                                 grid : {
987                                     dataSource : {
988                                         proxy : {
989                                             '|xns' : 'Roo.data',
990                                             url : baseURL + '/Roo/cntct.php',
991                                             method : 'GET',
992                                             xtype : 'HttpProxy',
993                                             xns : Roo.data
994                                         },
995                                         reader : {
996                                             '|xns' : 'Roo.data',
997                                             id : 'id',
998                                             root : 'data',
999                                             xtype : 'JsonReader',
1000                                             xns : Roo.data,
1001                                             fields : [
1002                                                 {
1003                                                     'name': 'cntct_addr_id_addr_line1',
1004                                                     'type': 'string'
1005                                                 },
1006                                                 {
1007                                                     'name': 'cntct_addr_id_addr_line2',
1008                                                     'type': 'string'
1009                                                 },
1010                                                 {
1011                                                     'name': 'cntct_addr_id_addr_line3',
1012                                                     'type': 'string'
1013                                                 },
1014                                                 {
1015                                                     'name': 'cntct_addr_id_addr_country',
1016                                                     'type': 'string'
1017                                                 },
1018                                                 {
1019                                                     'name': 'cntct_phone',
1020                                                     'type': 'string'
1021                                                 },
1022                                                 {
1023                                                     'name': 'cntct_phone2',
1024                                                     'type': 'string'
1025                                                 },
1026                                                 {
1027                                                     'name': 'cntct_name',
1028                                                     'type': 'string'
1029                                                 }
1030                                             ],
1031                                             totalProperty : 'total',
1032                                             builderCfg : '{\"cols\":[{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_line1\",\"columnshort\":\"addr_line1\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"},{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_line2\",\"columnshort\":\"addr_line2\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_line3\",\"columnshort\":\"addr_line3\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_country\",\"columnshort\":\"addr_country\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"cntct\",\"column\":\"cntct_phone\",\"columnshort\":\"cntct_phone\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"cntct\",\"column\":\"cntct_phone2\",\"columnshort\":\"cntct_phone2\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"cntct\",\"column\":\"cntct_name\",\"columnshort\":\"cntct_name\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}],\"cols_ex\":[\"cntct_addr_id_addr_line1\"],\"table\":\"cntct\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}'
1033                                         },
1034                                         '|xns' : 'Roo.data',
1035                                         xtype : 'Store',
1036                                         remoteSort : true,
1037                                         sortInfo : { field : 'cntct_name', direction: 'ASC' },
1038                                         xns : Roo.data,
1039                                         listeners : {
1040                                                 beforeload : function (_self, options)
1041                                                    {
1042                                                         options.params =  options.params || {};
1043                                                         options.params.limit = 99;
1044                                                        options.params._customer_id = _this.form.findField('cust_id').getValue() * 1;
1045                                                        if (options.params._customer_id < 1) {
1046                                                            this.removeAll();
1047                                                            _this.grid.view.el.mask("Save first");
1048                                                            return false;
1049                                                        }
1050                                                        options.params._add_is_types = 1;
1051                                                        _this.grid.view.el.unmask();    
1052                                                    },
1053                                                 load : function (_self, records, options)
1054                                                    {
1055                                                         var cc = _this.form.findField('cust_cntct_id');
1056                                                         var old = cc.getValue() * 1;
1057                                                         if (old > 1) {
1058                                                            Roo.each(records,function(r) {
1059                                                                if (r.data.cntct_id == old) {
1060                                                                    r.set('is_main',1);
1061                                                                }
1062                                                            });
1063                                                        }
1064                                                        (function() { 
1065                                                             _this.form.findField('shiplist').update();
1066                                                         }).defer(50);
1067                                                    }
1068                                         },
1069                                         items : [
1070
1071                                         ]
1072
1073                                     },
1074                                     sm : {
1075                                         '|xns' : 'Roo.grid',
1076                                         xtype : 'RowSelectionModel',
1077                                         singleSelect : true,
1078                                         xns : Roo.grid
1079                                     },
1080                                     toolbar : {
1081                                         '|xns' : 'Roo',
1082                                         xtype : 'Toolbar',
1083                                         xns : Roo,
1084                                         items : [
1085                                                 {
1086                                                 '|xns' : 'Roo.Toolbar',
1087                                                 xtype : 'Fill',
1088                                                 xns : Roo.Toolbar
1089                                             },
1090                                                 {
1091                                                 '|xns' : 'Roo.Toolbar',
1092                                                 text : "Add",
1093                                                 xtype : 'Button',
1094                                                 cls : 'x-btn-text-icon',
1095                                                 icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1096                                                 xns : Roo.Toolbar,
1097                                                 listeners : {
1098                                                         click : function()
1099                                                            {
1100                                                                   
1101                                                             
1102                                                             Pman.Dialog.XtupleQuickContact.show( 
1103                                                                    {
1104                                                                         _id : 0,
1105                                                                         customer_id : _this.form.findField('cust_id').getValue()
1106                                                                    },
1107                                                                    
1108                                                                    function (data) {
1109                                                                          _this.grid.ds.load({});
1110                                                                    }
1111                                                                ); 
1112                                                            
1113                                                                
1114                                                            }
1115                                                 }
1116                                             },
1117                                                 {
1118                                                 '|xns' : 'Roo.Toolbar',
1119                                                 text : "Delete",
1120                                                 xtype : 'Button',
1121                                                 cls : 'x-btn-text-icon',
1122                                                 icon : rootURL + '/Pman/templates/images/trash.gif',
1123                                                 xns : Roo.Toolbar,
1124                                                 listeners : {
1125                                                         click : function()
1126                                                            {
1127                                                                // will this work?
1128                                                                 var sel = _this.grid.sm.getSelected();
1129                                                                if (!sel  || !sel.data.cntct_id) {
1130                                                                    Roo.MessageBox.alert("Error", "Select a contact to delete");
1131                                                                    return;
1132                                                                }
1133                                                                new Pman.Request({
1134                                                                    url : baseURL + '/Roo/cntct',
1135                                                                    method : 'POST',
1136                                                                    params : {
1137                                                                        _delete : sel.data.cntct_id
1138                                                                    },
1139                                                                    success : function() 
1140                                                                    {
1141                                                                        _this.grid.ds.load({});
1142                                                                    }
1143                                                                });
1144                                                                
1145                                                                
1146                                                             
1147                                                            }
1148                                                 }
1149                                             }
1150                                         ]
1151
1152                                     },
1153                                     '|xns' : 'Roo.grid',
1154                                     autoExpandColumn : 'cntct_addr_id_addr_line1',
1155                                     xtype : 'Grid',
1156                                     loadMask : true,
1157                                     xns : Roo.grid,
1158                                     builderCfg : '{\"cols\":[{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_line1\",\"columnshort\":\"addr_line1\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"},{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_line2\",\"columnshort\":\"addr_line2\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_line3\",\"columnshort\":\"addr_line3\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_country\",\"columnshort\":\"addr_country\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"cntct\",\"column\":\"cntct_phone\",\"columnshort\":\"cntct_phone\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"cntct\",\"column\":\"cntct_phone2\",\"columnshort\":\"cntct_phone2\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"cntct\",\"column\":\"cntct_name\",\"columnshort\":\"cntct_name\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}],\"cols_ex\":[\"cntct_addr_id_addr_line1\"],\"table\":\"cntct\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}',
1159                                     colModel : [
1160                                          {
1161                                                 '|xns' : 'Roo.grid',
1162                                                 xtype : 'ColumnModel',
1163                                                 header : 'Main',
1164                                                 width : 30,
1165                                                 renderer : function(v,x,r) { 
1166                                                 
1167                                                     return     '<img class="x-grid-check-icon' + 
1168                                                                                         (v*1 ? '-checked' : '')  + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1169                                                                                         
1170                                                     
1171                                                 },
1172                                                 xns : Roo.grid,
1173                                                 dataIndex : 'is_main'
1174                                             },
1175 {
1176                                                 '|xns' : 'Roo.grid',
1177                                                 xtype : 'ColumnModel',
1178                                                 header : 'Ship',
1179                                                 width : 30,
1180                                                 renderer : function(v,x,r) { 
1181                                                 
1182                                                 // simple view of address:
1183                                                       return     '<img class="x-grid-check-icon' + 
1184                                                                                         (v*1 ? '-checked' : '')  + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1185                                                                                         
1186                                                     
1187                                                     
1188                                                     
1189                                                 },
1190                                                 xns : Roo.grid,
1191                                                 dataIndex : 'is_ship'
1192                                             },
1193 {
1194                                                 '|xns' : 'Roo.grid',
1195                                                 xtype : 'ColumnModel',
1196                                                 header : 'Contact / Address',
1197                                                 width : 200,
1198                                                 renderer : function(v,x,r) { 
1199                                                 
1200                                                 // simple view of address:
1201                                                 
1202                                                     var add = [];
1203                                                     Roo.each([ 'line1', 'line2', 'line3', 'city', 'state', 'country'], function (k) {
1204                                                         if (!r.data['cntct_addr_id_addr_' + k].length) {
1205                                                             return;
1206                                                         }
1207                                                         add.push(String.format("{0}", r.data['cntct_addr_id_addr_' + k]));
1208                                                     
1209                                                     });
1210                                                 
1211                                                     return String.format(
1212                                                         'Name: <B>{0}</B><br/>' + 
1213                                                         'Phone: <B>{1}</B> / Mobile: <B>{2}</B><br/>' + 
1214                                                         'Email: <a href="mailto:{3}">{3}</a>' +         
1215                                                         (add.length  ? '<BR/>' : '')  + '<B>' + add.join('<BR/>') + '</B>',
1216                                                     
1217                                                         r.data.cntct_name,
1218                                                         r.data.cntct_phone,
1219                                                         r.data.cntct_phone2,
1220                                                         
1221                                                         r.data.cntct_email
1222                                                     );
1223                                                     
1224                                                     
1225                                                 },
1226                                                 xns : Roo.grid,
1227                                                 dataIndex : 'cntct_addr_id_addr_line1'
1228                                             }
1229                                     ],
1230                                     listeners : {
1231                                         rowdblclick : function (_self, rowIndex, e)
1232                                            {
1233                                               
1234                                                var d =this.getDataSource().getAt(rowIndex).data;
1235                                                Pman.Dialog.XtupleContact.show( 
1236                                                    {
1237                                                        cntct_id : d.cntct_id , 
1238                                                        customer_id : _this.form.findField('cust_id').getValue()
1239                                                    } , function() {
1240                                                    _this.grid.ds.load({});
1241                                                });
1242                                            },
1243                                         cellclick : function (_self, rowIndex, columnIndex, e)
1244                                            {
1245                                            
1246                                                   if (columnIndex > 1 ) {
1247                                                       return;
1248                                                   } 
1249                                                   var d = this.ds.getAt(rowIndex);
1250                                                   var f = this.cm.getDataIndex(columnIndex);
1251                                                   
1252                                                   // toggle it..
1253                                            
1254                                                   d.set(f, d.data[f] * 1 ? 0 : 1);
1255                                                   
1256                                                     
1257                                                    if (f == 'is_main' && d.data[f] > 0 ) { // removed..
1258                                                        // set new main contact - remove old..
1259                                                        var cc = _this.form.findField('cust_cntct_id');
1260                                                        var old = cc.getValue() * 1;
1261                                                        if (old > 1) {
1262                                                            this.ds.each(function(r) {
1263                                                                if (r.data.cntct_id == old) {
1264                                                                    r.set('is_main', 0);
1265                                                                }
1266                                                            });
1267                                                        }
1268                                                        cc.setValue(d.data.cntct_id);
1269                                                    }
1270                                                    // sort out shipping.
1271                                                    _this.form.findField('shiplist').update();
1272                                                      
1273                                                   
1274                                            },
1275                                         render : function() 
1276                                            {
1277                                                _this.grid = this; 
1278                                            
1279                                                if (_this.panel.active) {
1280                                                   this.ds.load({});
1281                                                }
1282                                            }
1283                                     },
1284                                     items : [
1285
1286                                     ]
1287
1288                                 },
1289                                 '|xns' : 'Roo',
1290                                 background : false,
1291                                 fitToframe : true,
1292                                 region : 'east',
1293                                 title : "cntct",
1294                                 xtype : 'GridPanel',
1295                                 fitContainer : true,
1296                                 xns : Roo,
1297                                 builderCfg : '{\"cols\":[{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_line1\",\"columnshort\":\"addr_line1\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"},{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_line2\",\"columnshort\":\"addr_line2\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_line3\",\"columnshort\":\"addr_line3\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"addr\",\"column\":\"cntct_addr_id_addr_country\",\"columnshort\":\"addr_country\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"cntct\",\"column\":\"cntct_phone\",\"columnshort\":\"cntct_phone\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"cntct\",\"column\":\"cntct_phone2\",\"columnshort\":\"cntct_phone2\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"cntct\",\"column\":\"cntct_name\",\"columnshort\":\"cntct_name\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}],\"cols_ex\":[\"cntct_addr_id_addr_line1\"],\"table\":\"cntct\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}',
1298                                 tableName : 'cntct',
1299                                 listeners : {
1300                                         activate : function() {
1301                                                _this.panel = this;
1302                                                if (_this.grid) {
1303                                                    _this.grid.ds.load({});
1304                                                }
1305                                            }
1306                                 },
1307                                 items : [
1308
1309                                 ]
1310
1311                             }
1312                         ]
1313
1314                     },
1315                     '|xns' : 'Roo',
1316                     background : false,
1317                     region : 'center',
1318                     title : "Details",
1319                     xtype : 'NestedLayoutPanel',
1320                     xns : Roo,
1321                     items : [
1322
1323                     ]
1324
1325                 },
1326                 {
1327                     grid : {
1328                         dataSource : {
1329                             proxy : {
1330                                 '|xns' : 'Roo.data',
1331                                 url : baseURL + '/Roo/metasql.php',
1332                                 xtype : 'HttpProxy',
1333                                 method : 'GET',
1334                                 xns : Roo.data
1335                             },
1336                             reader : {
1337                                 '|xns' : 'Roo.data',
1338                                 id : 'id',
1339                                 root : 'data',
1340                                 xtype : 'JsonReader',
1341                                 xns : Roo.data,
1342                                 fields : [
1343                                     {
1344                                         'name': 'cohist_id',
1345                                         'type': 'int'
1346                                     },
1347                                     {
1348                                         'name': 'cohist_cust_id',
1349                                         'type': 'int'
1350                                     },
1351                                     {
1352                                         'name': 'cohist_itemsite_id',
1353                                         'type': 'int'
1354                                     },
1355                                     {
1356                                         'name': 'cohist_shipdate',
1357                                         'type': 'date',
1358                                         'dateFormat': 'Y-m-d'
1359                                     },
1360                                     {
1361                                         'name': 'cohist_shipvia',
1362                                         'type': 'string'
1363                                     },
1364                                     {
1365                                         'name': 'cohist_ordernumber',
1366                                         'type': 'string'
1367                                     },
1368                                     {
1369                                         'name': 'cohist_orderdate',
1370                                         'type': 'date',
1371                                         'dateFormat': 'Y-m-d'
1372                                     },
1373                                     {
1374                                         'name': 'cohist_invcnumber',
1375                                         'type': 'string'
1376                                     },
1377                                     {
1378                                         'name': 'cohist_invcdate',
1379                                         'type': 'date',
1380                                         'dateFormat': 'Y-m-d'
1381                                     },
1382                                     {
1383                                         'name': 'cohist_qtyshipped',
1384                                         'type': 'float'
1385                                     },
1386                                     {
1387                                         'name': 'cohist_unitprice',
1388                                         'type': 'float'
1389                                     },
1390                                     {
1391                                         'name': 'cohist_shipto_id',
1392                                         'type': 'int'
1393                                     },
1394                                     {
1395                                         'name': 'cohist_salesrep_id',
1396                                         'type': 'int'
1397                                     },
1398                                     {
1399                                         'name': 'cohist_duedate',
1400                                         'type': 'date',
1401                                         'dateFormat': 'Y-m-d'
1402                                     },
1403                                     {
1404                                         'name': 'cohist_imported',
1405                                         'type': 'int'
1406                                     },
1407                                     {
1408                                         'name': 'cohist_billtoname',
1409                                         'type': 'string'
1410                                     },
1411                                     {
1412                                         'name': 'cohist_billtoaddress1',
1413                                         'type': 'string'
1414                                     },
1415                                     {
1416                                         'name': 'cohist_billtoaddress2',
1417                                         'type': 'string'
1418                                     },
1419                                     {
1420                                         'name': 'cohist_billtoaddress3',
1421                                         'type': 'string'
1422                                     },
1423                                     {
1424                                         'name': 'cohist_billtocity',
1425                                         'type': 'string'
1426                                     },
1427                                     {
1428                                         'name': 'cohist_billtostate',
1429                                         'type': 'string'
1430                                     },
1431                                     {
1432                                         'name': 'cohist_billtozip',
1433                                         'type': 'string'
1434                                     },
1435                                     {
1436                                         'name': 'cohist_shiptoname',
1437                                         'type': 'string'
1438                                     },
1439                                     {
1440                                         'name': 'cohist_shiptoaddress1',
1441                                         'type': 'string'
1442                                     },
1443                                     {
1444                                         'name': 'cohist_shiptoaddress2',
1445                                         'type': 'string'
1446                                     },
1447                                     {
1448                                         'name': 'cohist_shiptoaddress3',
1449                                         'type': 'string'
1450                                     },
1451                                     {
1452                                         'name': 'cohist_shiptocity',
1453                                         'type': 'string'
1454                                     },
1455                                     {
1456                                         'name': 'cohist_shiptostate',
1457                                         'type': 'string'
1458                                     },
1459                                     {
1460                                         'name': 'cohist_shiptozip',
1461                                         'type': 'string'
1462                                     },
1463                                     {
1464                                         'name': 'cohist_commission',
1465                                         'type': 'float'
1466                                     },
1467                                     {
1468                                         'name': 'cohist_commissionpaid',
1469                                         'type': 'int'
1470                                     },
1471                                     {
1472                                         'name': 'cohist_unitcost',
1473                                         'type': 'float'
1474                                     },
1475                                     {
1476                                         'name': 'cohist_misc_type',
1477                                         'type': 'string'
1478                                     },
1479                                     {
1480                                         'name': 'cohist_misc_descrip',
1481                                         'type': 'string'
1482                                     },
1483                                     {
1484                                         'name': 'cohist_misc_id',
1485                                         'type': 'int'
1486                                     },
1487                                     {
1488                                         'name': 'cohist_doctype',
1489                                         'type': 'string'
1490                                     },
1491                                     {
1492                                         'name': 'cohist_promisedate',
1493                                         'type': 'date',
1494                                         'dateFormat': 'Y-m-d'
1495                                     },
1496                                     {
1497                                         'name': 'cohist_ponumber',
1498                                         'type': 'string'
1499                                     },
1500                                     {
1501                                         'name': 'cohist_curr_id',
1502                                         'type': 'int'
1503                                     },
1504                                     {
1505                                         'name': 'cohist_sequence',
1506                                         'type': 'int'
1507                                     },
1508                                     {
1509                                         'name': 'cohist_taxtype_id',
1510                                         'type': 'int'
1511                                     },
1512                                     {
1513                                         'name': 'cohist_taxzone_id',
1514                                         'type': 'int'
1515                                     },
1516                                     {
1517                                         'name': 'cohist_curr_id_curr_id',
1518                                         'type': 'int'
1519                                     },
1520                                     {
1521                                         'name': 'cohist_curr_id_curr_base',
1522                                         'type': 'int'
1523                                     },
1524                                     {
1525                                         'name': 'cohist_curr_id_curr_name',
1526                                         'type': 'string'
1527                                     },
1528                                     {
1529                                         'name': 'cohist_curr_id_curr_symbol',
1530                                         'type': 'string'
1531                                     },
1532                                     {
1533                                         'name': 'cohist_curr_id_curr_abbr',
1534                                         'type': 'string'
1535                                     },
1536                                     {
1537                                         'name': 'cohist_taxzone_id_taxzone_id',
1538                                         'type': 'int'
1539                                     },
1540                                     {
1541                                         'name': 'cohist_taxzone_id_taxzone_code',
1542                                         'type': 'string'
1543                                     },
1544                                     {
1545                                         'name': 'cohist_taxzone_id_taxzone_descrip',
1546                                         'type': 'string'
1547                                     },
1548                                     {
1549                                         'name': 'cohist_taxtype_id_taxtype_id',
1550                                         'type': 'int'
1551                                     },
1552                                     {
1553                                         'name': 'cohist_taxtype_id_taxtype_name',
1554                                         'type': 'string'
1555                                     },
1556                                     {
1557                                         'name': 'cohist_taxtype_id_taxtype_descrip',
1558                                         'type': 'string'
1559                                     },
1560                                     {
1561                                         'name': 'cohist_taxtype_id_taxtype_sys',
1562                                         'type': 'int'
1563                                     }
1564                                 ],
1565                                 totalProperty : 'total'
1566                             },
1567                             '|xns' : 'Roo.data',
1568                             xtype : 'Store',
1569                             remoteSort : true,
1570                             sortInfo : { field : 'cohist_shipvia', direction: 'ASC' },
1571                             xns : Roo.data,
1572                             listeners : {
1573                                 beforeload : function (_self, o)
1574                                    {
1575                                    
1576                                      
1577                                        Roo.apply(o.params, {
1578                                            _group : 'salesHistory',
1579                                            _name : 'detail',
1580                                            'cust_id:number' : _this.form.findField('cust_id').getValue(),
1581                                            'credit:text' : 'credit',
1582                                            'return:text' : 'return',
1583                                            'includeFormatted:int' :  1,
1584                                            'startDate:text' : _this.dateFrom.getValue(),
1585                                            'endDate:text' :  _this.dateTo.getValue()
1586                                        });
1587                                        
1588                                        
1589                                        
1590                                    },
1591                                 load : function (_self, records, options)
1592                                    {
1593                                        function setText(str) {
1594                                        
1595                                            _this.hgrid.footer.el.select('.sales-footer-text', 
1596                                                    true).first().dom.innerHTML = str;
1597                                        }
1598                                        
1599                                        
1600                                        if (!records.length) {
1601                                            //_this.footertext.setText('');
1602                                            Roo.log("no records");
1603                                            setText('');
1604                                            return;
1605                                        }
1606                                        new Pman.Request({
1607                                            method : 'GET',
1608                                            url : baseURL + '/Roo/cohist',
1609                                            params : {
1610                                                _sums : 1,
1611                                                
1612                                                cust_id : _this.form.findField('cust_id').getValue(),
1613                                                startDate : _this.dateFrom.getValue(),
1614                                                endDate :  _this.dateTo.getValue()
1615                                            },
1616                                            success : function(res) 
1617                                            {
1618                                                setText("Total Orders : " + parseInt(res.data[0].total_orders) + 
1619                                                        "  Total Shipped : " + parseInt(res.data[0].total_shipped) +                  
1620                                                       "   Total Value: " + res.data[0].total_basecurr + " " +
1621                                                        Roo.util.Format.number(res.data[0].total_value,2)
1622                                                );
1623                                            }
1624                                        });
1625                                        
1626                                            
1627                                    }
1628                             },
1629                             items : [
1630
1631                             ]
1632
1633                         },
1634                         footer : {
1635                             '|xns' : 'Roo',
1636                             pageSize : 25,
1637                             xtype : 'PagingToolbar',
1638                             emptyMsg : "No cohist found",
1639                             xns : Roo,
1640                             displayMsg : "Displaying Sales {0} - {1} of {2}",
1641                             displayInfo : true,
1642                             items : [
1643                                 {
1644                                     '|xns' : 'Roo.Toolbar',
1645                                     text : "<span class=\"sales-footer-text\"></span>",
1646                                     xtype : 'TextItem',
1647                                     xns : Roo.Toolbar
1648                                 }
1649                             ]
1650
1651                         },
1652                         toolbar : {
1653                             '|xns' : 'Roo',
1654                             xtype : 'Toolbar',
1655                             xns : Roo,
1656                             items : [
1657                                 {
1658                                     '|xns' : 'Roo.Toolbar',
1659                                     text : "From",
1660                                     xtype : 'TextItem',
1661                                     xns : Roo.Toolbar
1662                                 },
1663                                 {
1664                                     '|xns' : 'Roo.form',
1665                                     format : 'd/M/Y',
1666                                     xtype : 'DateField',
1667                                     useIso : true,
1668                                     value : (function() {return (new Date()).add(Date.MONTH, -3); })(),
1669                                     xns : Roo.form,
1670                                     listeners : {
1671                                         render : function (_self)
1672                                            {
1673                                              _this.dateFrom = _self;
1674                                            }
1675                                     }
1676                                 },
1677                                 {
1678                                     '|xns' : 'Roo.Toolbar',
1679                                     text : "To",
1680                                     xtype : 'TextItem',
1681                                     xns : Roo.Toolbar
1682                                 },
1683                                 {
1684                                     '|xns' : 'Roo.form',
1685                                     format : 'd/M/Y',
1686                                     xtype : 'DateField',
1687                                     useIso : true,
1688                                     value : (function() {return (new Date()) })(),
1689                                     xns : Roo.form,
1690                                     listeners : {
1691                                         render : function (_self)
1692                                            {
1693                                            _this.dateTo = _self;
1694                                            }
1695                                     }
1696                                 },
1697                                 {
1698                                     '|xns' : 'Roo.Toolbar',
1699                                     text : "Refresh",
1700                                     xtype : 'Button',
1701                                     xns : Roo.Toolbar,
1702                                     listeners : {
1703                                         click : function (_self, e)
1704                                            {
1705                                                _this.hgrid.footer.onClick('first');
1706                                            }
1707                                     }
1708                                 },
1709                                 {
1710                                     '|xns' : 'Roo.Toolbar',
1711                                     xtype : 'Fill',
1712                                     xns : Roo.Toolbar
1713                                 },
1714                                 {
1715                                     '|xns' : 'Roo.Toolbar',
1716                                     text : "Download",
1717                                     xtype : 'Button',
1718                                     xns : Roo.Toolbar,
1719                                     listeners : {
1720                                         click : function (_self, e)
1721                                            {
1722                                                new Pman.Download({
1723                                                    grid : _this.hgrid
1724                                                });
1725                                            }
1726                                     }
1727                                 }
1728                             ]
1729
1730                         },
1731                         '|xns' : 'Roo.grid',
1732                         autoExpandColumn : 'item_descrip1',
1733                         xtype : 'Grid',
1734                         loadMask : true,
1735                         xns : Roo.grid,
1736                         colModel : [
1737                                  {
1738                                         '|xns' : 'Roo.grid',
1739                                         xtype : 'ColumnModel',
1740                                         header : 'Customer',
1741                                         width : 75,
1742                                         renderer : function(v) { return String.format('{0}', v); },
1743                                         xns : Roo.grid,
1744                                         dataIndex : 'cust_name'
1745                                     },
1746 {
1747                                         '|xns' : 'Roo.grid',
1748                                         xtype : 'ColumnModel',
1749                                         header : 'Order',
1750                                         width : 75,
1751                                         renderer : function(v) { return String.format('{0}', v); },
1752                                         xns : Roo.grid,
1753                                         dataIndex : 'cohist_ordernumber'
1754                                     },
1755 {
1756                                         '|xns' : 'Roo.grid',
1757                                         xtype : 'ColumnModel',
1758                                         header : 'Invoice Month',
1759                                         width : 75,
1760                                         renderer : function(v) { 
1761                                             
1762                                             return String.format('{0}',v);
1763                                          },
1764                                         xns : Roo.grid,
1765                                         dataIndex : 'invmonth'
1766                                     },
1767 {
1768                                         '|xns' : 'Roo.grid',
1769                                         xtype : 'ColumnModel',
1770                                         header : 'Invoice date',
1771                                         width : 75,
1772                                         renderer : function(v) { 
1773                                             var d = Date.parseDate(v, 'Y-m-d');
1774                                             return String.format('{0}', d ? d.format('d/M/Y') : '');
1775                                          },
1776                                         xns : Roo.grid,
1777                                         dataIndex : 'cohead_orderdate'
1778                                     },
1779 {
1780                                         '|xns' : 'Roo.grid',
1781                                         xtype : 'ColumnModel',
1782                                         header : 'Invoice date',
1783                                         width : 75,
1784                                         renderer : function(v) { 
1785                                             var d = Date.parseDate(v, 'Y-m-d');
1786                                             return String.format('{0}', d ? d.format('d/M/Y') : '');
1787                                          },
1788                                         xns : Roo.grid,
1789                                         dataIndex : 'cohist_invcdate'
1790                                     },
1791 {
1792                                         '|xns' : 'Roo.grid',
1793                                         xtype : 'ColumnModel',
1794                                         header : 'Invoice#',
1795                                         width : 75,
1796                                         renderer : function(v) { return String.format('{0}', v); },
1797                                         xns : Roo.grid,
1798                                         dataIndex : 'cohist_invcnumber'
1799                                     },
1800 {
1801                                         '|xns' : 'Roo.grid',
1802                                         xtype : 'ColumnModel',
1803                                         header : 'Item No.',
1804                                         width : 75,
1805                                         renderer : function(v) { return String.format('{0}', v ? v   : ''); },
1806                                         xns : Roo.grid,
1807                                         dataIndex : 'item_number'
1808                                     },
1809 {
1810                                         '|xns' : 'Roo.grid',
1811                                         xtype : 'ColumnModel',
1812                                         header : 'Description',
1813                                         width : 200,
1814                                         renderer : function(v) { return String.format('{0}', v); },
1815                                         xns : Roo.grid,
1816                                         dataIndex : 'item_descrip1'
1817                                     },
1818 {
1819                                         '|xns' : 'Roo.grid',
1820                                         align : 'right',
1821                                         xtype : 'ColumnModel',
1822                                         header : 'Qty',
1823                                         width : 70,
1824                                         renderer : function(v) { return parseInt(v); },
1825                                         xns : Roo.grid,
1826                                         dataIndex : 'cohist_qtyshipped'
1827                                     },
1828 {
1829                                         '|xns' : 'Roo.grid',
1830                                         xtype : 'ColumnModel',
1831                                         header : 'Currency',
1832                                         width : 75,
1833                                         renderer : function(v) { return String.format('{0}', v.split(/\s+/)[0]); },
1834                                         xns : Roo.grid,
1835                                         dataIndex : 'currabbr'
1836                                     },
1837 {
1838                                         '|xns' : 'Roo.grid',
1839                                         align : 'right',
1840                                         xtype : 'ColumnModel',
1841                                         header : 'Unit Price',
1842                                         width : 75,
1843                                         renderer : function(v) { return Roo.util.Format.number( v, 2); },
1844                                         xns : Roo.grid,
1845                                         dataIndex : 'cohist_unitprice'
1846                                     },
1847 {
1848                                         '|xns' : 'Roo.grid',
1849                                         align : 'right',
1850                                         xtype : 'ColumnModel',
1851                                         header : 'Ext Cost',
1852                                         width : 75,
1853                                         renderer : function(v) { return Roo.util.Format.number( v, 2); },
1854                                         xns : Roo.grid,
1855                                         dataIndex : 'extprice'
1856                                     }
1857                         ],
1858                         listeners : {
1859                                 rowdblclick : function (_self, rowIndex, e)
1860                                    {
1861                                        if (!_this.dialog) return;
1862                                        _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
1863                                            _this.grid.footer.onClick('first');
1864                                        }); 
1865                                    },
1866                                 render : function() 
1867                                    {
1868                                        _this.hgrid = this; 
1869                                        //_this.dialog = Pman.Dialog.FILL_IN
1870                                        if (_this.hpanel.active) {
1871                                           this.footer.onClick('first');
1872                                        }
1873                                    }
1874                         },
1875                         items : [
1876
1877                         ]
1878
1879                     },
1880                     '|xns' : 'Roo',
1881                     fitToframe : true,
1882                     background : true,
1883                     region : 'center',
1884                     title : "History",
1885                     xtype : 'GridPanel',
1886                     fitContainer : true,
1887                     xns : Roo,
1888                     tableName : 'cohist',
1889                     listeners : {
1890                         activate : function() {
1891                                _this.hpanel = this;
1892                                if (_this.hgrid) {
1893                                    _this.hgrid.footer.onClick('first');
1894                                }
1895                            }
1896                     },
1897                     items : [
1898
1899                     ]
1900
1901                 },
1902                 {
1903                     grid : {
1904                         dataSource : {
1905                             proxy : {
1906                                 '|xns' : 'Roo.data',
1907                                 url : baseURL + '/Roo/Images.php',
1908                                 method : 'GET',
1909                                 xtype : 'HttpProxy',
1910                                 xns : Roo.data
1911                             },
1912                             reader : {
1913                                 '|xns' : 'Roo.data',
1914                                 id : 'id',
1915                                 root : 'data',
1916                                 xtype : 'JsonReader',
1917                                 xns : Roo.data,
1918                                 fields : [
1919                                     {
1920                                         'name': 'id',
1921                                         'type': 'int'
1922                                     },
1923                                     {
1924                                         'name': 'filename',
1925                                         'type': 'string'
1926                                     },
1927                                     {
1928                                         'name': 'imgtype',
1929                                         'type': 'string'
1930                                     },
1931                                     {
1932                                         'name': 'created',
1933                                         'type': 'date',
1934                                         'dateFormat': 'Y-m-d H:i:s'
1935                                     }
1936                                 ],
1937                                 totalProperty : 'total'
1938                             },
1939                             '|xns' : 'Roo.data',
1940                             xtype : 'Store',
1941                             remoteSort : true,
1942                             sortInfo : { field : 'id', direction: 'ASC' },
1943                             xns : Roo.data,
1944                             listeners : {
1945                                 beforeload : function (_self, o)
1946                                    {
1947                                        o.params = o.params || {}
1948                                        
1949                                        var cust_id = _this.form.findField('cust_id').getValue() * 1;
1950                                        
1951                                        if(cust_id < 1){
1952                                            this.removeAll();
1953                                            return false;
1954                                        }
1955                                    
1956                                        o.params.ontable = 'custinfo';
1957                                        o.params.onid = cust_id;
1958                                    }
1959                             },
1960                             items : [
1961
1962                             ]
1963
1964                         },
1965                         footer : {
1966                             '|xns' : 'Roo',
1967                             pageSize : 25,
1968                             xtype : 'PagingToolbar',
1969                             emptyMsg : "No Images found",
1970                             xns : Roo,
1971                             displayMsg : "Displaying Images {0} - {1} of {2}",
1972                             displayInfo : true
1973                         },
1974                         '|xns' : 'Roo.grid',
1975                         autoExpandColumn : 'imgtype',
1976                         xtype : 'Grid',
1977                         loadMask : true,
1978                         xns : Roo.grid,
1979                         cm : [
1980                                  {
1981                                         '|xns' : 'Roo.grid',
1982                                         xtype : 'ColumnModel',
1983                                         header : 'Image',
1984                                         width : 100,
1985                                         renderer : function(v,x,r) {
1986                                             return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}" height="50">', baseURL, v, r.data.filename);
1987                                         },
1988                                         xns : Roo.grid,
1989                                         dataIndex : 'id'
1990                                     },
1991 {
1992                                         '|xns' : 'Roo.grid',
1993                                         xtype : 'ColumnModel',
1994                                         width : 150,
1995                                         header : 'Date',
1996                                         renderer : function(v) { 
1997                                             return String.format('{0}', v ? v.format('d/M/Y') : '');
1998                                          },
1999                                         xns : Roo.grid,
2000                                         dataIndex : 'created'
2001                                     },
2002 {
2003                                         '|xns' : 'Roo.grid',
2004                                         xtype : 'ColumnModel',
2005                                         header : 'File Name',
2006                                         width : 200,
2007                                         renderer : function(v) { return String.format('{0}', v); },
2008                                         xns : Roo.grid,
2009                                         dataIndex : 'filename'
2010                                     },
2011 {
2012                                         '|xns' : 'Roo.grid',
2013                                         xtype : 'ColumnModel',
2014                                         header : 'Type',
2015                                         width : 200,
2016                                         renderer : function(v) { 
2017                                             return String.format('{0}',v);
2018                                          },
2019                                         xns : Roo.grid,
2020                                         dataIndex : 'imgtype'
2021                                     }
2022                         ],
2023                         listeners : {
2024                                 rowdblclick : function (_self, rowIndex, e)
2025                                    {
2026                                       var s =  _self.getDataSource().getAt(rowIndex);
2027                                       
2028                                       new Pman.Download({
2029                                            url : baseURL + '/Images/Download/' + s.data.id
2030                                        });
2031                                       
2032                                    },
2033                                 render : function() 
2034                                    {
2035                                        _this.igrid = this; 
2036                                    
2037                                        if (_this.ipanel.active) {
2038                                           this.footer.onClick('first');
2039                                        }
2040                                    }
2041                         },
2042                         items : [
2043
2044                         ]
2045
2046                     },
2047                     '|xns' : 'Roo',
2048                     region : 'center',
2049                     fitToframe : true,
2050                     background : true,
2051                     title : "Images",
2052                     xtype : 'GridPanel',
2053                     fitContainer : true,
2054                     xns : Roo,
2055                     tableName : 'Images',
2056                     listeners : {
2057                         activate : function() {
2058                                _this.ipanel = this;
2059                                if (_this.igrid) {
2060                                    _this.igrid.footer.onClick('first');
2061                                }
2062                            }
2063                     },
2064                     items : [
2065
2066                     ]
2067
2068                 }
2069             ]
2070
2071         });
2072     }
2073 };