Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleInvoice.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Dialog.XtupleInvoice = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             closable : true,
34             collapsible : false,
35             height : 600,
36             modal : true,
37             resizable : false,
38             title : "Edit / Create Invoice",
39             width : 900,
40             items : [
41                 {
42                     xtype: 'NestedLayoutPanel',
43                     xns: Roo,
44                     region : 'north',
45                     layout : {
46                         xtype: 'BorderLayout',
47                         xns: Roo,
48                         items : [
49                             {
50                                 xtype: 'GridPanel',
51                                 xns: Roo,
52                                 listeners : {
53                                     activate : function() {
54                                         _this.cmpanel = this;
55                                     
56                                     }
57                                 },
58                                 background : false,
59                                 fitContainer : true,
60                                 fitToframe : true,
61                                 region : 'east',
62                                 tableName : 'cmhead',
63                                 title : "Apply Credit Memos",
64                                 grid : {
65                                     xtype: 'Grid',
66                                     xns: Roo.grid,
67                                     listeners : {
68                                         render : function() 
69                                         {
70                                             _this.cmgrid = this; 
71                                             
72                                         },
73                                         cellclick : function (_self, rowIndex, columnIndex, e)
74                                         {
75                                         
76                                                if (columnIndex > 0 ) {
77                                                    return;
78                                                } 
79                                                var d = this.ds.getAt(rowIndex);
80                                                var f = this.cm.getDataIndex(columnIndex);
81                                                
82                                                // toggle it..
83                                             
84                                                d.set(f, d.data[f] * 1 ? 0 : 1);
85                                                 
86                                                 // sort out shipping.
87                                                _this.form.findField('cobapply_list').update();
88                                                   
89                                                
90                                         },
91                                         rowdblclick : function (_self, rowIndex, e)
92                                         {
93                                             var s = _this.cmgrid.ds.getAt(rowIndex);
94                                         
95                                             Pman.Dialog.XtupleCreditMemo.show({
96                                                 cmhead_id : s.data.join_aropen_cmhead_id
97                                             },function() {
98                                                 _this.cmgrid.ds.load({});
99                                             
100                                             });
101                                         }
102                                     },
103                                     autoExpandColumn : 'aropen_docnumber',
104                                     loadMask : true,
105                                     toolbar : {
106                                         xtype: 'Toolbar',
107                                         xns: Roo,
108                                         items : [
109                                             {
110                                                 xtype: 'Fill',
111                                                 xns: Roo.Toolbar
112                                             },
113                                             {
114                                                 xtype: 'Button',
115                                                 xns: Roo.Toolbar,
116                                                 listeners : {
117                                                     click : function()
118                                                     {
119                                                         var postit = function(params){
120                                                             new Pman.Request(\r
121                                                             {\r
122                                                                 url : baseURL + '/Roo/Cmhead',\r
123                                                                 mask: params.mask,\r
124                                                                 method : 'POST',\r
125                                                                 params : params.postdata,\r
126                                                                 success : function(res)\r
127                                                                 {\r
128                                                                      _this.cmgrid.ds.load({});
129                                                                     (function(){
130                                                                         _this.cmgrid.ds.each(function(d){
131                                                                             if(d.data.join_aropen_cmhead_id == res.data){
132                                                                                 d.set('toapply', 1);
133                                                                                 return false;
134                                                                             }
135                                                                         })
136                                                                     }).defer(500);\r
137                                                                 } \r
138                                                             });\r
139                                                         }
140                                                         var opendialog  = function(data){
141                                                             Pman.Dialog.XtupleCreditMemo.show( data , function(res) {
142                                                                 if(!res.has_item){
143                                                                    Roo.MessageBox.confirm(\r
144                                                                         "Confirm",\r
145                                                                         "These is no any credit items in this credit memo! Press YES to reopen the dialog for editing, Press NO will delete this credit memo.",\r
146                                                                         function(r) {\r
147                                                                             if (r != 'yes') {
148                                                                                 // delete the credit memo
149                                                                                 Roo.log('deleting');
150                                                                                 var params = {
151                                                                                     postdata : {
152                                                                                         _delete : res.cmhead_id
153                                                                                     },
154                                                                                     mask : 'Deleting'
155                                                                                 };
156                                                                                 postit(params);\r
157                                                                                 return;\r
158                                                                             }
159                                                                             // reopen\r
160                                                                             opendialog({cmhead_id : res.cmhead_id});
161                                                                             return;\r
162                                                                         }\r
163                                                                     ); 
164                                                                     return;
165                                                                 }
166                                                                 
167                                                                 Roo.MessageBox.confirm(\r
168                                                                     "Confirm Posting",\r
169                                                                     "Are you sure this credit memo is complete? <B>Voiding a Credit memo involves creating a sales order and invoice </b>, so make sure this is correct before posting! Press YES will post it, Press NO to reopen the dialog for editing.",\r
170                                                                     function(r) {\r
171                                                                         if (r != 'yes') {
172                                                                             opendialog({cmhead_id : res.cmhead_id});
173                                                                             return;\r
174                                                                         }\r
175                                                                         // postit
176                                                                         var params = {
177                                                                             postdata : {
178                                                                                 cmhead_id : res.cmhead_id,
179                                                                                 _post : 1
180                                                                             },
181                                                                             mask : 'Posting'
182                                                                         };
183                                                                         postit(params);
184                                                                        
185                                                                         return;\r
186                                                                     }\r
187                                                                 );
188                                                                 
189                                                                 
190                                                                 
191                                                             })
192                                                         }
193                                                         
194                                                         
195                                                         
196                                                         var cmdata = {
197                                                                 cmhead_cust_id : _this.data.cmdata.cm_cust_id,
198                                                                 cmhead_cust_id_cust_name : _this.data.cmdata.cm_cust_id_cust_name,
199                                                                 cmhead_curr_id : _this.data.cmdata.cm_curr_id,
200                                                                 cmhead_curr_id_curr_name : _this.data.cmdata.cm_curr_id_curr_name,
201                                                                 cmhead_terms_id : _this.data.cmdata.cm_terms_id,
202                                                                 cmhead_terms_id_terms_descrip : _this.data.cmdata.cm_terms_id_terms_descrip,
203                                                                 cmhead_salesrep_id : _this.data.cmdata.cm_salesrep_id,
204                                                                 cmhead_salesrep_id_salesrep_name : _this.data.cmdata.cm_salesrep_id_salesrep_name,
205                                                                 cmhead_docdate : new Date(),
206                                                                 cmhead_taxzone_id : _this.data.cmdata.cm_taxzone_id,
207                                                                 cmhead_taxzone_id_taxzone_descrip : _this.data.cmdata.cm_taxzone_id_taxzone_descrip,
208                                                                 cmhead_billto_cntct_id : _this.data.cmdata.cm_billto_cntct_id,
209                                                                 cmhead_billto_cntct_id_cntct_name : _this.data.cmdata.cm_billto_cntct_id_cntct_name,
210                                                                 cmhead_location_id : _this.data.cmdata.cm_location_src,
211                                                                 cmhead_location_id_location_name : _this.data.cmdata.cm_location_src_location_name,
212                                                                 billto_address : _this.data.cmdata.cm_billto_address
213                                                                 
214                                                                 
215                                                         };
216                                                         
217                                                         opendialog(cmdata);
218                                                         
219                                                     }
220                                                 },
221                                                 cls : 'x-btn-text-icon',
222                                                 text : "Add",
223                                                 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
224                                             }
225                                         ]
226                                     },
227                                     dataSource : {
228                                         xtype: 'Store',
229                                         xns: Roo.data,
230                                         listeners : {
231                                             beforeload : function (_self, o)
232                                             {
233                                                 o.params = o.params || {};
234                                                 o.params.limit = 999;
235                                                 o.params._opencm = 1;
236                                                 o.params._for_cohead = _this.form.findField('cobmisc_cohead_id').getValue();
237                                                 o.params._for_cobmisc_id = _this.form.findField('cobmisc_id').getValue();
238                                             },
239                                             load : function (_self, records, options)
240                                             {
241                                                  _this.form.findField('cobapply_list').update();
242                                             }
243                                         },
244                                         remoteSort : true,
245                                         sortInfo : { field : 'aropen_docnumber', direction: 'DESC' },
246                                         proxy : {
247                                             xtype: 'HttpProxy',
248                                             xns: Roo.data,
249                                             method : 'GET',
250                                             url : baseURL + '/Roo/aropen.php'
251                                         },
252                                         reader : {
253                                             xtype: 'JsonReader',
254                                             xns: Roo.data,
255                                             totalProperty : 'total',
256                                             root : 'data',
257                                             id : 'id',
258                                             fields : [
259                                                 {
260                                                     'name': 'cmhead_id',
261                                                     'type': 'int'
262                                                 },
263                                                 {
264                                                     'name': 'cmhead_number',
265                                                     'type': 'string'
266                                                 },
267                                                 {
268                                                     'name': 'cmhead_posted',
269                                                     'type': 'int'
270                                                 },
271                                                 {
272                                                     'name': 'cmhead_invcnumber',
273                                                     'type': 'string'
274                                                 },
275                                                 {
276                                                     'name': 'cmhead_custponumber',
277                                                     'type': 'string'
278                                                 },
279                                                 {
280                                                     'name': 'cmhead_cust_id',
281                                                     'type': 'int'
282                                                 },
283                                                 {
284                                                     'name': 'cmhead_docdate',
285                                                     'type': 'date',
286                                                     'dateFormat': 'Y-m-d'
287                                                 },
288                                                 {
289                                                     'name': 'cmhead_shipto_id',
290                                                     'type': 'int'
291                                                 },
292                                                 {
293                                                     'name': 'cmhead_shipto_name',
294                                                     'type': 'string'
295                                                 },
296                                                 {
297                                                     'name': 'cmhead_shipto_address1',
298                                                     'type': 'string'
299                                                 },
300                                                 {
301                                                     'name': 'cmhead_shipto_address2',
302                                                     'type': 'string'
303                                                 },
304                                                 {
305                                                     'name': 'cmhead_shipto_address3',
306                                                     'type': 'string'
307                                                 },
308                                                 {
309                                                     'name': 'cmhead_shipto_city',
310                                                     'type': 'string'
311                                                 },
312                                                 {
313                                                     'name': 'cmhead_shipto_state',
314                                                     'type': 'string'
315                                                 },
316                                                 {
317                                                     'name': 'cmhead_shipto_zipcode',
318                                                     'type': 'string'
319                                                 },
320                                                 {
321                                                     'name': 'cmhead_salesrep_id',
322                                                     'type': 'int'
323                                                 },
324                                                 {
325                                                     'name': 'cmhead_freight',
326                                                     'type': 'float'
327                                                 },
328                                                 {
329                                                     'name': 'cmhead_misc',
330                                                     'type': 'float'
331                                                 },
332                                                 {
333                                                     'name': 'cmhead_comments',
334                                                     'type': 'string'
335                                                 },
336                                                 {
337                                                     'name': 'cmhead_printed',
338                                                     'type': 'int'
339                                                 },
340                                                 {
341                                                     'name': 'cmhead_billtoname',
342                                                     'type': 'string'
343                                                 },
344                                                 {
345                                                     'name': 'cmhead_billtoaddress1',
346                                                     'type': 'string'
347                                                 },
348                                                 {
349                                                     'name': 'cmhead_billtoaddress2',
350                                                     'type': 'string'
351                                                 },
352                                                 {
353                                                     'name': 'cmhead_billtoaddress3',
354                                                     'type': 'string'
355                                                 },
356                                                 {
357                                                     'name': 'cmhead_billtocity',
358                                                     'type': 'string'
359                                                 },
360                                                 {
361                                                     'name': 'cmhead_billtostate',
362                                                     'type': 'string'
363                                                 },
364                                                 {
365                                                     'name': 'cmhead_billtozip',
366                                                     'type': 'string'
367                                                 },
368                                                 {
369                                                     'name': 'cmhead_hold',
370                                                     'type': 'int'
371                                                 },
372                                                 {
373                                                     'name': 'cmhead_commission',
374                                                     'type': 'float'
375                                                 },
376                                                 {
377                                                     'name': 'cmhead_misc_accnt_id',
378                                                     'type': 'int'
379                                                 },
380                                                 {
381                                                     'name': 'cmhead_misc_descrip',
382                                                     'type': 'string'
383                                                 },
384                                                 {
385                                                     'name': 'cmhead_rsncode_id',
386                                                     'type': 'int'
387                                                 },
388                                                 {
389                                                     'name': 'cmhead_curr_id',
390                                                     'type': 'int'
391                                                 },
392                                                 {
393                                                     'name': 'cmhead_freighttaxtype_id',
394                                                     'type': 'int'
395                                                 },
396                                                 {
397                                                     'name': 'cmhead_gldistdate',
398                                                     'type': 'date',
399                                                     'dateFormat': 'Y-m-d'
400                                                 },
401                                                 {
402                                                     'name': 'cmhead_billtocountry',
403                                                     'type': 'string'
404                                                 },
405                                                 {
406                                                     'name': 'cmhead_shipto_country',
407                                                     'type': 'string'
408                                                 },
409                                                 {
410                                                     'name': 'cmhead_rahead_id',
411                                                     'type': 'int'
412                                                 },
413                                                 {
414                                                     'name': 'cmhead_taxzone_id',
415                                                     'type': 'int'
416                                                 },
417                                                 {
418                                                     'name': 'cmhead_prj_id',
419                                                     'type': 'int'
420                                                 },
421                                                 {
422                                                     'name': 'cmhead_curr_id_curr_id',
423                                                     'type': 'int'
424                                                 },
425                                                 {
426                                                     'name': 'cmhead_curr_id_curr_base',
427                                                     'type': 'int'
428                                                 },
429                                                 {
430                                                     'name': 'cmhead_curr_id_curr_name',
431                                                     'type': 'string'
432                                                 },
433                                                 {
434                                                     'name': 'cmhead_curr_id_curr_symbol',
435                                                     'type': 'string'
436                                                 },
437                                                 {
438                                                     'name': 'cmhead_curr_id_curr_abbr',
439                                                     'type': 'string'
440                                                 },
441                                                 {
442                                                     'name': 'cmhead_taxzone_id_taxzone_id',
443                                                     'type': 'int'
444                                                 },
445                                                 {
446                                                     'name': 'cmhead_taxzone_id_taxzone_code',
447                                                     'type': 'string'
448                                                 },
449                                                 {
450                                                     'name': 'cmhead_taxzone_id_taxzone_descrip',
451                                                     'type': 'string'
452                                                 },
453                                                 {
454                                                     'name': 'cmhead_prj_id_prj_id',
455                                                     'type': 'int'
456                                                 },
457                                                 {
458                                                     'name': 'cmhead_prj_id_prj_number',
459                                                     'type': 'string'
460                                                 },
461                                                 {
462                                                     'name': 'cmhead_prj_id_prj_name',
463                                                     'type': 'string'
464                                                 },
465                                                 {
466                                                     'name': 'cmhead_prj_id_prj_descrip',
467                                                     'type': 'string'
468                                                 },
469                                                 {
470                                                     'name': 'cmhead_prj_id_prj_status',
471                                                     'type': 'string'
472                                                 },
473                                                 {
474                                                     'name': 'cmhead_prj_id_prj_so',
475                                                     'type': 'int'
476                                                 },
477                                                 {
478                                                     'name': 'cmhead_prj_id_prj_wo',
479                                                     'type': 'int'
480                                                 },
481                                                 {
482                                                     'name': 'cmhead_prj_id_prj_po',
483                                                     'type': 'int'
484                                                 },
485                                                 {
486                                                     'name': 'cmhead_prj_id_prj_owner_username',
487                                                     'type': 'string'
488                                                 },
489                                                 {
490                                                     'name': 'cmhead_prj_id_prj_start_date',
491                                                     'type': 'date'
492                                                 },
493                                                 {
494                                                     'name': 'cmhead_prj_id_prj_due_date',
495                                                     'type': 'date'
496                                                 },
497                                                 {
498                                                     'name': 'cmhead_prj_id_prj_assigned_date',
499                                                     'type': 'date'
500                                                 },
501                                                 {
502                                                     'name': 'cmhead_prj_id_prj_completed_date',
503                                                     'type': 'date'
504                                                 },
505                                                 {
506                                                     'name': 'cmhead_prj_id_prj_username',
507                                                     'type': 'string'
508                                                 },
509                                                 {
510                                                     'name': 'cmhead_prj_id_prj_recurring_prj_id',
511                                                     'type': 'int'
512                                                 },
513                                                 {
514                                                     'name': 'cmhead_freighttaxtype_id_taxtype_id',
515                                                     'type': 'int'
516                                                 },
517                                                 {
518                                                     'name': 'cmhead_freighttaxtype_id_taxtype_name',
519                                                     'type': 'string'
520                                                 },
521                                                 {
522                                                     'name': 'cmhead_freighttaxtype_id_taxtype_descrip',
523                                                     'type': 'string'
524                                                 },
525                                                 {
526                                                     'name': 'cmhead_freighttaxtype_id_taxtype_sys',
527                                                     'type': 'int'
528                                                 }
529                                             ]
530                                         }
531                                     },
532                                     colModel : [
533                                         {
534                                             xtype: 'ColumnModel',
535                                             xns: Roo.grid,
536                                             dataIndex : 'toapply',
537                                             header : 'Apply',
538                                             width : 50,
539                                             renderer : function(v,x,r) { 
540                                             
541                                                 return     '<img class="x-grid-check-icon' + 
542                                                                 (v*1 ? '-checked' : '')  + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
543                                                                                     
544                                                 
545                                             }
546                                         },
547                                         {
548                                             xtype: 'ColumnModel',
549                                             xns: Roo.grid,
550                                             dataIndex : 'aropen_docnumber',
551                                             header : 'Number#',
552                                             width : 150,
553                                             renderer : function(v) { return String.format('{0}', v); }
554                                         },
555                                         {
556                                             xtype: 'ColumnModel',
557                                             xns: Roo.grid,
558                                             align : 'right',
559                                             dataIndex : 'balance',
560                                             header : 'Amount Avail',
561                                             width : 75,
562                                             renderer : function(v,x,r) { 
563                                                 if (r.data.applied*1.0 > 0.0)  {
564                                                     return String.format('{0}', r.data.applied*1.0); 
565                                                 }
566                                             
567                                                 return String.format('{0}', v); 
568                                             }
569                                         }
570                                     ]
571                                 }
572                             },
573                             {
574                                 xtype: 'ContentPanel',
575                                 xns: Roo,
576                                 region : 'center',
577                                 items : [
578                                     {
579                                         xtype: 'Form',
580                                         xns: Roo.form,
581                                         listeners : {
582                                             actioncomplete : function (_self,action) {
583                                                  if (action.type == 'setdata') {
584                                                     if (_this.data.cobmisc_id) {
585                                                         this.load({ method: 'GET', params: { '_id' : _this.data.cobmisc_id }});
586                                                        return;
587                                                    }      
588                                                    
589                                                        
590                                                    
591                                                    _this.saveBtn.show();
592                                                    // see if we can create an invoice...
593                                                    new Pman.Request({
594                                                         url : baseURL + '/Roo/Cobmisc',
595                                                         params : {
596                                                             _canCreate : _this.data.cobmisc_cohead_id
597                                                         },
598                                                         method : 'GET',
599                                                         success: function(r) {
600                                                             if (r.data.canCreate * 1 > 0 ) {
601                                                                 Roo.MessageBox.alert(
602                                                                     "Error", "An unposted Bill already exists for this order"
603                                                                 );
604                                                                 _this.dialog.hide();
605                                                                 return;
606                                                             }
607                                             
608                                                            // _this.form.findField('cobmisc_misc').setValue(r.data.cohead.cohead_misc);
609                                                             _this.form.findField('cobmisc_misc').setValue(r.data.cohead.cohead_pretax_discount);
610                                                             _this.form.findField('cobmisc_cohead_id_cohead_pretax_discount').setValue(r.data.cohead.cohead_pretax_discount);
611                                                             _this.form.findField('cobmisc_posttax_discount').setValue(
612                                                                 (1* r.data.cohead.cohead_posttax_discount) //- (1*r.data.cohead.cohead_pretax_discount)
613                                                             );
614                                                            // _this.form.findField('cobmisc_cohead_id_cohead_posttax_discount').setValue(r.data.cohead.cohead_posttax_discount);
615                                                             _this.form.findField('cobmisc_misc_descrip').setValue(r.data.cohead.cohead_misc_descrip);
616                                                            _this.grid.ds.load({});
617                                                         }
618                                                     });
619                                                          
620                                                     
621                                                 }
622                                                 if (action.type == 'load') {
623                                                     var d = action.result.data;
624                                                     
625                                                     
626                                                     if(d.cobmisc_misc != 0 && d.cobmisc_posttax_discount == 0 && d.cobmisc_cohead_id_cohead_pretax_discount == 0){
627                                                         _this.form.findField('cobmisc_cohead_id_cohead_pretax_discount').setValue(d.cobmisc_misc);
628                                                     }
629                                                     
630                                                     _this.form.findField('cobmisc_posttax_discount').setValue(d.cobmisc_misc - d.cobmisc_cohead_id_cohead_pretax_discount);
631                                                     
632                                                     if (d.cobmisc_invchead_id *1 > 0) {
633                                                             Roo.MessageBox.alert(
634                                                                     "Warning", "This invoice has been posted, you must void it before you can edit it"
635                                                                 );
636                                             
637                                                             _this.saveBtn.hide();
638                                                         
639                                                     } else {
640                                                         _this.saveBtn.show();
641                                                     }
642                                                      _this.grid.ds.load({});
643                                                     return;
644                                                 }
645                                                 if (action.type =='submit') {
646                                                 
647                                                     _this.dialog.hide();
648                                                 
649                                                      if (_this.callback) {
650                                                         _this.callback.call(_this, _this.form.getValues());
651                                                      }
652                                                      _this.form.reset();
653                                                      return;
654                                                 }
655                                                 
656                                             },
657                                             rendered : function (form)
658                                             {
659                                                 _this.form= form;
660                                             }
661                                         },
662                                         method : 'POST',
663                                         style : 'margin:10px;',
664                                         recalc : function() {
665                                             // recalc prices.
666                                             var error = 0;
667                                             var ic = 0.0;
668                                             var total_tax = 0.0;
669                                             _this.grid.ds.each(function(r) {
670                                                 ic += ((r.data.cobill_qty * r.data.coitem_price).toFixed(2) * 1);
671                                                 if (r.data.calc_tax) {
672                                                     // either full, or a proportion of...
673                                                     total_tax += (r.data.cobill_qty == r.data.coitem_qtyord) ? 
674                                                         (1*r.data.calc_tax) : (
675                                                             (1*r.data.calc_tax) * (r.data.cobill_qty / r.data.coitem_qtyord)
676                                                         );
677                                                 }
678                                             
679                                             });
680                                             
681                                             _this.form.findField('cobmisc_itemcost').setValue(ic.toFixed(2));    
682                                             _this.form.findField('cobmisc_total_tax').setValue( total_tax.toFixed(2));
683                                         
684                                             
685                                             var total  = (_this.form.findField('cobmisc_itemcost').getValue() * 1.0) +
686                                                  ( _this.form.findField('cobmisc_freight').getValue() * 1.0)  + 
687                                          
688                                                  ( _this.form.findField('cobmisc_cohead_id_cohead_pretax_discount').getValue() * 1.0)  + 
689                                                  ( _this.form.findField('cobmisc_posttax_discount').getValue() * 1.0)  + 
690                                                  ( _this.form.findField('cobmisc_total_tax').getValue() * 1.0)   
691                                                  ;
692                                         
693                                             // special handling for credit memos.
694                                             
695                                             var val = 0.0;\r
696                                             var count = 0;\r
697                                             _this.cmgrid.ds.each(function(r) {\r
698                                                 if (r.data.toapply *  1)  { \r
699                                                     count = count + 1;\r
700                                                     if (r.data.applied *1.0 > 0.0) {\r
701                                                         val += parseFloat(r.data.applied);\r
702                                                         return;\r
703                                                     }\r
704                                                     val += parseFloat(r.data.balance);\r
705                                                 }\r
706                                                \r
707                                             });\r
708                                             if(count == 1 && total < val){
709                                                 val = total;
710                                             }
711                                             
712                                             _this.form.findField('cobmisc_cm_total').setValue( (val * -1).toFixed(2));
713                                             _this.form.findField('cobmisc_total').setValue((total - val).toFixed(2));
714                                             _this.form.findField('cobapply_total').setValue((val * -1).toFixed(2));
715                                             
716                                             /*
717                                             if (total < 0.0) {
718                                                 // this is an error condition.
719                                                 _this.form.findField('cobmisc_total').setValue(total);
720                                                 return;
721                                             
722                                             }
723                                          
724                                            
725                                             var cmlist =  _this.form.findField('cobapply_list').getValue();
726                                             var cmval =  _this.form.findField('cobapply_total').getValue() * 1.0;
727                                             
728                                             if (total + cmval >= 0.0 ) {
729                                                 _this.form.findField('cobmisc_total').setValue(((total + cmval) * 1.0).toFixed(2));
730                                                 return; 
731                                             }
732                                             if (cmlist.length || cmlist.split(',').length > 1) {
733                                                 _this.form.findField('cobmisc_total').setValue(total + cmval);         
734                                                 return;
735                                             }
736                                             // fixme we need to work out the correct value...
737                                             
738                                              _this.form.findField('cobmisc_cm_total').setValue( (total * -1).toFixed(2));
739                                             
740                                             _this.form.findField('cobmisc_total').setValue(0.0);         
741                                                 
742                                             */
743                                             
744                                         },
745                                         url : baseURL + '/Roo/cobmisc.php',
746                                         items : [
747                                             {
748                                                 xtype: 'Row',
749                                                 xns: Roo.form,
750                                                 width : 750,
751                                                 items : [
752                                                     {
753                                                         xtype: 'Column',
754                                                         xns: Roo.form,
755                                                         width : 250,
756                                                         items : [
757                                                             {
758                                                                 xtype: 'FieldSet',
759                                                                 xns: Roo.form,
760                                                                 legend : "Invoice Details",
761                                                                 style : 'width:230px',
762                                                                 items : [
763                                                                     {
764                                                                         xtype: 'DateField',
765                                                                         xns: Roo.form,
766                                                                         fieldLabel : 'Invoice Date',
767                                                                         format : 'Y-m-d',
768                                                                         name : 'cobmisc_invcdate',
769                                                                         width : 100
770                                                                     },
771                                                                     {
772                                                                         xtype: 'DateField',
773                                                                         xns: Roo.form,
774                                                                         fieldLabel : 'Shipment Date',
775                                                                         format : 'Y-m-d',
776                                                                         name : 'cobmisc_shipdate',
777                                                                         width : 100
778                                                                     }
779                                                                 ]
780                                                             },
781                                                             {
782                                                                 xtype: 'Row',
783                                                                 xns: Roo.form,
784                                                                 labelAlign : 'top',
785                                                                 items : [
786                                                                     {
787                                                                         xtype: 'TextArea',
788                                                                         xns: Roo.form,
789                                                                         fieldLabel : 'Notes',
790                                                                         height : 100,
791                                                                         name : 'cobmisc_notes',
792                                                                         width : 240
793                                                                     }
794                                                                 ]
795                                                             }
796                                                         ]
797                                                     },
798                                                     {
799                                                         xtype: 'Column',
800                                                         xns: Roo.form,
801                                                         labelAlign : 'left',
802                                                         style : 'margin-left:10px',
803                                                         width : 350,
804                                                         items : [
805                                                             {
806                                                                 xtype: 'FieldSet',
807                                                                 xns: Roo.form,
808                                                                 labelAlign : 'right',
809                                                                 labelWidth : 220,
810                                                                 legend : "Charges",
811                                                                 style : 'width:330px',
812                                                                 items : [
813                                                                     {
814                                                                         xtype: 'NumberField',
815                                                                         xns: Roo.form,
816                                                                         allowDecimals : true,
817                                                                         cls : 'roo-align-right',
818                                                                         decimalPrecision : 3,
819                                                                         fieldLabel : 'Item(s) Total',
820                                                                         name : 'cobmisc_itemcost',
821                                                                         readOnly : true,
822                                                                         width : 80
823                                                                     },
824                                                                     {
825                                                                         xtype: 'NumberField',
826                                                                         xns: Roo.form,
827                                                                         listeners : {
828                                                                             keyup : function (_self, e)
829                                                                             {
830                                                                                _this.form.recalc();
831                                                                             }
832                                                                         },
833                                                                         allowDecimals : true,
834                                                                         cls : 'roo-align-right',
835                                                                         decimalPrecision : 3,
836                                                                         fieldLabel : 'Shipping',
837                                                                         name : 'cobmisc_freight',
838                                                                         width : 80
839                                                                     },
840                                                                     {
841                                                                         xtype: 'NumberField',
842                                                                         xns: Roo.form,
843                                                                         allowDecimals : true,
844                                                                         cls : 'roo-align-right',
845                                                                         decimalPrecision : 3,
846                                                                         fieldLabel : 'Pre Tax discount:',
847                                                                         name : 'cobmisc_cohead_id_cohead_pretax_discount',
848                                                                         readOnly : true,
849                                                                         width : 80
850                                                                     },
851                                                                     {
852                                                                         xtype: 'Row',
853                                                                         xns: Roo.form,
854                                                                         labelAlign : 'top',
855                                                                         width : 430,
856                                                                         items : [
857                                                                             {
858                                                                                 xtype: 'TextField',
859                                                                                 xns: Roo.form,
860                                                                                 fieldLabel : 'Discount after Tax Description ',
861                                                                                 name : 'cobmisc_misc_descrip',
862                                                                                 width : 205
863                                                                             },
864                                                                             {
865                                                                                 xtype: 'NumberField',
866                                                                                 xns: Roo.form,
867                                                                                 listeners : {
868                                                                                     keyup : function (_self, e)
869                                                                                     {
870                                                                                        _this.form.recalc();
871                                                                                        _this.form.findField('cobmisc_misc').recalc();
872                                                                                     }
873                                                                                 },
874                                                                                 allowDecimals : true,
875                                                                                 cls : 'roo-align-right',
876                                                                                 decimalPrecision : 3,
877                                                                                 fieldLabel : 'Amount',
878                                                                                 name : 'cobmisc_posttax_discount',
879                                                                                 width : 80
880                                                                             }
881                                                                         ]
882                                                                     },
883                                                                     {
884                                                                         xtype: 'NumberField',
885                                                                         xns: Roo.form,
886                                                                         allowDecimals : true,
887                                                                         cls : 'roo-align-right',
888                                                                         decimalPrecision : 3,
889                                                                         fieldLabel : 'Tax',
890                                                                         name : 'cobmisc_total_tax',
891                                                                         readOnly : true,
892                                                                         width : 80
893                                                                     },
894                                                                     {
895                                                                         xtype: 'NumberField',
896                                                                         xns: Roo.form,
897                                                                         allowDecimals : true,
898                                                                         cls : 'roo-align-right',
899                                                                         decimalPrecision : 3,
900                                                                         fieldLabel : 'Credit Memos Applied',
901                                                                         name : 'cobmisc_cm_total',
902                                                                         readOnly : true,
903                                                                         width : 80
904                                                                     },
905                                                                     {
906                                                                         xtype: 'NumberField',
907                                                                         xns: Roo.form,
908                                                                         allowDecimals : true,
909                                                                         cls : 'roo-align-right',
910                                                                         decimalPrecision : 3,
911                                                                         fieldLabel : 'Total',
912                                                                         minValue : 0,
913                                                                         name : 'cobmisc_total',
914                                                                         readOnly : true,
915                                                                         width : 80
916                                                                     }
917                                                                 ]
918                                                             }
919                                                         ]
920                                                     }
921                                                 ]
922                                             },
923                                             {
924                                                 xtype: 'Hidden',
925                                                 xns: Roo.form,
926                                                 name : 'cobmisc_misc',
927                                                 recalc : function() {\r
928                                                     var d = _this.form.getValues();\r
929                                                     this.setValue( \r
930                                                         parseFloat(d.cobmisc_cohead_id_cohead_pretax_discount) + \r
931                                                         parseFloat(d.cobmisc_posttax_discount) );\r
932                                                 }
933                                             },
934                                             {
935                                                 xtype: 'Hidden',
936                                                 xns: Roo.form,
937                                                 name : 'cobmisc_cohead_id'
938                                             },
939                                             {
940                                                 xtype: 'Hidden',
941                                                 xns: Roo.form,
942                                                 name : 'cobmisc_id'
943                                             },
944                                             {
945                                                 xtype: 'Hidden',
946                                                 xns: Roo.form,
947                                                 name : 'cobapply_total'
948                                             },
949                                             {
950                                                 xtype: 'Hidden',
951                                                 xns: Roo.form,
952                                                 name : 'cobapply_list',
953                                                 update : function() {
954                                                    var ret = [];
955                                                    var val = 0.0;
956                                                    var count = 0;
957                                                     _this.cmgrid.ds.each(function(r) {
958                                                     
959                                                         if (r.data.toapply *  1)  {
960                                                             count = count + 1;
961                                                             ret.push(r.data.aropen_id);
962                                                             if (r.data.applied *1.0 > 0.0) {
963                                                                 val += parseFloat(r.data.applied);
964                                                                 return;
965                                                             }
966                                                 
967                                                             val += parseFloat(r.data.balance);
968                                                         }
969                                                     });
970                                                     
971                                                     var total  = (_this.form.findField('cobmisc_itemcost').getValue() * 1.0) +\r
972                                                                  ( _this.form.findField('cobmisc_freight').getValue() * 1.0)  + \r
973                                                          \r
974                                                                  ( _this.form.findField('cobmisc_cohead_id_cohead_pretax_discount').getValue() * 1.0)  + \r
975                                                                  ( _this.form.findField('cobmisc_posttax_discount').getValue() * 1.0)  + \r
976                                                                  ( _this.form.findField('cobmisc_total_tax').getValue() * 1.0)   \r
977                                                                  ;\r
978                                                 \r
979                                                     if(count > 1 && total < val){\r
980                                                         Roo.Msg.alert('Error', 'Credit memo total goes over the invoice total');\r
981                                                     }\r
982                                                     this.setValue(ret.join(','));
983                                                     _this.form.findField('cobmisc_cm_total').setValue( (val * -1).toFixed(2));
984                                                     _this.form.findField('cobapply_total').setValue( (val * -1).toFixed(2));
985                                                     _this.form.recalc();
986                                                 }
987                                             },
988                                             {
989                                                 xtype: 'Hidden',
990                                                 xns: Roo.form,
991                                                 name : 'billitems'
992                                             }
993                                         ]
994                                     }
995                                 ]
996                             }
997                         ],
998                         center : {
999                             xtype: 'LayoutRegion',
1000                             xns: Roo
1001                         },
1002                         east : {
1003                             xtype: 'LayoutRegion',
1004                             xns: Roo,
1005                             titlebar : true,
1006                             width : 250
1007                         }
1008                     }
1009                 },
1010                 {
1011                     xtype: 'GridPanel',
1012                     xns: Roo,
1013                     listeners : {
1014                         activate : function() {
1015                             _this.panel = this;
1016                             
1017                             if (_this.isBuilder) {
1018                                 return;
1019                             }
1020                             
1021                            
1022                             if (_this.grid) {
1023                                 _this.grid.ds.load({});
1024                             }
1025                         }
1026                     },
1027                     fitContainer : true,
1028                     fitToframe : true,
1029                     region : 'center',
1030                     tableName : 'coitem',
1031                     title : "Order Items",
1032                     grid : {
1033                         xtype: 'EditorGrid',
1034                         xns: Roo.grid,
1035                         listeners : {
1036                             render : function() 
1037                             {
1038                                 _this.grid = this; 
1039                                 //_this.dialog = Pman.Dialog.FILL_IN
1040                                 if (_this.panel.active) {
1041                                    this.ds.load({});
1042                                 }
1043                             },
1044                             rowdblclick : function (_self, rowIndex, e)
1045                             {
1046                                 
1047                             },
1048                             afteredit : function (e)
1049                             {
1050                                 //Roo.log('afteredit');
1051                                // Roo.log(e);
1052                                 if (e.field == 'item_number') {
1053                                     // afterselect handles this...
1054                                     return;
1055                                 }
1056                                 e.record.commit();
1057                             }
1058                         },
1059                         autoExpandColumn : 'item_descrip1',
1060                         clicksToEdit : 1,
1061                         loadMask : true,
1062                         sm : {
1063                             xtype: 'CellSelectionModel',
1064                             xns: Roo.grid,
1065                             enter_is_tab : true
1066                         },
1067                         dataSource : {
1068                             xtype: 'Store',
1069                             xns: Roo.data,
1070                             listeners : {
1071                                 beforeload : function (_self,o) {
1072                                     if (! _this.form.findField('cobmisc_cohead_id').getValue()) {
1073                                         return false;
1074                                     }
1075                                     o.params = o.params || {};
1076                                     
1077                                     o.params.coitem_cohead_id = _this.form.findField('cobmisc_cohead_id').getValue();
1078                                     o.params.limit = 999;
1079                                     o.params.cobmisc_id = _this.form.findField('cobmisc_id').getValue();
1080                                     
1081                                 },
1082                                 load : function (_self, records, options)
1083                                 {
1084                                    (function() { _this.form.recalc(); }).defer(100);
1085                                    _this.cmgrid.ds.load({});
1086                                 },
1087                                 update : function (_self, record, operation)
1088                                 {
1089                                   _this.form.recalc();
1090                                 }
1091                             },
1092                             remoteSort : true,
1093                             sortInfo : { field : 'coitem_linenumber', direction: 'ASC' },
1094                             proxy : {
1095                                 xtype: 'HttpProxy',
1096                                 xns: Roo.data,
1097                                 method : 'GET',
1098                                 url : baseURL + '/Roo/coitem.php'
1099                             },
1100                             reader : {
1101                                 xtype: 'JsonReader',
1102                                 xns: Roo.data,
1103                                 totalProperty : 'total',
1104                                 root : 'data',
1105                                 id : 'id',
1106                                 fields : [
1107                                     {
1108                                         'name': 'coitem_linenumber',
1109                                         'type': 'int'
1110                                     },
1111                                     {
1112                                         'name': 'coitem_itemsite_id',
1113                                         'type': 'int'
1114                                     },
1115                                     {
1116                                         'name': 'coitem_qtyord'
1117                                     },
1118                                     {
1119                                         'name': 'coitem_unitcost'
1120                                     },
1121                                     {
1122                                         'name': 'coitem_price'
1123                                     },
1124                                     {
1125                                         'name': 'coitem_custprice'
1126                                     },
1127                                     {
1128                                         'name': 'coitem_qtyreturned'
1129                                     },
1130                                     {
1131                                         'name': 'coitem_prcost'
1132                                     },
1133                                     {
1134                                         'name': 'coitem_price_uom_id',
1135                                         'type': 'int'
1136                                     },
1137                                     {
1138                                         'name': 'coitem_qtyreserved'
1139                                     }
1140                                 ]
1141                             }
1142                         },
1143                         toolbar : {
1144                             xtype: 'Toolbar',
1145                             xns: Roo,
1146                             items : [
1147                                 {
1148                                     xtype: 'Button',
1149                                     xns: Roo.Toolbar,
1150                                     listeners : {
1151                                         click : function (_self, e)
1152                                         {
1153                                             _this.grid.ds.each(function(r) {
1154                                                 r.set('cobill_qty', Math.max(0, r.data.coitem_qtyord - r.data.cobill_billed));
1155                                             });
1156                                         }
1157                                     },
1158                                     text : "Invoice all"
1159                                 },
1160                                 {
1161                                     xtype: 'TextItem',
1162                                     xns: Roo.Toolbar,
1163                                     text : "Restore from : "
1164                                 },
1165                                 {
1166                                     xtype: 'ComboBox',
1167                                     xns: Roo.form,
1168                                     listeners : {
1169                                         select : function (combo, record, index)
1170                                         {
1171                                           //_this.grid.footer.onClick('first');
1172                                           
1173                                            (function() { 
1174                                             combo.setValue('');
1175                                            }).defer(100);
1176                                            var data = record.json.data;
1177                                            
1178                                            _this.grid.ds.each(function (r) {
1179                                                 if (typeof(data[r.data.coitem_itemsite_id+'']) == 'undefined') {
1180                                                     return;
1181                                                 }
1182                                                 r.set('cobill_qty', parseInt(data[r.data.coitem_itemsite_id+'']));
1183                                            
1184                                            });
1185                                            
1186                                            
1187                                            
1188                                           
1189                                         }
1190                                     },
1191                                     allowBlank : true,
1192                                     displayField : 'name',
1193                                     editable : false,
1194                                     emptyText : "Restore from",
1195                                     forceSelection : true,
1196                                     listWidth : 300,
1197                                     loadingText : "Searching...",
1198                                     name : 'name',
1199                                     pageSize : 20,
1200                                     qtip : "Select Action",
1201                                     queryParam : 'query[action]',
1202                                     selectOnFocus : true,
1203                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
1204                                     triggerAction : 'all',
1205                                     typeAhead : true,
1206                                     valueField : 'name',
1207                                     width : 300,
1208                                     store : {
1209                                         xtype: 'Store',
1210                                         xns: Roo.data,
1211                                         listeners : {
1212                                             beforeload : function (_self, o)
1213                                             {
1214                                                 o.params = o.params || {};
1215                                                 // staff can see all logs, other companies can only see their own.
1216                                                  
1217                                                 o.params._stash = _this.form.findField('cobmisc_cohead_id').getValue();
1218                                             
1219                                             }
1220                                         },
1221                                         remoteSort : true,
1222                                         sortInfo : { field : 'action' , direction : 'ASC' },
1223                                         proxy : {
1224                                             xtype: 'HttpProxy',
1225                                             xns: Roo.data,
1226                                             method : 'GET',
1227                                             url : baseURL + '/Roo/Cobmisc.php'
1228                                         },
1229                                         reader : {
1230                                             xtype: 'JsonReader',
1231                                             xns: Roo.data,
1232                                             id : 'name',
1233                                             root : 'data',
1234                                             totalProperty : 'total',
1235                                             fields : [
1236                                                 {
1237                                                     'name': 'name',
1238                                                     'type': 'string'
1239                                                 }
1240                                              
1241                                             ]
1242                                         }
1243                                     }
1244                                 },
1245                                 {
1246                                     xtype: 'Fill',
1247                                     xns: Roo.Toolbar
1248                                 },
1249                                 {
1250                                     xtype: 'Button',
1251                                     xns: Roo.Toolbar,
1252                                     listeners : {
1253                                         click : function()
1254                                         {
1255                                              _this.grid.ds.each(function(r) {
1256                                                 r.set('cobill_qty', 0);
1257                                             });
1258                                         }
1259                                     },
1260                                     text : "Reset"
1261                                 }
1262                             ]
1263                         },
1264                         colModel : [
1265                             {
1266                                 xtype: 'ColumnModel',
1267                                 xns: Roo.grid,
1268                                 header : 'Item#',
1269                                 width : 75,
1270                                 dataIndex : 'coitem_linenumber',
1271                                 renderer : function(v) { return String.format('{0}', v); }
1272                             },
1273                             {
1274                                 xtype: 'ColumnModel',
1275                                 xns: Roo.grid,
1276                                 header : 'Item Code',
1277                                 width : 75,
1278                                 dataIndex : 'item_number',
1279                                 renderer : function(v) { return String.format('{0}', v); }
1280                             },
1281                             {
1282                                 xtype: 'ColumnModel',
1283                                 xns: Roo.grid,
1284                                 dataIndex : 'item_descrip1',
1285                                 header : 'Item Description',
1286                                 width : '150.00',
1287                                 renderer : function(v, x, r) {
1288                                 
1289                                     var vv = v;
1290                                     if (r.data.coitem_memo && r.data.coitem_memo.length) {
1291                                         vv = r.data.coitem_memo;
1292                                     }
1293                                     return String.format('{0}', vv); 
1294                                  
1295                                  }
1296                             },
1297                             {
1298                                 xtype: 'ColumnModel',
1299                                 xns: Roo.grid,
1300                                 align : 'right',
1301                                 dataIndex : 'coitem_custprice',
1302                                 header : 'List Price',
1303                                 width : 80,
1304                                 renderer : function(v) { return String.format('{0}', (v *1.0).toFixed(2)); }
1305                             },
1306                             {
1307                                 xtype: 'ColumnModel',
1308                                 xns: Roo.grid,
1309                                 align : 'right',
1310                                 dataIndex : 'coitem_price',
1311                                 header : 'Sell @',
1312                                 width : 80,
1313                                 renderer : function(v) { return String.format('{0}', (v *1.0).toFixed(2)); }
1314                             },
1315                             {
1316                                 xtype: 'ColumnModel',
1317                                 xns: Roo.grid,
1318                                 align : 'right',
1319                                 dataIndex : 'calc_tax',
1320                                 header : 'Tax',
1321                                 width : 80,
1322                                 renderer : function(v) { return String.format('{0}', (v *1.0).toFixed(2)); }
1323                             },
1324                             {
1325                                 xtype: 'ColumnModel',
1326                                 xns: Roo.grid,
1327                                 align : 'right',
1328                                 dataIndex : 'coitem_qtyord',
1329                                 header : 'Ordered Qty',
1330                                 width : 70,
1331                                 renderer : function(v) { return String.format('{0}', v); }
1332                             },
1333                             {
1334                                 xtype: 'ColumnModel',
1335                                 xns: Roo.grid,
1336                                 align : 'right',
1337                                 dataIndex : 'cobill_billed',
1338                                 header : 'Not Billed Qty',
1339                                 width : 70,
1340                                 renderer : function(v,x,r) {
1341                                 
1342                                      Roo.log(v);
1343                                      return String.format('{0}', r.data.coitem_qtyord - v); 
1344                                  }
1345                             },
1346                             {
1347                                 xtype: 'ColumnModel',
1348                                 xns: Roo.grid,
1349                                 align : 'right',
1350                                 dataIndex : 'cobill_qty',
1351                                 header : 'Bill Qty',
1352                                 width : 100,
1353                                 renderer : function(v,x,r) { 
1354                                     
1355                                     var vv = parseInt(v);
1356                                     vv = isNaN(vv) ? 0 : vv;
1357                                     r.data.cobill_qty = vv; // get rid of decimal.
1358                                     if (r.data.cobill_billed + vv > r.data.coitem_qtyord) {
1359                                             return String.format('<b style="background-color:red;color:yellow">{0}</b>', vv); 
1360                                     }
1361                                     // not fully fullfilled
1362                                     if (r.data.cobill_billed + vv != r.data.coitem_qtyord) {
1363                                             return String.format('<b style="background-color:blue;color:yellow">{0}</b>', vv); 
1364                                     }   
1365                                     return String.format('{0}', vv); 
1366                                     
1367                                 },
1368                                 editor : {
1369                                     xtype: 'GridEditor',
1370                                     xns: Roo.grid,
1371                                     field : {
1372                                         xtype: 'NumberField',
1373                                         xns: Roo.form,
1374                                         allowDecimals : true,
1375                                         decimalPrecision : 0,
1376                                         minValue : 0,
1377                                         style : 'text-align:right'
1378                                     }
1379                                 }
1380                             }
1381                         ]
1382                     }
1383                 }
1384             ],
1385             center : {
1386                 xtype: 'LayoutRegion',
1387                 xns: Roo
1388             },
1389             north : {
1390                 xtype: 'LayoutRegion',
1391                 xns: Roo,
1392                 height : 270
1393             },
1394             buttons : [
1395                 {
1396                     xtype: 'Button',
1397                     xns: Roo,
1398                     listeners : {
1399                         click : function (_self, e)
1400                         {
1401                             _this.dialog.hide();
1402                         }
1403                     },
1404                     text : "Cancel"
1405                 },
1406                 {
1407                     xtype: 'Button',
1408                     xns: Roo,
1409                     listeners : {
1410                         click : function (_self, e)
1411                         {
1412                             var hasListDiscount = false;
1413                             var orderQty = 0;
1414                             var billQty = 0;
1415                             
1416                             var ar = [];
1417                             _this.grid.ds.each(function(r) {
1418                                 if(r.data.item_number == 'Z-LIST-DISCOUNT'){
1419                                     hasListDiscount = true;
1420                                 }
1421                                 orderQty += r.data.coitem_qtyord;
1422                                 billQty += r.data.cobill_qty;
1423                                 
1424                                 ar.push({
1425                                     cobill_coitem_id : r.data.coitem_id,
1426                                     cobill_qty : r.data.cobill_qty 
1427                                 });
1428                             });
1429                             var doSubmit = function(){
1430                                 _this.form.findField('billitems').setValue(JSON.stringify(ar));
1431                                 _this.form.doAction("submit");   
1432                             
1433                             }
1434                             if(hasListDiscount && orderQty != billQty){
1435                                 Roo.MessageBox.confirm("Confirm", "This Invoice contains a pre-tax discount - you can still invoice the customer however the calculations for discount will be inaccurate.",
1436                                     function (res) {
1437                                         if(res!='yes') {
1438                                             return;
1439                                         }
1440                                         doSubmit();
1441                                  });
1442                                  return;
1443                              }
1444                              
1445                             doSubmit();
1446                         
1447                         },
1448                         render : function (_self)
1449                         {
1450                          _this.saveBtn = _self;
1451                         }
1452                     },
1453                     text : "Save"
1454                 }
1455             ]
1456         });
1457     }
1458 };