Pman.Tab.XtupleCreditMemos.bjs
[Pman.Xtuple] / Pman.Tab.XtupleCreditMemos.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.Tab.XtupleCreditMemos = new Roo.XComponent({
6     part     :  ["Xtuple","CreditMemos"],
7     order    : '200-Pman.Tab.XtupleCreditMemos',
8     region   : 'center',
9     parent   : 'Pman.Tab.XtupleSales',
10     name     : "Pman.Tab.XtupleCreditMemos",
11     disabled : false, 
12     permname : '', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'GridPanel',
19             xns: Roo,
20             listeners : {
21                 activate : function() {
22                     _this.panel = this;
23                     if (_this.grid) {
24                         _this.grid.footer.onClick('first');
25                     }
26                 }
27             },
28             background : true,
29             fitContainer : true,
30             fitToframe : true,
31             region : 'center',
32             tableName : 'cmhead',
33             title : "Credit Memos",
34             grid : {
35                 xtype: 'Grid',
36                 xns: Roo.grid,
37                 listeners : {
38                     render : function() 
39                     {
40                         _this.grid = this; 
41                         //_this.dialog = Pman.Dialog.FILL_IN
42                         if (_this.panel.active) {
43                            this.footer.onClick('first');
44                         }
45                     },
46                     rowdblclick : function (_self, rowIndex, e)
47                     {
48                         var s = this.dataSource.getAt(rowIndex);
49                         Pman.Dialog.XtupleCreditMemo.show({
50                             cmhead_id : s.data.cmhead_id
51                         },function() {
52                             _this.grid.footer.onClick('first');
53                         
54                         });
55                     /*    if (!_this.dialog) return;
56                         _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
57                             _this.grid.footer.onClick('first');
58                         }); */
59                     }
60                 },
61                 autoExpandColumn : 'cmhead_cust_id_cust_name',
62                 loadMask : true,
63                 dataSource : {
64                     xtype: 'Store',
65                     xns: Roo.data,
66                     listeners : {
67                         beforeload : function (_self, o)
68                         {
69                             if ( _this.customer &&  _this.customer.getValue() ) {
70                                o.params.cmhead_cust_id = _this.customer.getValue();
71                             }
72                             if (_this.cmnumber && _this.cmnumber.getValue() ) {
73                                o.params.cmhead_id =  _this.cmnumber.getValue();
74                             }
75                             if (_this.status) { 
76                                 o.params['query[status]'] = _this.status.getValue();
77                             }
78                             
79                             o.params._with_aropen = 1;
80                         }
81                     },
82                     remoteSort : true,
83                     sortInfo : { field : 'cmhead_id', direction: 'DESC' },
84                     proxy : {
85                         xtype: 'HttpProxy',
86                         xns: Roo.data,
87                         method : 'GET',
88                         url : baseURL + '/Roo/cmhead.php'
89                     },
90                     reader : {
91                         xtype: 'JsonReader',
92                         xns: Roo.data,
93                         totalProperty : 'total',
94                         root : 'data',
95                         id : 'id',
96                         fields : [
97                             {
98                                 'name': 'cmhead_id',
99                                 'type': 'int'
100                             },
101                             {
102                                 'name': 'cmhead_number',
103                                 'type': 'string'
104                             },
105                             {
106                                 'name': 'cmhead_posted',
107                                 'type': 'int'
108                             },
109                             {
110                                 'name': 'cmhead_invcnumber',
111                                 'type': 'string'
112                             },
113                             {
114                                 'name': 'cmhead_custponumber',
115                                 'type': 'string'
116                             },
117                             {
118                                 'name': 'cmhead_cust_id',
119                                 'type': 'int'
120                             },
121                             {
122                                 'name': 'cmhead_docdate',
123                                 'type': 'date',
124                                 'dateFormat': 'Y-m-d'
125                             },
126                             {
127                                 'name': 'cmhead_shipto_id',
128                                 'type': 'int'
129                             },
130                             {
131                                 'name': 'cmhead_shipto_name',
132                                 'type': 'string'
133                             },
134                             {
135                                 'name': 'cmhead_shipto_address1',
136                                 'type': 'string'
137                             },
138                             {
139                                 'name': 'cmhead_shipto_address2',
140                                 'type': 'string'
141                             },
142                             {
143                                 'name': 'cmhead_shipto_address3',
144                                 'type': 'string'
145                             },
146                             {
147                                 'name': 'cmhead_shipto_city',
148                                 'type': 'string'
149                             },
150                             {
151                                 'name': 'cmhead_shipto_state',
152                                 'type': 'string'
153                             },
154                             {
155                                 'name': 'cmhead_shipto_zipcode',
156                                 'type': 'string'
157                             },
158                             {
159                                 'name': 'cmhead_salesrep_id',
160                                 'type': 'int'
161                             },
162                             {
163                                 'name': 'cmhead_freight',
164                                 'type': 'float'
165                             },
166                             {
167                                 'name': 'cmhead_misc',
168                                 'type': 'float'
169                             },
170                             {
171                                 'name': 'cmhead_comments',
172                                 'type': 'string'
173                             },
174                             {
175                                 'name': 'cmhead_printed',
176                                 'type': 'int'
177                             },
178                             {
179                                 'name': 'cmhead_billtoname',
180                                 'type': 'string'
181                             },
182                             {
183                                 'name': 'cmhead_billtoaddress1',
184                                 'type': 'string'
185                             },
186                             {
187                                 'name': 'cmhead_billtoaddress2',
188                                 'type': 'string'
189                             },
190                             {
191                                 'name': 'cmhead_billtoaddress3',
192                                 'type': 'string'
193                             },
194                             {
195                                 'name': 'cmhead_billtocity',
196                                 'type': 'string'
197                             },
198                             {
199                                 'name': 'cmhead_billtostate',
200                                 'type': 'string'
201                             },
202                             {
203                                 'name': 'cmhead_billtozip',
204                                 'type': 'string'
205                             },
206                             {
207                                 'name': 'cmhead_hold',
208                                 'type': 'int'
209                             },
210                             {
211                                 'name': 'cmhead_commission',
212                                 'type': 'float'
213                             },
214                             {
215                                 'name': 'cmhead_misc_accnt_id',
216                                 'type': 'int'
217                             },
218                             {
219                                 'name': 'cmhead_misc_descrip',
220                                 'type': 'string'
221                             },
222                             {
223                                 'name': 'cmhead_rsncode_id',
224                                 'type': 'int'
225                             },
226                             {
227                                 'name': 'cmhead_curr_id',
228                                 'type': 'int'
229                             },
230                             {
231                                 'name': 'cmhead_freighttaxtype_id',
232                                 'type': 'int'
233                             },
234                             {
235                                 'name': 'cmhead_gldistdate',
236                                 'type': 'date',
237                                 'dateFormat': 'Y-m-d'
238                             },
239                             {
240                                 'name': 'cmhead_billtocountry',
241                                 'type': 'string'
242                             },
243                             {
244                                 'name': 'cmhead_shipto_country',
245                                 'type': 'string'
246                             },
247                             {
248                                 'name': 'cmhead_rahead_id',
249                                 'type': 'int'
250                             },
251                             {
252                                 'name': 'cmhead_taxzone_id',
253                                 'type': 'int'
254                             },
255                             {
256                                 'name': 'cmhead_prj_id',
257                                 'type': 'int'
258                             }
259                         ]
260                     }
261                 },
262                 footer : {
263                     xtype: 'PagingToolbar',
264                     xns: Roo,
265                     pageSize : 25,
266                     displayInfo : true,
267                     displayMsg : "Displaying cmhead{0} - {1} of {2}",
268                     emptyMsg : "No cmhead found",
269                     items : [
270                         {
271                             xtype: 'Button',
272                             xns: Roo.Toolbar,
273                             listeners : {
274                                 click : function (_self, e)
275                                 {
276                                  new Pman.Download({
277                                         grid : _this.grid
278                                     });
279                                     Roo.MessageBox.alert("Notice", "Report is downloading");
280                                 }
281                             },
282                             text : "Download"
283                         }
284                     ]
285                 },
286                 toolbar : {
287                     xtype: 'Toolbar',
288                     xns: Roo,
289                     items : [
290                         {
291                             xtype: 'ComboBox',
292                             xns: Roo.form,
293                             listeners : {
294                                 render : function (_self)
295                                 {
296                                     _this.cmnumber = _self;
297                                 },
298                                 select : function (combo, record, index)
299                                 {
300                                     Roo.log('select');
301                                     _this.grid.footer.onClick('first');
302                                 }
303                             },
304                             allowBlank : true,
305                             displayField : 'cmhead_number',
306                             editable : true,
307                             emptyText : "Order",
308                             fieldLabel : 'ordernumber',
309                             forceSelection : true,
310                             hiddenName : 'cmhead_id',
311                             listWidth : 400,
312                             loadingText : "Searching...",
313                             minChars : 2,
314                             name : 'cmhead_number',
315                             pageSize : 20,
316                             qtip : "Select invchead",
317                             queryParam : 'query[cmhead_number]',
318                             selectOnFocus : true,
319                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{cmhead_number}</b> </div>',
320                             triggerAction : 'all',
321                             typeAhead : false,
322                             valueField : 'cmhead_id',
323                             width : 150,
324                             store : {
325                                 xtype: 'Store',
326                                 xns: Roo.data,
327                                 listeners : {
328                                     beforeload : function (_self, o){
329                                         o.params = o.params || {};
330                                         // set more here
331                                     }
332                                 },
333                                 remoteSort : true,
334                                 sortInfo : { direction : 'ASC', field: 'cmhead_number' },
335                                 proxy : {
336                                     xtype: 'HttpProxy',
337                                     xns: Roo.data,
338                                     method : 'GET',
339                                     url : baseURL + '/Roo/cmhead.php'
340                                 },
341                                 reader : {
342                                     xtype: 'JsonReader',
343                                     xns: Roo.data,
344                                     id : 'cmhead_id',
345                                     root : 'data',
346                                     totalProperty : 'total',
347                                     fields : [{"name":"cmhead_id","type":"int"},"cmhead_number"]
348                                 }
349                             }
350                         },
351                         {
352                             xtype: 'ComboBox',
353                             xns: Roo.form,
354                             listeners : {
355                                 render : function (_self)
356                                 {
357                                     _this.customer = _self;
358                                 },
359                                 select : function (combo, record, index)
360                                 {
361                                     _this.grid.footer.onClick('first');
362                                 }
363                             },
364                             allowBlank : true,
365                             displayField : 'cust_name',
366                             editable : true,
367                             emptyText : "Select Customer",
368                             fieldLabel : 'cust_name',
369                             forceSelection : true,
370                             hiddenName : 'cust_id',
371                             listWidth : 400,
372                             loadingText : "Searching...",
373                             minChars : 2,
374                             name : 'cust_name',
375                             pageSize : 20,
376                             qtip : "Select custinfo",
377                             queryParam : 'query[cust_name]',
378                             selectOnFocus : true,
379                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{cust_name}</b> </div>',
380                             triggerAction : 'all',
381                             typeAhead : false,
382                             valueField : 'cust_id',
383                             width : 200,
384                             store : {
385                                 xtype: 'Store',
386                                 xns: Roo.data,
387                                 sortInfo : { direction : 'ASC', field: 'cust_name' },
388                                 remoteSort : true,
389                                 listeners : {
390                                     beforeload : function (_self, o){
391                                         o.params = o.params || {};
392                                         // set more here
393                                     }
394                                 },
395                                 proxy : {
396                                     xtype: 'HttpProxy',
397                                     xns: Roo.data,
398                                     method : 'GET',
399                                     url : baseURL + '/Roo/custinfo.php'
400                                 },
401                                 reader : {
402                                     xtype: 'JsonReader',
403                                     xns: Roo.data,
404                                     id : 'cust_id',
405                                     root : 'data',
406                                     totalProperty : 'total',
407                                     fields : [{"name":"cust_id","type":"int"},"cust_name"]
408                                 }
409                             }
410                         },
411                         {
412                             xtype: 'ComboBox',
413                             xns: Roo.form,
414                             listeners : {
415                                 render : function (_self)
416                                 {
417                                   _this.status = _self;
418                                 },
419                                 select : function (combo, record, index)
420                                 {
421                                     Roo.log('select');
422                                     _this.grid.footer.onClick('first');
423                                 }
424                             },
425                             allowBlank : false,
426                             displayField : 'fname',
427                             editable : false,
428                             fieldLabel : 'Status',
429                             hiddenName : 'cm_status',
430                             listWidth : 200,
431                             mode : 'local',
432                             name : 'cm_status_name',
433                             triggerAction : 'all',
434                             value : "NOTCLOSED",
435                             valueField : 'ftype',
436                             width : 150,
437                             store : {
438                                 xtype: 'SimpleStore',
439                                 xns: Roo.data,
440                                 data : [ 
441                                     [ 'NOTCLOSED', "Not Closed"],
442                                     [ 'CLOSED' , "Closed"],
443                                     [ 'UNPOSTED', "Unposted only"] ,
444                                     [ 'UNUSED', "Posted and not used"] ,
445                                     [ 'VOIDED', "Voided"],
446                                     [ 'NOTVOIDED', "Not Voided"]
447                                 ],
448                                 fields : [  'ftype', 'fname']
449                             }
450                         },
451                         {
452                             xtype: 'Fill',
453                             xns: Roo.Toolbar
454                         },
455                         {
456                             xtype: 'Button',
457                             xns: Roo.Toolbar,
458                             cls : 'x-btn-text-icon',
459                             text : "Add",
460                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
461                             menu : {
462                                 xtype: 'Menu',
463                                 xns: Roo.menu,
464                                 items : [
465                                     {
466                                         xtype: 'Item',
467                                         xns: Roo.menu,
468                                         listeners : {
469                                             click : function (_self, e)
470                                             {
471                                                Pman.Dialog.XtupleCreditMemoNew.show( {} , function() {
472                                                     _this.grid.footer.onClick('first');
473                                                }); 
474                                             
475                                             }
476                                         },
477                                         cls : 'x-btn-text-icon',
478                                         text : "New Credit Memo",
479                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
480                                     },
481                                     {
482                                         xtype: 'Separator',
483                                         xns: Roo.menu
484                                     },
485                                     {
486                                         xtype: 'Item',
487                                         xns: Roo.menu,
488                                         listeners : {
489                                             click : function (_self, e)
490                                             {
491                                                var s = _this.grid.getSelectionModel().getSelections();
492                                             
493                                                 if (!s.length || (s.length > 1))  {
494                                                     Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
495                                                     return;
496                                                 }    
497                                                 if(s[0].data.checkhead_total == 0){
498                                                     Roo.MessageBox.alert("Error", "you cannot create the miscellaneous check for the credit memo coz the total amount remaining is 0! ");
499                                                     return;
500                                                 }
501                                                 if(!s[0].data.cmhead_posted){
502                                                     Roo.MessageBox.alert("Error", "This credit memo  has not been posted!");
503                                                     return;
504                                                 }
505                                                 var data = {
506                                                     'checkhead_recip_id' : s[0].data.cmhead_cust_id,
507                                                     'checkhead_recip_type' : 'C',
508                                                     'checkhead_checkdate' : new Date(),
509                                                     'checkhead_amount' : s[0].data.checkhead_total,
510                                                     'remaining_total' : s[0].data.checkhead_total,
511                                                     'checkhead_curr_id' : s[0].data.cmhead_curr_id,
512                                                     'checkhead_curr_id_curr_name' : s[0].data.cmhead_curr_id_curr_name,
513                                                     'checkhead_misc' : true,
514                                                     'aropen_id' : s[0].data.cmhead_aropen_id_aropen_id,
515                                                         'cmhead_number' : s[0].data.cmhead_number,
516                                                 'cust_name' : s[0].data.cmhead_cust_id_cust_name,
517                                                 '_create_and_post' : 1
518                                             
519                                                 };
520                                                 
521                                                 
522                                                 Pman.Dialog.XtupleMiscellaneousCheck.show( data , function() {
523                                                     _this.grid.footer.onClick('first');
524                                                }); 
525                                             
526                                             }
527                                         },
528                                         cls : 'x-btn-text-icon',
529                                         text : "New Miscellaneous Check",
530                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
531                                     }
532                                 ]
533                             }
534                         },
535                         {
536                             xtype: 'Separator',
537                             xns: Roo.Toolbar
538                         },
539                         {
540                             xtype: 'Button',
541                             xns: Roo.Toolbar,
542                             listeners : {
543                                 click : function()
544                                 {
545                                     var s = _this.grid.getSelectionModel().getSelections();
546                                 
547                                     if (!s.length || (s.length > 1))  {
548                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
549                                         return;
550                                     }
551                                 
552                                     var postit = function()
553                                     {
554                                         new Pman.Request(
555                                         {
556                                             url : baseURL + '/Roo/Cmhead',
557                                             mask: 'Voiding',
558                                             method : 'POST',
559                                             params : {
560                                                 cmhead_id : s[0].data.cmhead_id,
561                                                 _void : 1
562                                             },
563                                             success : function()
564                                             {
565                                                 _this.grid.footer.onClick('refresh');
566                                             } 
567                                         });
568                                     
569                                     };
570                                 
571                                 
572                                     Roo.MessageBox.confirm(
573                                         "Confirm",
574                                         "Are you sure to void this credit memo?",
575                                         function(r) {
576                                             if (r != 'yes') {
577                                                 return;
578                                             }
579                                             postit();
580                                         }
581                                     );
582                                     
583                                 }
584                             },
585                             cls : 'x-btn-text-icon',
586                             text : "Void Credit Memo",
587                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
588                         },
589                         {
590                             xtype: 'Separator',
591                             xns: Roo.Toolbar
592                         },
593                         {
594                             xtype: 'Button',
595                             xns: Roo.Toolbar,
596                             listeners : {
597                                 click : function()
598                                 {
599                                     var s = _this.grid.getSelectionModel().getSelections();
600                                 
601                                     if (!s.length || (s.length > 1))  {
602                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
603                                         return;
604                                     }
605                                     if (s[0].data.cmhead_posted ) { 
606                                         Roo.MessageBox.alert("Error", 
607                                             "You can not delete posted credit memo's - you have to create an invoice to reverse them");
608                                         return;
609                                     }
610                                     
611                                     
612                                 
613                                     var postit = function()
614                                     {
615                                         new Pman.Request(
616                                         {
617                                             url : baseURL + '/Roo/Cmhead',
618                                             mask: 'Deleting',
619                                             method : 'POST',
620                                             params : {
621                                                 _delete  : s[0].data.cmhead_id 
622                                             },
623                                             success : function()
624                                             {
625                                                 _this.grid.footer.onClick('refresh');
626                                             } 
627                                         });
628                                     
629                                     };
630                                 
631                                 
632                                     Roo.MessageBox.confirm(
633                                         "Confirm Deletion",
634                                         "You will have to make sure this credit memo has no line items associated before deleting it. ",
635                                         function(r) {
636                                             if (r != 'yes') {
637                                                 return;
638                                             }
639                                             postit();
640                                         }
641                                     );
642                                     
643                                 }
644                             },
645                             cls : 'x-btn-text-icon',
646                             text : "Delete Credit Memo",
647                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
648                         },
649                         {
650                             xtype: 'Separator',
651                             xns: Roo.Toolbar
652                         },
653                         {
654                             xtype: 'Button',
655                             xns: Roo.Toolbar,
656                             listeners : {
657                                 click : function()
658                                 {
659                                     var s = _this.grid.getSelectionModel().getSelections();
660                                 
661                                     if (!s.length || (s.length > 1))  {
662                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
663                                         return;
664                                     }
665                                 
666                                     var postit = function()
667                                     {
668                                         new Pman.Request(
669                                         {
670                                             url : baseURL + '/Roo/Cmhead',
671                                             mask: 'Posting',
672                                             method : 'POST',
673                                             params : {
674                                                 cmhead_id : s[0].data.cmhead_id,
675                                                 _post : 1
676                                             },
677                                             success : function()
678                                             {
679                                                 _this.grid.footer.onClick('refresh');
680                                             } 
681                                         });
682                                     
683                                     };
684                                 
685                                 
686                                     Roo.MessageBox.confirm(
687                                         "Confirm Posting",
688                                         "Are you sure that is complete, <B>Voiding a Credit memo invoices creating a sales order and invoice</B>, so make sure this is correct before posting",
689                                         function(r) {
690                                             if (r != 'yes') {
691                                                 return;
692                                             }
693                                             postit();
694                                         }
695                                     ); 
696                                     
697                                 }
698                             },
699                             cls : 'x-btn-text-icon',
700                             text : "POST",
701                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
702                         },
703                         {
704                             xtype: 'Separator',
705                             xns: Roo.Toolbar
706                         },
707                         {
708                             xtype: 'Button',
709                             xns: Roo.Toolbar,
710                             listeners : {
711                                 click : function ()
712                                 {
713                                     var s = _this.grid.getSelectionModel().getSelected();
714                                       if (!s || !s.data.cmhead_id) {
715                                         Roo.MessageBox.alert("Error", "Select a credit memo");
716                                         return
717                                       }
718                                       
719                                       var ext = baseURL.split('/').pop().replace(/\.php/, '');
720                                       new Pman.Download({
721                                         url : baseURL + '/Xtuple/Print',
722                                         params :  {
723                                             template: 'creditmemo-' + ext,
724                                             filename : 'creditmemo-' + s.data.cmhead_id,
725                                             'param[0]':   "cmhead_id:string='" + s.data.cmhead_id + "'"
726                                            
727                                         },
728                                         method : 'GET'
729                                      });
730                                      Roo.MessageBox.alert("Notice", "Report will download shortly");
731                                             
732                                             
733                                    
734                                 }
735                             },
736                             cls : 'x-btn-text-icon',
737                             text : "Print",
738                             icon : rootURL + '/Pman/templates/images/pdf.gif'
739                         },
740                         {
741                             xtype: 'Separator',
742                             xns: Roo.Toolbar
743                         },
744                         {
745                             xtype: 'Button',
746                             xns: Roo.Toolbar,
747                             cls : 'x-btn-text-icon',
748                             text : "Tools",
749                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
750                             menu : {
751                                 xtype: 'Menu',
752                                 xns: Roo.menu,
753                                 items : [
754                                     {
755                                         xtype: 'Separator',
756                                         xns: Roo.menu
757                                     },
758                                     {
759                                         xtype: 'Item',
760                                         xns: Roo.menu,
761                                         listeners : {
762                                             click : function (_self, e)
763                                             {
764                                                Roo.MessageBox.confirm(
765                                                     "Confirm",
766                                                     "It is going to fill in all the blank return stock. Are you sure?",
767                                                     function(r) {
768                                                         if (r != 'yes') {
769                                                             return;
770                                                         }
771                                                         new Pman.Request(
772                                                         {
773                                                             url : baseURL + '/Roo/Cmhead',
774                                                             mask: 'Processing',
775                                                             method : 'POST',
776                                                             params : {
777                                                                 _fix_stock : 1
778                                                             },
779                                                             success : function()
780                                                             {
781                                                                 Roo.MessageBox.alert('Notice','Fixed');
782                                                                 _this.grid.footer.onClick('refresh');
783                                                             } 
784                                                         });
785                                                     }
786                                                 ); 
787                                             }
788                                         },
789                                         cls : 'x-btn-text-icon',
790                                         text : "Fix Blank Return Stock",
791                                         icon : Roo.rootURL + 'images/default/tree/leaf.gif'
792                                     }
793                                 ]
794                             }
795                         }
796                     ]
797                 },
798                 colModel : [
799                     {
800                         xtype: 'ColumnModel',
801                         xns: Roo.grid,
802                         dataIndex : 'cmhead_number',
803                         header : 'Ref #',
804                         sortable : true,
805                         width : 150,
806                         renderer : function(v) { return String.format('{0}', v); }
807                     },
808                     {
809                         xtype: 'ColumnModel',
810                         xns: Roo.grid,
811                         dataIndex : 'cmhead_docdate',
812                         header : 'Date',
813                         sortable : true,
814                         width : 100,
815                         renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
816                     },
817                     {
818                         xtype: 'ColumnModel',
819                         xns: Roo.grid,
820                         dataIndex : 'cmhead_salesrep_id_salesrep_name',
821                         header : 'Sales Rep',
822                         sortable : true,
823                         width : 100,
824                         renderer : function(v) { return String.format('{0}', v  ); }
825                     },
826                     {
827                         xtype: 'ColumnModel',
828                         xns: Roo.grid,
829                         dataIndex : 'cmhead_salesrep_id_salesrep_name',
830                         header : 'Cust. Sales Rep',
831                         sortable : true,
832                         width : 100,
833                         renderer : function(v) { return String.format('{0}', v  ); }
834                     },
835                     {
836                         xtype: 'ColumnModel',
837                         xns: Roo.grid,
838                         dataIndex : 'cmhead_cust_id_cust_name',
839                         header : 'Customer',
840                         width : 200,
841                         renderer : function(v) { return String.format('{0}', v); }
842                     },
843                     {
844                         xtype: 'ColumnModel',
845                         xns: Roo.grid,
846                         align : 'right',
847                         dataIndex : 'cmhead_curr_id_curr_symbol',
848                         header : 'Currency',
849                         width : 70,
850                         renderer : function(v)
851                         {
852                             return String.format('{0}', v ? v : '??');
853                         }
854                     },
855                     {
856                         xtype: 'ColumnModel',
857                         xns: Roo.grid,
858                         align : 'right',
859                         dataIndex : 'cmhead_value',
860                         header : 'Value',
861                         width : 100,
862                         renderer : function(v)
863                         {
864                             return Roo.util.Format.usMoney(v);
865                         }
866                     },
867                     {
868                         xtype: 'ColumnModel',
869                         xns: Roo.grid,
870                         align : 'right',
871                         dataIndex : 'cmhead_unpaid',
872                         header : 'Open Value',
873                         width : 100,
874                         renderer : function(v,x,r)
875                         {
876                             if (!r.data.cmhead_posted) {
877                                 return '';
878                             }
879                             return Roo.util.Format.usMoney(v);
880                         }
881                     },
882                     {
883                         xtype: 'ColumnModel',
884                         xns: Roo.grid,
885                         dataIndex : 'cmhead_posted',
886                         header : 'Posted',
887                         width : 75,
888                         renderer : function(v) { return String.format('{0}', v ? 'Yes':''); }
889                     }
890                 ]
891             }
892         };
893     }
894 });