1 //<script type="text/javascript">
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
5 Pman.Dialog.XtupleCreditMemo = {
10 show : function(data, cb)
18 this.dialog.show(this.data._el);
21 this.form.setValues(data);
22 this.form.fireEvent('actioncomplete', this.form, { type: 'setdata', data: data });
30 this.dialog = Roo.factory({
31 xtype: 'LayoutDialog',
35 this.layout.getRegion('center').showPanel(0);
43 title : "Edit / Create Credit Memo",
47 xtype: 'ContentPanel',
50 activate : function (_self)
52 // we need to reload to find out the subtotal.
53 if (!_this.data || !_this.data.cmhead_id) {
59 url : baseURL + '/Roo/cmhead',
61 _id : _this.data.cmhead_id
63 success : function(res) {
64 // update the items and tax values...?
65 _this.form.findField('cmhead_value').setValue(res.data.cmhead_value);
66 _this.form.findField('cmhead_tax_value').setValue(res.data.cmhead_tax_value * 1);
67 _this.form.findField('cmhead_taxable_value').setValue(res.data.cmhead_taxable_value * 1);
68 _this.form.findField('cmhead_misc_per').update();
69 _this.form.findField('cmhead_total').recalc();
76 title : "Credit Details",
82 actioncomplete : function(_self,action)
84 if (action.type == 'setdata') {
87 if (_this.data.cmhead_id) {
88 this.load({ method: 'GET', params: { '_id' : _this.data.cmhead_id }});
92 _this.dialog.setTitle("Add New Credit Memo");
94 _this.form.findField('cmhead_docdate').setValue(new Date());
98 if (action.type == 'load') {
100 _this.data = action.result.data;
102 if(_this.data.cmhead_posted){
103 _this.saveBtn.hide();
105 _this.dataloading = true;
106 if (_this.data.cmhead_shipto_cntct_id == _this.data.cmhead_billto_cntct_id) {
107 this.findField('_shipto_same').setValue(1);
108 Roo.log('set shipto 1');
110 // this.findField('_shipto_same').setValue(0);
111 Roo.log('set shipto 0');
113 _this.dataloading = false;
116 this.findField('billto_address').update();
117 // this.findField('shipto_address').update();
118 _this.dialog.setTitle("Edit Credit Memo Order - " + this.findField('cmhead_number').getValue());
120 _this.form.findField('cmhead_misc_per').update();
121 _this.form.findField('cmhead_total').recalc();
124 if (action.type =='submit') {
127 var id = _this.form.findField('cmhead_id').getValue() * 1;
130 _this.data.cmhead_id = action.result.data.cmhead_id;
131 this.load({ method: 'GET', params: { '_id' : _this.data.cmhead_id }});
137 if (_this.callback) {
138 _this.callback.call(_this, _this.form.getValues());
144 rendered : function (form)
148 actionfailed : function (_self, action)
150 if (action.failureType == 'client') {
151 Roo.MessageBox.alert("Error", "Fill in all the required fields");
153 if (action.failureType == 'server') {
155 Roo.MessageBox.alert("Error", action.result.errorMsg);
157 _this.dialog.layout.getRegion('center').showPanel(0);
161 style : 'margin:10px;',
162 url : baseURL + '/Roo/cmhead.php',
174 style : 'width:420px',
186 emptyText : "Automatic",
187 fieldLabel : 'Ref #',
188 name : 'cmhead_number',
196 fieldLabel : 'Customer',
197 name : 'cmhead_cust_id_cust_name',
205 displayField : 'location_name',
207 emptyText : "select location",
208 fieldLabel : 'Return stock to',
209 forceSelection : true,
210 hiddenName : 'cmhead_location_id',
212 loadingText : "Searching...",
214 name : 'cmhead_location_id_location_name',
216 qtip : "Select terms",
217 queryParam : 'query[location_name]',
218 selectOnFocus : true,
219 tpl : '<div class="x-grid-cell-text x-btn button"><b>{location_name}</b> {location_descrip}</div>',
220 triggerAction : 'all',
222 valueField : 'location_id',
228 beforeload : function (_self, o){
229 o.params = o.params || {};
231 o.params.location_netable = 1;
232 o.params._notinternalcompany = 1;
233 o.params.location_restrict = 0;
237 sortInfo : { direction : 'ASC', field: 'location_name' },
242 url : baseURL + '/Roo/location.php'
249 totalProperty : 'total',
250 fields : [{'name':'location_id','type':'int'},'location_name']
260 name : 'cmhead_docdate',
266 displayField : 'salesrep_name',
268 emptyText : "Select salesrep",
269 fieldLabel : 'Staff I.C.',
270 forceSelection : true,
271 hiddenName : 'cmhead_salesrep_id',
273 loadingText : "Searching...",
275 name : 'cmhead_salesrep_id_salesrep_name',
277 qtip : "Select salesrep",
278 queryParam : 'query[salesrep_name]',
279 selectOnFocus : true,
280 tpl : '<div class="x-grid-cell-text x-btn button"><b>{salesrep_name}</b> </div>',
281 triggerAction : 'all',
283 valueField : 'salesrep_id',
289 beforeload : function (_self, o){
290 o.params = o.params || {};
295 sortInfo : { direction : 'ASC', field: 'salesrep_name' },
300 url : baseURL + '/Roo/salesrep.php'
307 totalProperty : 'total',
308 fields : [{'name':'salesrep_id','type':'int'},'salesrep_name']
315 fieldLabel : 'Comments',
317 name : 'cmhead_comments',
329 style : 'margin-left:10px',
335 legend : "Price Details",
336 style : 'width:420px',
342 labelAlign : 'right',
349 labelAlign : 'right',
354 xtype: 'NumberField',
356 allowDecimals : true,
357 cls : 'roo-align-right',
358 decimalPrecision : 3,
359 fieldLabel : 'Taxable Value',
360 name : 'cmhead_taxable_value',
365 xtype: 'NumberField',
367 allowDecimals : true,
368 cls : 'roo-align-right',
369 decimalPrecision : 3,
370 fieldLabel : 'Tax Free Value',
371 name : 'cmhead_taxfree_value',
381 labelSeparator : ' ',
388 displayField : 'curr_name',
390 emptyText : "Select Currency",
391 fieldLabel : 'Currency',
392 forceSelection : true,
393 hiddenName : 'cmhead_curr_id',
395 loadingText : "Searching...",
397 name : 'cmhead_curr_id_curr_name',
399 qtip : "Select Currency",
400 queryParam : 'query[curr_name]',
401 selectOnFocus : true,
402 tpl : '<div class="x-grid-cell-text x-btn button"><b>{curr_name}</b> </div>',
403 triggerAction : 'all',
405 valueField : 'curr_id',
411 beforeload : function (_self, o){
412 o.params = o.params || {};
418 sortInfo : { direction : 'ASC', field: 'curr_symbol' },
423 url : baseURL + '/Roo/curr_symbol.php'
430 totalProperty : 'total',
431 fields : [{'name':'curr_id','type':'int'},'curr_symbol']
436 xtype: 'NumberField',
439 keyup : function (_self, e)
441 _this.form.findField('cmhead_total').recalc();
444 allowDecimals : true,
445 cls : 'roo-align-right',
446 decimalPrecision : 3,
447 fieldLabel : 'Freight',
448 name : 'cmhead_freight',
457 labelSeparator : ' ',
463 fieldLabel : 'Discount Description',
464 name : 'cmhead_misc_descrip',
468 xtype: 'NumberField',
471 keyup : function (_self, e)
473 var m = _this.form.findField('cmhead_misc');
474 var pv = _this.form.findField('cmhead_value').getValue();
475 var n = this.getValue();
476 var discount = parseInt(n * pv * 0.01);
477 m.setValue(discount * -1.000);
480 _this.form.findField('cmhead_total').recalc();
481 var val = discount * -1.0;
483 _this.form.findField('cohead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
487 allowDecimals : true,
488 cls : 'roo-align-right',
489 decimalPrecision : 1,
491 name : 'cmhead_misc_per',
493 update : function() {
494 var m = _this.form.findField('cmhead_misc_per');
495 var pv = parseFloat(_this.form.findField('cmhead_taxfree_value').getValue()) +
496 parseFloat(_this.form.findField('cmhead_taxable_value').getValue()) ;
497 var discount = parseFloat(_this.form.findField('cmhead_misc').getValue());
499 if (discount > 0.0) {
507 var val = ((discount) / pv) * -100;
509 //Roo.log("update discount?" + val);
510 this.setValue(val.toFixed(1));
513 _this.form.findField('cmhead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
521 xtype: 'NumberField',
524 keyup : function (_self, e)
526 _this.form.findField('cmhead_misc_per').update();
527 _this.form.findField('cmhead_total').recalc();
530 allowDecimals : true,
531 cls : 'roo-align-right',
532 decimalPrecision : 3,
533 fieldLabel : ' ',
534 name : 'cmhead_misc',
543 labelSeparator : ' ',
550 select : function (combo, record, index)
552 _this.form.findField('cmhead_tax_value').setValue(
553 record.data.taxzone_rate * _this.form.findField('cmhead_taxable_value').getValue()
558 displayField : 'taxzone_descrip',
560 emptyText : "Select tax zone",
561 fieldLabel : 'Tax Zone',
562 forceSelection : true,
563 hiddenName : 'cmhead_taxzone_id',
565 loadingText : "Searching...",
567 name : 'cmhead_taxzone_id_taxzone_descrip',
569 qtip : "Select tax zone",
570 queryParam : 'query[taxzone_descrip]',
571 selectOnFocus : true,
572 tpl : '<div class="x-grid-cell-text x-btn button"><b>{taxzone_descrip}</b> </div>',
573 triggerAction : 'all',
575 valueField : 'taxzone_id',
581 beforeload : function (_self, o){
582 o.params = o.params || {};
585 o.params.with_date = _this.form.findField('cmhead_docdate').getValue().format('Y-m-d');
586 Roo.log("with date?" + o.params.with_date);
592 sortInfo : { direction : 'ASC', field: 'taxzone_descrip' },
597 url : baseURL + '/Roo/taxzone.php'
604 totalProperty : 'total',
605 fields : [{'name':'taxzone_id','type':'int'},'taxzone_descrip']
610 xtype: 'NumberField',
612 allowDecimals : true,
613 cls : 'roo-align-right',
614 decimalPrecision : 3,
616 name : 'cmhead_tax_value',
625 labelAlign : 'right',
630 xtype: 'NumberField',
632 allowDecimals : true,
633 cls : 'roo-align-right',
634 decimalPrecision : 3,
635 fieldLabel : 'Total',
636 name : 'cmhead_total',
639 recalc : function() {
640 var vals = _this.form.getValues();
642 (1*vals.cmhead_taxable_value) + (1*vals.cmhead_taxfree_value) + (1*vals.cmhead_freight) + (1*vals.cmhead_tax_value) + (1*vals.cmhead_misc)
656 style : 'width:420px',
668 beforeselect : function (combo, record, index)
670 // set _this.data values ..
672 // just add everything...
673 for(var i in record.data) {
674 // Roo.log('cmhead_billto_cntct_id_' + i +' =' + record.data[i]);
675 _this.data['cmhead_billto_cntct_id_' + i] = record.data[i];
678 _this.form.findField('billto_address').update();
682 add : function (combo)
685 Pman.Dialog.XtupleQuickContact.show(
688 customer_id : _this.form.findField('cmhead_cust_id').getValue()
695 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
698 _this.form.findField('billto_address').update();
699 // fill in the select box..
700 _this.form.setValues( {
701 cmhead_billto_cntct_id : data.cntct_id,
702 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
708 // Pman.Dialog.XtupleCustomer.show(
709 //{ cust_id : _this.form.findField('cohead_cust_id').getValue() },
711 // refresh the data in the pulldown..
718 displayField : 'cntct_name',
720 emptyText : "Select Contact",
721 fieldLabel : 'Bill To (select)',
722 forceSelection : true,
723 hiddenName : 'cmhead_billto_cntct_id',
725 loadingText : "Searching...",
727 name : 'cmhead_billto_cntct_id_cntct_name',
729 qtip : "Select Contact",
730 queryParam : 'query[cntct_name]',
731 selectOnFocus : true,
732 tpl : '<div class="x-grid-cell-text x-btn button"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>',
733 triggerAction : 'all',
735 valueField : 'cntct_id',
741 beforeload : function (_self, o){
742 o.params = o.params || {};
744 o.params._customer_id = _this.data.cmhead_cust_id;
748 sortInfo : { direction : 'ASC', field: 'cntct_name' },
753 url : baseURL + '/Roo/cntct.php'
760 totalProperty : 'total',
761 fields : [{'name':'cntct_id','type':'int'},'cntct_name']
769 render : function (_self)
775 this.el.on('click', function() {
776 var id = _this.form.findField('cmhead_billto_cntct_id').getValue();
777 Pman.Dialog.XtupleQuickContact.show(
780 customer_id : _this.form.findField('cmhead_cust_id').getValue()
787 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
790 _this.form.findField('billto_address').update();
791 // fill in the select box..
792 _this.form.setValues( {
793 cmhead_billto_cntct_id : data.cntct_id,
794 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
802 fieldLabel : 'or enter Address',
803 name : 'billto_address',
805 update : function() {
807 var c = ['first_name', 'last_name' ] ;
808 var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
810 Roo.each(c, function(e) {
811 if (_this.data['cmhead_billto_cntct_id_cntct_' +e] &&
812 _this.data['cmhead_billto_cntct_id_cntct_' +e].length) {
813 v.push(_this.data['cmhead_billto_cntct_id_cntct_' +e]);
816 Roo.each(a, function(e) {
817 if (_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e] &&
818 _this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e].length) {
819 v.push(_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e]);
822 this.setValue(v.join("\n"));
839 name : 'cmhead_billto_addr_id'
844 name : 'cmhead_taxable_value'
849 name : 'cmhead_posted'
854 name : 'cmhead_cust_id'
859 name : 'taxzone_rate'
874 deactivate : function (_self)
877 _this.grid.stopEditing();
880 activate : function (_self)
885 try { if (MODULE.isBuilder) {
889 var id = _this.form.findField('cmhead_id').getValue() * 1;
891 Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
892 _this.dialog.layout.getRegion('center').showPanel(0);
896 _this.grid.ds.load({});
905 tableName : 'coitem',
906 title : "Credit Items",
915 //_this.dialog = Pman.Dialog.FILL_IN
916 if (_this.panel.active) {
920 afteredit : function (e)
922 //Roo.log('afteredit');
925 if (e.field == 'item_number' || e.originalValue == e.value) {
926 // afterselect handles this...
931 if ( r && r.data.cmitem_id) {
932 // as we disable update to the display on the ajax callback to
933 // allow editing flow to continue, and not refresh - we can only update
934 // these values after something has actually been edited.
935 r.set('coitem_id', r.data.cmitem_id);
939 if(r.data.cmitem_taxtype_id_taxtype_name == 'Taxable' ){
940 rate = _this.form.findField('taxzone_rate').getValue();
942 if(e.field == 'cmitem_tax_unitprice'){
943 r.set('cmitem_unitprice', r.data.cmitem_tax_unitprice * 1 / (1 + rate * 1));
944 // fields.push('cmitem_unitprice');
946 if(e.field == 'cmitem_unitprice'){
947 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1) );
948 // fields.push('cmitem_tax_unitprice');
950 if(e.field == 'cmitem_taxtype_id'){
951 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1) );
952 // fields.push('cmitem_tax_unitprice');
955 r.set('cmitem_tax_listprice', r.data.cmitem_item_listprice * (1 + rate * 1) );
956 // fields.push('cmitem_tax_listprice');
957 r.set('cmitem_line_value', r.data.cmitem_qtycredit * r.data.cmitem_unitprice );
958 // fields.push('cmitem_line_value');
959 r.set('cmitem_line_tax_value', r.data.cmitem_qtycredit * r.data.cmitem_tax_unitprice );
960 // fields.push('cmitem_line_tax_value');
962 // fields.push('cmitem_id');
966 var doupdate = function() {
967 if (!_this.itemsUpdating) {
968 Roo.log('doupdate...');
974 doupdate.defer(1000);
981 beforeedit : function (e)
983 // we can only edit if nothing is assigned to shipping or invoices..
984 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
985 Roo.MessageBox.alert("Error", "credit memo is already posted");
992 // seems below logic is useless...!!!!
995 if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
996 Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
1001 if (rec.data.coitem_subnumber * 1 > 0) {
1002 Roo.log("Edit container event");
1003 Roo.log(e); // if it's a tab..
1007 // allow editing of source / destination..
1008 case 'coitem_shipto_id':
1009 case 'coitem_location_src':
1014 Roo.MessageBox.alert("Error", "That is a kit item, edit the container.");
1018 // zero off values..
1019 //if (e.field == 'coitem_qtyord' && rec.data.coitem_qtyord == 0) {
1022 // if (e.field == 'coitem_custprice' && rec.data.coitem_qtyord == 0.0) {
1026 if (rec.data.item_type == 'K' && e.field == 'item_number') {
1027 // you can not change the product type on kits' as it messing things up..
1028 Roo.MessageBox.alert("Error", "That is a kit item,if you need to change it, delete it first.");
1034 celldblclick : function (_self, rowIndex, columnIndex, e)
1036 var rec = this.ds.getAt(rowIndex);
1037 var di = this.cm.getDataIndex(columnIndex);
1038 if (di != 'avail_qty') {
1041 Pman.Dialog.XtupleInvHistory.show({
1042 itemsite_item_id_item_number : rec.data.item_number,
1043 // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
1044 location_name : rec.data.coitem_location_src_location_name,
1045 location_descrip : rec.data.coitem_location_src_location_descrip,
1047 invhist_transdate : _this.form.findField('cohead_targetdate').getValue()
1051 rowclass : function (gridview, rowcfg)
1053 if (rowcfg.record.data.coitem_status == 'C' &&
1054 rowcfg.record.data.shipitem_shipped * 1 < 1) {
1056 rowcfg.rowClass = 'strikethrough';
1058 if (rowcfg.record.data.coitem_status == 'X' ) {
1060 rowcfg.rowClass = 'strikethrough';
1066 autoExpandColumn : 'cmitem_comments',
1069 loadAvail : function() {
1074 this.ds.each( function(r) {
1076 // only update if we do not have the details.
1077 if (r.data.avail_qty == 0) {
1081 item : r.data.item_number,
1082 loc: r.data.coitem_location_src_location_name,
1083 id: r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '')
1087 // needs to be a post to allow long lists of products..
1090 url : baseURL + '/Roo/itemloc',
1092 mask : "Loading available qty",
1093 maskel : _this.grid.view.el,
1095 _availqty : Roo.encode(q),
1096 curr_id : _this.form.findField('cohead_curr_id').getValue()
1098 success : function(d)
1100 _this.grid.ds.each(function(r) {
1101 var id = r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '');
1104 if (typeof(d.data[id]) == 'undefined') {
1107 r.set('avail_qty', d.data[id].qty);
1108 if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
1109 r.set('coitem_unitcost_in_order_cur', d.data[id].unitcost);
1121 xtype: 'CellSelectionModel',
1124 tabend : function (_self)
1126 _this.addItemBtn.fireEvent('click', _this.addItemBtn);
1128 beforeeditnext : function (eventdata)
1131 // this does not work, as the reload effect cancels editng.
1132 var rec = _this.grid.ds.getAt(eventdata.cell[0]);
1133 if (rec.data.coitem_subnumber *1 < 0 ) {
1136 var r = eventdata.cell[0] + 1;
1139 if (r > _this.grid.ds.getCount()-1 ) {
1140 eventdata.cell = false;
1143 rec = _this.grid.ds.getAt(r);
1144 if (rec.data.coitem_subnumber *1 < 0 ) {
1145 eventdata.cell = [ r, eventdata.cell[1] ];
1162 beforeload : function (_self,o) {
1168 Roo.log(_this.data);
1169 if (!_this.data || !_this.data.cmhead_id) {
1172 o.params = o.params || {};
1173 Roo.log(_this.data);
1174 o.params.cmitem_cmhead_id = _this.data.cmhead_id;
1175 o.params.limit = 999;
1178 update : function (_self, rec, operation)
1181 if (operation != Roo.data.Record.COMMIT) {
1185 // row has been updated..
1186 // if the qty + item has been filled in, we should try and save it..
1187 if (!(rec.data.cmitem_itemsite_id * 1) || !(rec.data.cmitem_qtycredit*1) || !(rec.data.cmitem_unitprice*1)) {
1188 Roo.log('not saving - row not completed');
1192 if (_this.itemsUpdating) {
1193 Roo.log('currently updating?');
1196 _this.itemsUpdating = true;
1199 Roo.log('Running update');
1202 url : baseURL+'/Roo/Cmitem',
1206 success: function(res)
1208 Roo.log('GOT success');
1209 // update the data...
1210 if (rec.data.item_type == 'K') {
1211 _this.itemsUpdating = false;
1212 _this.grid.ds.load({});
1215 if (_this.grid.activeEditor) {
1218 rec.set('cmitem_id', res.data.cmitem_id);
1220 _this.itemsUpdating = false;
1222 if(_this.hasQuery != 0){
1228 delete rec.modified;
1230 _this.grid.loadAvail();
1233 failure : function(res)
1235 Roo.MessageBox.alert(res.message);
1236 _this.itemsUpdating = false;
1247 load : function (_self, records, options)
1249 // need to fetch availablity from master data..
1250 // build a list of what to ask..
1252 // query: ITEM CODE - LOCATION
1254 //_this.grid.loadAvail.defer(100, _this.grid);
1257 Roo.each(records, function(r){
1259 if(r.data.cmitem_taxtype_id == r.data.cmitem_taxable_id ){
1260 rate = _this.form.findField('taxzone_rate').getValue();
1262 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1));
1263 r.set('cmitem_tax_listprice', r.data.cmitem_item_listprice * (1 + rate * 1));
1264 r.set('cmitem_line_tax_value', r.data.cmitem_line_value * (1 + rate * 1));
1270 sortInfo : { field : 'cmitem_linenumber', direction: 'ASC' },
1275 url : baseURL + '/Roo/Cmitem.php'
1278 xtype: 'JsonReader',
1280 totalProperty : 'total',
1285 'name': 'coitem_linenumber',
1289 'name': 'coitem_itemsite_id',
1293 'name': 'coitem_qtyord'
1296 'name': 'coitem_unitcost'
1299 'name': 'coitem_price'
1302 'name': 'coitem_custprice'
1305 'name': 'coitem_qtyreturned'
1308 'name': 'coitem_prcost'
1311 'name': 'coitem_price_uom_id',
1315 'name': 'coitem_qtyreserved'
1332 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1333 Roo.MessageBox.alert("Error", "credit memo is already posted");
1338 var grid = _this.grid;
1341 _this.grid.ds.each(function(r) {
1342 last = r.data.cmitem_linenumber;
1347 var nr = _this.grid.ds.reader.newRow({
1348 cmitem_linenumber : last,
1351 cmitem_cmhead_id : _this.form.findField('cmhead_id').getValue(),
1352 cmitem_comments : '',
1353 cmitem_taxtype_id : _this.data.default_taxtype_id,
1354 cmitem_taxtype_id_taxtype_name : 'Taxable'
1357 grid.ds.insert(grid.ds.getCount(), nr);
1358 grid.startEditing(grid.ds.getCount()-1, 1); // type..
1360 render : function (_self)
1362 _this.addItemBtn = _self;
1365 cls : 'x-btn-text-icon',
1367 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
1373 click : function (_self, e)
1377 _this.grid.ds.each(function(r) {
1378 last = r.data.cmitem_linenumber +1;
1383 var grid = _this.grid;
1384 var ct = _this.grid.ds.getCount();
\r
1385 var lastrow = ct ? _this.grid.ds.getAt(ct-1) : false;
\r
1387 var cmhead_cust_id = _this.form.findField('cmhead_cust_id').getValue();
1388 var cmhead_id = _this.form.findField('cmhead_id').getValue();
1390 Pman.Dialog.XtupleSalesProductList.show( {cohead_cust_id : cmhead_cust_id, cmhead_id : cmhead_id} , function(res) {
1397 if (!lr.data.cmitem_itemsite_id) {
1398 lr.set('cmitem_itemsite_id', res.item_itemsite_id_itemsite_id);
1399 lr.set('item_number', res.item_number);
1400 lr.set('item_descrip1', res.item_descrip1);
1401 lr.set('cmitem_comments', res.item_descrip1);
1402 lr.set('cmitem_cmhead_id', _this.form.findField('cmhead_id').getValue());
1406 var rate = _this.form.findField('taxzone_rate').getValue();
\r
1407 var nr = grid.ds.reader.newRow({
1408 cmitem_linenumber : last,
1409 cmitem_itemsite_id : res.item_itemsite_id_itemsite_id,
1410 item_number : res.item_number,
1411 item_descrip1 : res.item_descrip1 ,
1412 cmitem_cmhead_id : _this.form.findField('cmhead_id').getValue(),
1413 cmitem_comments : res.item_descrip1,
1414 cmitem_tax_listprice : res.item_price * ( 1 + rate * 1),
1415 cmitem_item_listprice : res.item_price,
1416 cmitem_tax_unitprice : res.item_price * ( 1 + rate * 1),
1417 cmitem_unitprice : res.item_price,
1418 cmitem_qtycredit : 1,
1419 cmitem_line_value : res.item_price,
1420 cmitem_line_tax_value : res.item_price * ( 1 + rate * 1)
1423 grid.ds.insert(grid.ds.getCount(), nr);
1425 var ar = grid.ds.getAt(grid.ds.getCount() - 1);
1431 cls : 'x-btn-text-icon',
1432 text : "Find Products",
1433 icon : rootURL + '/Pman/templates/images/search.gif'
1441 var cmhead_id = 1 * _this.form.findField('cmhead_id').getValue();
1443 Roo.MessageBox.alert("Error", "Save credit memo first!");
1449 url : baseURL + '/Roo/Metasql',
1455 'cmhead_id:number' : cmhead_id,
1465 cls : 'x-btn-text-icon',
1466 text : "Download Excel",
1467 icon : rootURL + '/Pman/templates/images/spreadsheet.gif'
1473 click : function (_self, e)
1476 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1477 Roo.MessageBox.alert("Error", "credit memo is already posted");
1481 Pman.Dialog.Image.show(
1483 _url : baseURL + '/Xtuple/Import/CreditMemo',
1484 onid : _this.form.findField('cmhead_id').getValue()
1488 _this.grid.ds.load({});
\r
1492 render : function (_self)
1494 _this.uploadBtn = _self;
1497 cls : 'x-btn-text-icon',
1498 text : "Upload Excel",
1499 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
1511 _this.grid.stopEditing();
1512 // check that no shipments or invoices are done..
1513 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1514 Roo.MessageBox.alert("Error", "credit memo is already posted");
1517 // check that no shipments or invoices are done..
1518 var rc = _this.grid.getSelectionModel().getSelectedCell();
1520 var rec = _this.grid.ds.getAt(rc[0]);
1522 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that line?", function(r)
1530 if (!rec.data.cmitem_id) {
1531 _this.grid.ds.remove(rec);
1537 url : baseURL + '/Roo/cmitem',
1540 _delete : rec.data.cmitem_id
1543 success : function() {
1544 if (rec.data.item_type == 'K') {
1545 _this.grid.ds.load({});
1548 _this.grid.ds.remove(rec);
1558 cls : 'x-btn-text-icon',
1560 icon : rootURL + '/Pman/templates/images/trash.gif'
1566 xtype: 'ColumnModel',
1568 dataIndex : 'cmitem_linenumber',
1571 renderer : function(v,x,r) {
1573 if (r.data.coitem_subnumber * 1 > 0) {
1574 return String.format('{0}.{1}', v,r.data.coitem_subnumber);
1576 return String.format('{0}', v);
1580 xtype: 'ColumnModel',
1582 dataIndex : 'item_number',
1583 header : 'Item Code',
1585 renderer : function(v) { return String.format('{0}', v); },
1587 xtype: 'GridEditor',
1593 beforeselect : function (combo, record, index)
1595 // set _this.data values ..
1596 var ar = _this.grid.activeEditor.record;
1597 //Roo.log('beforeselect');
1599 var rate = _this.form.findField('taxzone_rate').getValue();
1603 ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
1604 ar.set('cmitem_comments', record.data.itemsite_item_id_item_descrip1);
1605 ar.set('cmitem_tax_listprice', record.data.item_listprice * ( 1 + rate * 1) );
1606 ar.set('cmitem_item_listprice', record.data.item_listprice * 1);
1607 ar.set('cmitem_tax_unitprice', record.data.item_price * ( 1 + rate * 1) );
1608 ar.set('cmitem_unitprice', record.data.item_price * 1);
1609 ar.set('cmitem_qtycredit', 1);
1610 ar.set('cmitem_line_value', record.data.item_price * ar.data.cmitem_qtycredit);
1611 ar.set('cmitem_line_tax_value', ar.data.cmitem_tax_unitprice * ar.data.cmitem_qtycredit);
1612 ar.set('cmitem_itemsite_id', record.data.itemsite_id);
1613 ar.set('item_number', record.data.itemsite_item_id_item_number);
1614 ar.set('item_type', record.data.itemsite_item_id_item_type);
1615 ar.set('avail_qty', 0);
1616 // ar.updateFields = ['All'];
1623 displayField : 'itemsite_item_id_item_number',
1625 emptyText : "Select item",
1626 forceSelection : true,
1627 hiddenName : 'itemsite_item_id_item_number',
1629 loadingText : "Searching...",
1631 name : 'item_number',
1633 qtip : "Select item",
1634 queryParam : 'query[number]',
1635 selectOnFocus : true,
1636 tpl : '<div class="x-grid-cell-text x-btn button"><b>{itemsite_item_id_item_number}</b> ${item_price:toFixed(2)}- {itemsite_item_id_item_descrip1} </div>',
1637 triggerAction : 'all',
1639 valueField : 'item_number',
1644 beforeload : function (_self, o){
1645 o.params = o.params || {};
1646 o.params.customer_id = _this.form.findField('cmhead_cust_id').getValue();
1647 o.params['query[cmhead_id]'] = _this.form.findField('cmhead_id').getValue();
1648 //o.params.shipto_cust_id = _this.data.cohead_cust_id;
1653 sortInfo : { direction : 'ASC', field: 'item_number' },
1658 url : baseURL + '/Roo/itemsite.php'
1661 xtype: 'JsonReader',
1665 totalProperty : 'total',
1666 fields : [{'name':'item_id','type':'int'},'item_number']
1673 xtype: 'ColumnModel',
1675 dataIndex : 'cmitem_comments',
1676 header : 'Item Description',
1678 renderer : function(v,x,r) {
1681 r.set('cmitem_comments', r.data.item_descrip1);
1682 v = r.data.item_descrip1;
1684 if (v && v.length > 49) {
1685 return String.format('<span style="color:orange" qtip="line may be too long to print">{0}</span>', v);
1687 return String.format('{0}', v);
1691 xtype: 'GridEditor',
1701 xtype: 'ColumnModel',
1704 dataIndex : 'cmitem_qtycredit',
1707 renderer : function(v)
1709 return String.format('{0}', v ? parseInt(v) : '');
1712 xtype: 'GridEditor',
1715 xtype: 'NumberField',
1718 focus : function (_self)
1720 if (this.value == 0) {
1721 this.el.dom.value = '';
1725 allowDecimals : false,
1726 decimalPrecision : 0,
1728 style : 'text-align:right'
1733 xtype: 'ColumnModel',
1736 dataIndex : 'cmitem_tax_listprice',
1737 header : 'List Price w. tax',
1739 renderer : function(v,x,r)
1741 // var rate = _this.form.findField('taxzone_rate').getValue();
1742 // v = v * (1 + rate * 1);
1744 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1748 xtype: 'ColumnModel',
1751 dataIndex : 'cmitem_taxtype_id',
1754 renderer : function(v,x,r) { return String.format('{0}', r.data.cmitem_taxtype_id_taxtype_name); },
1756 xtype: 'GridEditor',
1762 displayField : 'taxtype_name',
1764 emptyText : "Select Tax Type",
1765 forceSelection : true,
1766 hiddenName : 'cmitem_taxtype_id',
1768 loadingText : "Searching...",
1770 name : 'cmitem_taxtype_id_taxtype_name',
1772 qtip : "Select taxtype",
1773 queryParam : 'query[taxtype_id]',
1774 selectOnFocus : true,
1775 tpl : '<div class="x-grid-cell-text x-btn button"><b>{taxtype_name}</b> </div>',
1776 triggerAction : 'all',
1778 valueField : 'taxtype_id',
1784 beforeload : function (_self, o){
1785 o.params = o.params || {};
1788 /* o.params.with_date = _this.form.findField('cohead_orderdate').getValue().format('Y-m-d');
1789 Roo.log("with date?" + o.params.with_date);*/
1795 sortInfo : { direction : 'ASC', field: 'taxtype_name' },
1800 url : baseURL + '/Roo/taxtype.php'
1803 xtype: 'JsonReader',
1807 totalProperty : 'total',
1808 fields : [{'name':'taxtype_id','type':'int'},'taxtype_name']
1815 xtype: 'ColumnModel',
1818 dataIndex : 'cmitem_tax_unitprice',
1819 header : 'Unit Price w. tax',
1821 renderer : function(v,x,r)
1823 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1826 xtype: 'GridEditor',
1829 xtype: 'NumberField',
1832 focus : function (_self)
1834 if (this.value == 0.0) {
1835 this.el.dom.value = '';
1839 decimalPrecision : 2,
1841 style : 'text-align:right'
1846 xtype: 'ColumnModel',
1849 dataIndex : 'cmitem_unitprice',
1850 header : 'Unit Price',
1852 renderer : function(v)
1854 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1857 xtype: 'GridEditor',
1860 xtype: 'NumberField',
1863 focus : function (_self)
1865 if (this.value == 0.0) {
1866 this.el.dom.value = '';
1870 decimalPrecision : 2,
1872 style : 'text-align:right'
1877 xtype: 'ColumnModel',
1880 dataIndex : 'cmitem_line_value',
1883 renderer : function(v)
1885 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1890 dataIndex : 'cmitem_line_tax_value',
1891 header : 'Total w. tax',
1893 renderer : function(v,x,r)
1895 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1906 activate : function() {
1907 _this.cpanel = this;
1909 var id = _this.form.findField('cmhead_id').getValue() * 1;
1911 Roo.MessageBox.alert("Error", "save the credit memo first!");
1912 _this.dialog.layout.getRegion('center').showPanel(0);
1917 _this.cgrid.footer.onClick('first');
1922 fitContainer : true,
1925 tableName : 'checkitem',
1926 title : "Miscellaneous Check",
1934 //_this.dialog = Pman.Dialog.FILL_IN
1935 if (_this.cpanel.active) {
1936 this.footer.onClick('first');
1940 autoExpandColumn : 'checkitem_checkhead_id_checkhead_notes',
1946 beforeload : function (_self, options)
1948 options.params = options.params || {};
1949 options.params.checkitem_cmnumber = _this.form.findField('cmhead_number').getValue();
1953 sortInfo : { field : 'checkitem_id', direction: 'DESC' },
1958 url : baseURL + '/Roo/checkitem.php'
1961 xtype: 'JsonReader',
1965 totalProperty : 'total',
1984 'name': 'leader_id',
1988 'name': 'leader_office_id',
1992 'name': 'leader_name',
1996 'name': 'leader_phone',
2000 'name': 'leader_fax',
2004 'name': 'leader_email',
2008 'name': 'leader_company_id',
2012 'name': 'leader_role',
2016 'name': 'leader_active',
2020 'name': 'leader_remarks',
2024 'name': 'leader_passwd',
2028 'name': 'leader_owner_id',
2032 'name': 'leader_lang',
2036 'name': 'leader_no_reset_sent',
2040 'name': 'leader_action_type',
2044 'name': 'leader_project_id',
2048 'name': 'leader_deleted_by',
2052 'name': 'leader_deleted_dt',
2056 'name': 'leader_firstname',
2060 'name': 'leader_lastname',
2064 'name': 'leader_name_facebook',
2068 'name': 'leader_url_blog',
2072 'name': 'leader_url_twitter',
2076 'name': 'leader_url_linkedin',
2080 'name': 'leader_crm_lead_percentage',
2084 'name': 'leader_crm_industry_id',
2088 'name': 'leader_crm_updated_action_id',
2092 'name': 'leader_crm_created_action_id',
2096 'name': 'leader_crm_type_id',
2103 xtype: 'PagingToolbar',
2106 displayMsg : "Displaying check item{0} - {1} of {2}",
2107 emptyMsg : "No check item found",
2112 xtype: 'ColumnModel',
2114 dataIndex : 'checkitem_docdate',
2117 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
2120 xtype: 'ColumnModel',
2122 dataIndex : 'checkitem_bankaccnt_id_bankaccnt_name',
2123 header : 'Bank Account',
2125 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2128 xtype: 'ColumnModel',
2130 dataIndex : 'checkitem_checkhead_id_checkhead_for',
2133 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2136 xtype: 'ColumnModel',
2138 dataIndex : 'checkitem_checkhead_id_checkhead_notes',
2141 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2144 xtype: 'ColumnModel',
2147 dataIndex : 'checkitem_curr_id_curr_name',
2148 header : 'Currency',
2150 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2153 xtype: 'ColumnModel',
2156 dataIndex : 'checkitem_amount',
2159 renderer : function(v) { return String.format('{0}', v ? parseFloat(v).toFixed(2) : ''); }
2168 activate : function() {
2169 _this.apanel = this;
2171 _this.agrid.footer.onClick('first');
2176 fitContainer : true,
2179 tableName : 'invchead',
2180 title : "Applications",
2188 //_this.dialog = Pman.Dialog.FILL_IN
2189 if (_this.apanel.active) {
2190 this.footer.onClick('first');
2194 autoExpandColumn : 'arapply_target_docnumber',
2200 beforeload : function (_self,o) {
2206 if (!_this.data || !_this.data.cmhead_id) {
2209 o.params = o.params || {};
2211 o.params._application = _this.data.cmhead_id
2216 sortInfo : { field : 'arapply_id', direction: 'ASC' },
2221 url : baseURL + '/Roo/Arapply.php'
2224 xtype: 'JsonReader',
2226 totalProperty : 'total',
2247 'name': 'leader_id',
2251 'name': 'leader_office_id',
2255 'name': 'leader_name',
2259 'name': 'leader_phone',
2263 'name': 'leader_fax',
2267 'name': 'leader_email',
2271 'name': 'leader_company_id',
2275 'name': 'leader_role',
2279 'name': 'leader_active',
2283 'name': 'leader_remarks',
2287 'name': 'leader_passwd',
2291 'name': 'leader_owner_id',
2295 'name': 'leader_lang',
2299 'name': 'leader_no_reset_sent',
2303 'name': 'leader_action_type',
2307 'name': 'leader_project_id',
2311 'name': 'leader_deleted_by',
2315 'name': 'leader_deleted_dt',
2319 'name': 'leader_firstname',
2323 'name': 'leader_lastname',
2327 'name': 'leader_name_facebook',
2331 'name': 'leader_url_blog',
2335 'name': 'leader_url_twitter',
2339 'name': 'leader_url_linkedin',
2343 'name': 'leader_crm_lead_percentage',
2347 'name': 'leader_crm_industry_id',
2351 'name': 'leader_crm_updated_action_id',
2355 'name': 'leader_crm_created_action_id',
2359 'name': 'leader_crm_type_id',
2366 xtype: 'PagingToolbar',
2369 displayMsg : "Displaying application{0} - {1} of {2}",
2370 emptyMsg : "No application found",
2375 xtype: 'ColumnModel',
2377 dataIndex : 'arapply_id',
2380 renderer : function(v) { return String.format('{0}', v); }
2383 xtype: 'ColumnModel',
2385 dataIndex : 'arapply_distdate',
2388 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
2391 xtype: 'ColumnModel',
2393 dataIndex : 'arapply_target_doctype',
2394 header : 'Target Doctype',
2396 renderer : function(v) { return String.format('{0}', v); }
2399 xtype: 'ColumnModel',
2401 dataIndex : 'arapply_target_docnumber',
2402 header : 'Target Docnumber',
2404 renderer : function(v) { return String.format('{0}', v); }
2407 xtype: 'ColumnModel',
2409 dataIndex : 'arapply_curr_id_curr_name',
2410 header : 'Currency',
2412 renderer : function(v) { return String.format('{0}', v); }
2415 xtype: 'ColumnModel',
2417 dataIndex : 'arapply_applied',
2420 renderer : function(v) { return String.format('{0}', v); }
2429 activate : function() {
2430 _this.hpanel = this;
2432 _this.hgrid.footer.onClick('first');
2437 fitContainer : true,
2440 tableName : 'events',
2449 //_this.dialog = Pman.Dialog.FILL_IN
2450 if (_this.hpanel.active) {
2451 this.footer.onClick('first');
2454 rowdblclick : function (_self, rowIndex, e)
2456 if (!_this.dialog) return;
2457 _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
2458 _this.grid.footer.onClick('first');
2462 autoExpandColumn : 'remarks',
2468 beforeload : function (_self, options)
2470 options.params._related_on_table = 'cmhead';
2471 options.params._related_on_id = _this.form.findField('cmhead_id').getValue();
2476 sortInfo : { field : 'event_when', direction: 'DESC' },
2481 url : baseURL + '/Roo/events.php'
2484 xtype: 'JsonReader',
2486 totalProperty : 'total',
2491 'name': 'event_when',
2503 'name': 'person_id_name',
2514 xtype: 'PagingToolbar',
2518 displayMsg : "Displaying events{0} - {1} of {2}",
2519 emptyMsg : "No events found"
2523 xtype: 'ColumnModel',
2525 dataIndex : 'event_when',
2528 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); }
2531 xtype: 'ColumnModel',
2533 dataIndex : 'action',
2536 renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); }
2539 xtype: 'ColumnModel',
2541 dataIndex : 'ipaddr',
2542 header : 'IP address',
2544 renderer : function(v) { return String.format('{0}', v); }
2547 xtype: 'ColumnModel',
2549 dataIndex : 'person_id_name',
2552 renderer : function(v) { return String.format('{0}', v); }
2555 xtype: 'ColumnModel',
2557 dataIndex : 'remarks',
2560 renderer : function(v) { return String.format('{0}', v); }
2567 xtype: 'LayoutRegion',
2569 alwaysShowTabs : true,
2577 click : function (_self, e)
2579 if (_this.grid) _this.grid.stopEditing();
2580 _this.dialog.hide();
2589 click : function (_self, e)
2592 if (_this.grid) _this.grid.stopEditing();
2593 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
2594 Roo.MessageBox.alert("Error", "credit memo is already posted");
2599 if (_this.grid && _this.grid.ds) {
2600 _this.grid.ds.each(function(rec) {
2601 if (!(rec.data.cmitem_itemsite_id * 1) || !(rec.data.cmitem_qtycredit*1) || !(rec.data.cmitem_unitprice*1)) {
2609 Roo.MessageBox.alert("Error", "Some lines do not have product/qty/price set");
2614 _this.form.findField('has_item').setValue(ar.length);
2617 _this.form.doAction("submit");
2619 render : function (_self)
2621 _this.saveBtn = _self;