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_value').getValue());
496 var discount = parseFloat(_this.form.findField('cmhead_misc').getValue());
498 if (discount > 0.0) {
506 var val = ((discount) / pv) * -100;
508 //Roo.log("update discount?" + val);
509 this.setValue(val.toFixed(1));
512 _this.form.findField('cmhead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
520 xtype: 'NumberField',
523 keyup : function (_self, e)
525 _this.form.findField('cmhead_misc_per').update();
526 _this.form.findField('cmhead_total').recalc();
529 allowDecimals : true,
530 cls : 'roo-align-right',
531 decimalPrecision : 3,
532 fieldLabel : ' ',
533 name : 'cmhead_misc',
542 labelSeparator : ' ',
549 select : function (combo, record, index)
551 _this.form.findField('cmhead_tax_value').setValue(
552 record.data.taxzone_rate * _this.form.findField('cmhead_taxable_value').getValue()
557 displayField : 'taxzone_descrip',
559 emptyText : "Select tax zone",
560 fieldLabel : 'Tax Zone',
561 forceSelection : true,
562 hiddenName : 'cmhead_taxzone_id',
564 loadingText : "Searching...",
566 name : 'cmhead_taxzone_id_taxzone_descrip',
568 qtip : "Select tax zone",
569 queryParam : 'query[taxzone_descrip]',
570 selectOnFocus : true,
571 tpl : '<div class="x-grid-cell-text x-btn button"><b>{taxzone_descrip}</b> </div>',
572 triggerAction : 'all',
574 valueField : 'taxzone_id',
580 beforeload : function (_self, o){
581 o.params = o.params || {};
584 o.params.with_date = _this.form.findField('cmhead_docdate').getValue().format('Y-m-d');
585 Roo.log("with date?" + o.params.with_date);
591 sortInfo : { direction : 'ASC', field: 'taxzone_descrip' },
596 url : baseURL + '/Roo/taxzone.php'
603 totalProperty : 'total',
604 fields : [{'name':'taxzone_id','type':'int'},'taxzone_descrip']
609 xtype: 'NumberField',
611 allowDecimals : true,
612 cls : 'roo-align-right',
613 decimalPrecision : 3,
615 name : 'cmhead_tax_value',
624 labelAlign : 'right',
629 xtype: 'NumberField',
631 allowDecimals : true,
632 cls : 'roo-align-right',
633 decimalPrecision : 3,
634 fieldLabel : 'Total',
635 name : 'cmhead_total',
638 recalc : function() {
639 var vals = _this.form.getValues();
641 (1*vals.cmhead_taxable_value) + (1*vals.cmhead_taxfree_value) + (1*vals.cmhead_freight) + (1*vals.cmhead_tax_value) + (1*vals.cmhead_misc)
655 style : 'width:420px',
667 beforeselect : function (combo, record, index)
669 // set _this.data values ..
671 // just add everything...
672 for(var i in record.data) {
673 // Roo.log('cmhead_billto_cntct_id_' + i +' =' + record.data[i]);
674 _this.data['cmhead_billto_cntct_id_' + i] = record.data[i];
677 _this.form.findField('billto_address').update();
681 add : function (combo)
684 Pman.Dialog.XtupleQuickContact.show(
687 customer_id : _this.form.findField('cmhead_cust_id').getValue()
694 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
697 _this.form.findField('billto_address').update();
698 // fill in the select box..
699 _this.form.setValues( {
700 cmhead_billto_cntct_id : data.cntct_id,
701 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
707 // Pman.Dialog.XtupleCustomer.show(
708 //{ cust_id : _this.form.findField('cohead_cust_id').getValue() },
710 // refresh the data in the pulldown..
717 displayField : 'cntct_name',
719 emptyText : "Select Contact",
720 fieldLabel : 'Bill To (select)',
721 forceSelection : true,
722 hiddenName : 'cmhead_billto_cntct_id',
724 loadingText : "Searching...",
726 name : 'cmhead_billto_cntct_id_cntct_name',
728 qtip : "Select Contact",
729 queryParam : 'query[cntct_name]',
730 selectOnFocus : true,
731 tpl : '<div class="x-grid-cell-text x-btn button"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>',
732 triggerAction : 'all',
734 valueField : 'cntct_id',
740 beforeload : function (_self, o){
741 o.params = o.params || {};
743 o.params._customer_id = _this.data.cmhead_cust_id;
747 sortInfo : { direction : 'ASC', field: 'cntct_name' },
752 url : baseURL + '/Roo/cntct.php'
759 totalProperty : 'total',
760 fields : [{'name':'cntct_id','type':'int'},'cntct_name']
768 render : function (_self)
774 this.el.on('click', function() {
775 var id = _this.form.findField('cmhead_billto_cntct_id').getValue();
776 Pman.Dialog.XtupleQuickContact.show(
779 customer_id : _this.form.findField('cmhead_cust_id').getValue()
786 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
789 _this.form.findField('billto_address').update();
790 // fill in the select box..
791 _this.form.setValues( {
792 cmhead_billto_cntct_id : data.cntct_id,
793 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
801 fieldLabel : 'or enter Address',
802 name : 'billto_address',
804 update : function() {
806 var c = ['first_name', 'last_name' ] ;
807 var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
809 Roo.each(c, function(e) {
810 if (_this.data['cmhead_billto_cntct_id_cntct_' +e] &&
811 _this.data['cmhead_billto_cntct_id_cntct_' +e].length) {
812 v.push(_this.data['cmhead_billto_cntct_id_cntct_' +e]);
815 Roo.each(a, function(e) {
816 if (_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e] &&
817 _this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e].length) {
818 v.push(_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e]);
821 this.setValue(v.join("\n"));
838 name : 'cmhead_billto_addr_id'
843 name : 'cmhead_taxable_value'
848 name : 'cmhead_posted'
853 name : 'cmhead_cust_id'
858 name : 'taxzone_rate'
873 deactivate : function (_self)
876 _this.grid.stopEditing();
879 activate : function (_self)
884 try { if (MODULE.isBuilder) {
888 var id = _this.form.findField('cmhead_id').getValue() * 1;
890 Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
891 _this.dialog.layout.getRegion('center').showPanel(0);
895 _this.grid.ds.load({});
904 tableName : 'coitem',
905 title : "Credit Items",
914 //_this.dialog = Pman.Dialog.FILL_IN
915 if (_this.panel.active) {
919 afteredit : function (e)
921 //Roo.log('afteredit');
924 if (e.field == 'item_number' || e.originalValue == e.value) {
925 // afterselect handles this...
930 if ( r && r.data.cmitem_id) {
931 // as we disable update to the display on the ajax callback to
932 // allow editing flow to continue, and not refresh - we can only update
933 // these values after something has actually been edited.
934 r.set('coitem_id', r.data.cmitem_id);
938 if(r.data.cmitem_taxtype_id_taxtype_name == 'Taxable' ){
939 rate = _this.form.findField('taxzone_rate').getValue();
941 if(e.field == 'cmitem_tax_unitprice'){
942 r.set('cmitem_unitprice', r.data.cmitem_tax_unitprice * 1 / (1 + rate * 1));
943 // fields.push('cmitem_unitprice');
945 if(e.field == 'cmitem_unitprice'){
946 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1) );
947 // fields.push('cmitem_tax_unitprice');
949 if(e.field == 'cmitem_taxtype_id'){
950 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1) );
951 // fields.push('cmitem_tax_unitprice');
954 r.set('cmitem_tax_listprice', r.data.cmitem_item_listprice * (1 + rate * 1) );
955 // fields.push('cmitem_tax_listprice');
956 r.set('cmitem_line_value', r.data.cmitem_qtycredit * r.data.cmitem_unitprice );
957 // fields.push('cmitem_line_value');
958 r.set('cmitem_line_tax_value', r.data.cmitem_qtycredit * r.data.cmitem_tax_unitprice );
959 // fields.push('cmitem_line_tax_value');
961 // fields.push('cmitem_id');
965 var doupdate = function() {
966 if (!_this.itemsUpdating) {
967 Roo.log('doupdate...');
973 doupdate.defer(1000);
980 beforeedit : function (e)
982 // we can only edit if nothing is assigned to shipping or invoices..
983 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
984 Roo.MessageBox.alert("Error", "credit memo is already posted");
991 // seems below logic is useless...!!!!
994 if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
995 Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
1000 if (rec.data.coitem_subnumber * 1 > 0) {
1001 Roo.log("Edit container event");
1002 Roo.log(e); // if it's a tab..
1006 // allow editing of source / destination..
1007 case 'coitem_shipto_id':
1008 case 'coitem_location_src':
1013 Roo.MessageBox.alert("Error", "That is a kit item, edit the container.");
1017 // zero off values..
1018 //if (e.field == 'coitem_qtyord' && rec.data.coitem_qtyord == 0) {
1021 // if (e.field == 'coitem_custprice' && rec.data.coitem_qtyord == 0.0) {
1025 if (rec.data.item_type == 'K' && e.field == 'item_number') {
1026 // you can not change the product type on kits' as it messing things up..
1027 Roo.MessageBox.alert("Error", "That is a kit item,if you need to change it, delete it first.");
1033 celldblclick : function (_self, rowIndex, columnIndex, e)
1035 var rec = this.ds.getAt(rowIndex);
1036 var di = this.cm.getDataIndex(columnIndex);
1037 if (di != 'avail_qty') {
1040 Pman.Dialog.XtupleInvHistory.show({
1041 itemsite_item_id_item_number : rec.data.item_number,
1042 // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
1043 location_name : rec.data.coitem_location_src_location_name,
1044 location_descrip : rec.data.coitem_location_src_location_descrip,
1046 invhist_transdate : _this.form.findField('cohead_targetdate').getValue()
1050 rowclass : function (gridview, rowcfg)
1052 if (rowcfg.record.data.coitem_status == 'C' &&
1053 rowcfg.record.data.shipitem_shipped * 1 < 1) {
1055 rowcfg.rowClass = 'strikethrough';
1057 if (rowcfg.record.data.coitem_status == 'X' ) {
1059 rowcfg.rowClass = 'strikethrough';
1065 autoExpandColumn : 'cmitem_comments',
1068 loadAvail : function() {
1073 this.ds.each( function(r) {
1075 // only update if we do not have the details.
1076 if (r.data.avail_qty == 0) {
1080 item : r.data.item_number,
1081 loc: r.data.coitem_location_src_location_name,
1082 id: r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '')
1086 // needs to be a post to allow long lists of products..
1089 url : baseURL + '/Roo/itemloc',
1091 mask : "Loading available qty",
1092 maskel : _this.grid.view.el,
1094 _availqty : Roo.encode(q),
1095 curr_id : _this.form.findField('cohead_curr_id').getValue()
1097 success : function(d)
1099 _this.grid.ds.each(function(r) {
1100 var id = r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '');
1103 if (typeof(d.data[id]) == 'undefined') {
1106 r.set('avail_qty', d.data[id].qty);
1107 if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
1108 r.set('coitem_unitcost_in_order_cur', d.data[id].unitcost);
1120 xtype: 'CellSelectionModel',
1123 tabend : function (_self)
1125 _this.addItemBtn.fireEvent('click', _this.addItemBtn);
1127 beforeeditnext : function (eventdata)
1130 // this does not work, as the reload effect cancels editng.
1131 var rec = _this.grid.ds.getAt(eventdata.cell[0]);
1132 if (rec.data.coitem_subnumber *1 < 0 ) {
1135 var r = eventdata.cell[0] + 1;
1138 if (r > _this.grid.ds.getCount()-1 ) {
1139 eventdata.cell = false;
1142 rec = _this.grid.ds.getAt(r);
1143 if (rec.data.coitem_subnumber *1 < 0 ) {
1144 eventdata.cell = [ r, eventdata.cell[1] ];
1161 beforeload : function (_self,o) {
1167 Roo.log(_this.data);
1168 if (!_this.data || !_this.data.cmhead_id) {
1171 o.params = o.params || {};
1172 Roo.log(_this.data);
1173 o.params.cmitem_cmhead_id = _this.data.cmhead_id;
1174 o.params.limit = 999;
1177 update : function (_self, rec, operation)
1180 if (operation != Roo.data.Record.COMMIT) {
1184 // row has been updated..
1185 // if the qty + item has been filled in, we should try and save it..
1186 if (!(rec.data.cmitem_itemsite_id * 1) || !(rec.data.cmitem_qtycredit*1) || !(rec.data.cmitem_unitprice*1)) {
1187 Roo.log('not saving - row not completed');
1191 if (_this.itemsUpdating) {
1192 Roo.log('currently updating?');
1195 _this.itemsUpdating = true;
1198 Roo.log('Running update');
1201 url : baseURL+'/Roo/Cmitem',
1205 success: function(res)
1207 Roo.log('GOT success');
1208 // update the data...
1209 if (rec.data.item_type == 'K') {
1210 _this.itemsUpdating = false;
1211 _this.grid.ds.load({});
1214 if (_this.grid.activeEditor) {
1217 rec.set('cmitem_id', res.data.cmitem_id);
1219 _this.itemsUpdating = false;
1221 if(_this.hasQuery != 0){
1227 delete rec.modified;
1229 _this.grid.loadAvail();
1232 failure : function(res)
1234 Roo.MessageBox.alert(res.message);
1235 _this.itemsUpdating = false;
1246 load : function (_self, records, options)
1248 // need to fetch availablity from master data..
1249 // build a list of what to ask..
1251 // query: ITEM CODE - LOCATION
1253 //_this.grid.loadAvail.defer(100, _this.grid);
1256 Roo.each(records, function(r){
1258 if(r.data.cmitem_taxtype_id == r.data.cmitem_taxable_id ){
1259 rate = _this.form.findField('taxzone_rate').getValue();
1261 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1));
1262 r.set('cmitem_tax_listprice', r.data.cmitem_item_listprice * (1 + rate * 1));
1263 r.set('cmitem_line_tax_value', r.data.cmitem_line_value * (1 + rate * 1));
1269 sortInfo : { field : 'cmitem_linenumber', direction: 'ASC' },
1274 url : baseURL + '/Roo/Cmitem.php'
1277 xtype: 'JsonReader',
1279 totalProperty : 'total',
1284 'name': 'coitem_linenumber',
1288 'name': 'coitem_itemsite_id',
1292 'name': 'coitem_qtyord'
1295 'name': 'coitem_unitcost'
1298 'name': 'coitem_price'
1301 'name': 'coitem_custprice'
1304 'name': 'coitem_qtyreturned'
1307 'name': 'coitem_prcost'
1310 'name': 'coitem_price_uom_id',
1314 'name': 'coitem_qtyreserved'
1331 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1332 Roo.MessageBox.alert("Error", "credit memo is already posted");
1337 var grid = _this.grid;
1340 _this.grid.ds.each(function(r) {
1341 last = r.data.cmitem_linenumber;
1346 var nr = _this.grid.ds.reader.newRow({
1347 cmitem_linenumber : last,
1350 cmitem_cmhead_id : _this.form.findField('cmhead_id').getValue(),
1351 cmitem_comments : '',
1352 cmitem_taxtype_id : _this.data.default_taxtype_id,
1353 cmitem_taxtype_id_taxtype_name : 'Taxable'
1356 grid.ds.insert(grid.ds.getCount(), nr);
1357 grid.startEditing(grid.ds.getCount()-1, 1); // type..
1359 render : function (_self)
1361 _this.addItemBtn = _self;
1364 cls : 'x-btn-text-icon',
1366 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
1372 click : function (_self, e)
1376 _this.grid.ds.each(function(r) {
1377 last = r.data.cmitem_linenumber +1;
1382 var grid = _this.grid;
1383 var ct = _this.grid.ds.getCount();
\r
1384 var lastrow = ct ? _this.grid.ds.getAt(ct-1) : false;
\r
1386 var cmhead_cust_id = _this.form.findField('cmhead_cust_id').getValue();
1387 var cmhead_id = _this.form.findField('cmhead_id').getValue();
1389 Pman.Dialog.XtupleSalesProductList.show( {cohead_cust_id : cmhead_cust_id, cmhead_id : cmhead_id} , function(res) {
1396 if (!lr.data.cmitem_itemsite_id) {
1397 lr.set('cmitem_itemsite_id', res.item_itemsite_id_itemsite_id);
1398 lr.set('item_number', res.item_number);
1399 lr.set('item_descrip1', res.item_descrip1);
1400 lr.set('cmitem_comments', res.item_descrip1);
1401 lr.set('cmitem_cmhead_id', _this.form.findField('cmhead_id').getValue());
1405 var rate = _this.form.findField('taxzone_rate').getValue();
\r
1406 var nr = grid.ds.reader.newRow({
1407 cmitem_linenumber : last,
1408 cmitem_itemsite_id : res.item_itemsite_id_itemsite_id,
1409 item_number : res.item_number,
1410 item_descrip1 : res.item_descrip1 ,
1411 cmitem_cmhead_id : _this.form.findField('cmhead_id').getValue(),
1412 cmitem_comments : res.item_descrip1,
1413 cmitem_tax_listprice : res.item_price * ( 1 + rate * 1),
1414 cmitem_item_listprice : res.item_price,
1415 cmitem_tax_unitprice : res.item_price * ( 1 + rate * 1),
1416 cmitem_unitprice : res.item_price,
1417 cmitem_qtycredit : 1,
1418 cmitem_line_value : res.item_price,
1419 cmitem_line_tax_value : res.item_price * ( 1 + rate * 1)
1422 grid.ds.insert(grid.ds.getCount(), nr);
1424 var ar = grid.ds.getAt(grid.ds.getCount() - 1);
1430 cls : 'x-btn-text-icon',
1431 text : "Find Products",
1432 icon : rootURL + '/Pman/templates/images/search.gif'
1440 var cmhead_id = 1 * _this.form.findField('cmhead_id').getValue();
1442 Roo.MessageBox.alert("Error", "Save credit memo first!");
1448 url : baseURL + '/Roo/Metasql',
1454 'cmhead_id:number' : cmhead_id,
1464 cls : 'x-btn-text-icon',
1465 text : "Download Excel",
1466 icon : rootURL + '/Pman/templates/images/spreadsheet.gif'
1472 click : function (_self, e)
1475 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1476 Roo.MessageBox.alert("Error", "credit memo is already posted");
1480 Pman.Dialog.Image.show(
1482 _url : baseURL + '/Xtuple/Import/CreditMemo',
1483 onid : _this.form.findField('cmhead_id').getValue()
1487 _this.grid.ds.load({});
\r
1491 render : function (_self)
1493 _this.uploadBtn = _self;
1496 cls : 'x-btn-text-icon',
1497 text : "Upload Excel",
1498 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
1510 _this.grid.stopEditing();
1511 // check that no shipments or invoices are done..
1512 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1513 Roo.MessageBox.alert("Error", "credit memo is already posted");
1516 // check that no shipments or invoices are done..
1517 var rc = _this.grid.getSelectionModel().getSelectedCell();
1519 var rec = _this.grid.ds.getAt(rc[0]);
1521 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that line?", function(r)
1529 if (!rec.data.cmitem_id) {
1530 _this.grid.ds.remove(rec);
1536 url : baseURL + '/Roo/cmitem',
1539 _delete : rec.data.cmitem_id
1542 success : function() {
1543 if (rec.data.item_type == 'K') {
1544 _this.grid.ds.load({});
1547 _this.grid.ds.remove(rec);
1557 cls : 'x-btn-text-icon',
1559 icon : rootURL + '/Pman/templates/images/trash.gif'
1565 xtype: 'ColumnModel',
1567 dataIndex : 'cmitem_linenumber',
1570 renderer : function(v,x,r) {
1572 if (r.data.coitem_subnumber * 1 > 0) {
1573 return String.format('{0}.{1}', v,r.data.coitem_subnumber);
1575 return String.format('{0}', v);
1579 xtype: 'ColumnModel',
1581 dataIndex : 'item_number',
1582 header : 'Item Code',
1584 renderer : function(v) { return String.format('{0}', v); },
1586 xtype: 'GridEditor',
1592 beforeselect : function (combo, record, index)
1594 // set _this.data values ..
1595 var ar = _this.grid.activeEditor.record;
1596 //Roo.log('beforeselect');
1598 var rate = _this.form.findField('taxzone_rate').getValue();
1602 ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
1603 ar.set('cmitem_comments', record.data.itemsite_item_id_item_descrip1);
1604 ar.set('cmitem_tax_listprice', record.data.item_listprice * ( 1 + rate * 1) );
1605 ar.set('cmitem_item_listprice', record.data.item_listprice * 1);
1606 ar.set('cmitem_tax_unitprice', record.data.item_price * ( 1 + rate * 1) );
1607 ar.set('cmitem_unitprice', record.data.item_price * 1);
1608 ar.set('cmitem_qtycredit', 1);
1609 ar.set('cmitem_line_value', record.data.item_price * ar.data.cmitem_qtycredit);
1610 ar.set('cmitem_line_tax_value', ar.data.cmitem_tax_unitprice * ar.data.cmitem_qtycredit);
1611 ar.set('cmitem_itemsite_id', record.data.itemsite_id);
1612 ar.set('item_number', record.data.itemsite_item_id_item_number);
1613 ar.set('item_type', record.data.itemsite_item_id_item_type);
1614 ar.set('avail_qty', 0);
1615 // ar.updateFields = ['All'];
1622 displayField : 'itemsite_item_id_item_number',
1624 emptyText : "Select item",
1625 forceSelection : true,
1626 hiddenName : 'itemsite_item_id_item_number',
1628 loadingText : "Searching...",
1630 name : 'item_number',
1632 qtip : "Select item",
1633 queryParam : 'query[number]',
1634 selectOnFocus : true,
1635 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>',
1636 triggerAction : 'all',
1638 valueField : 'item_number',
1643 beforeload : function (_self, o){
1644 o.params = o.params || {};
1645 o.params.customer_id = _this.form.findField('cmhead_cust_id').getValue();
1646 o.params['query[cmhead_id]'] = _this.form.findField('cmhead_id').getValue();
1647 //o.params.shipto_cust_id = _this.data.cohead_cust_id;
1652 sortInfo : { direction : 'ASC', field: 'item_number' },
1657 url : baseURL + '/Roo/itemsite.php'
1660 xtype: 'JsonReader',
1664 totalProperty : 'total',
1665 fields : [{'name':'item_id','type':'int'},'item_number']
1672 xtype: 'ColumnModel',
1674 dataIndex : 'cmitem_comments',
1675 header : 'Item Description',
1677 renderer : function(v,x,r) {
1680 r.set('cmitem_comments', r.data.item_descrip1);
1681 v = r.data.item_descrip1;
1683 if (v && v.length > 49) {
1684 return String.format('<span style="color:orange" qtip="line may be too long to print">{0}</span>', v);
1686 return String.format('{0}', v);
1690 xtype: 'GridEditor',
1700 xtype: 'ColumnModel',
1703 dataIndex : 'cmitem_qtycredit',
1706 renderer : function(v)
1708 return String.format('{0}', v ? parseInt(v) : '');
1711 xtype: 'GridEditor',
1714 xtype: 'NumberField',
1717 focus : function (_self)
1719 if (this.value == 0) {
1720 this.el.dom.value = '';
1724 allowDecimals : false,
1725 decimalPrecision : 0,
1727 style : 'text-align:right'
1732 xtype: 'ColumnModel',
1735 dataIndex : 'cmitem_tax_listprice',
1736 header : 'List Price w. tax',
1738 renderer : function(v,x,r)
1740 // var rate = _this.form.findField('taxzone_rate').getValue();
1741 // v = v * (1 + rate * 1);
1743 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1747 xtype: 'ColumnModel',
1750 dataIndex : 'cmitem_taxtype_id',
1753 renderer : function(v,x,r) { return String.format('{0}', r.data.cmitem_taxtype_id_taxtype_name); },
1755 xtype: 'GridEditor',
1761 displayField : 'taxtype_name',
1763 emptyText : "Select Tax Type",
1764 forceSelection : true,
1765 hiddenName : 'cmitem_taxtype_id',
1767 loadingText : "Searching...",
1769 name : 'cmitem_taxtype_id_taxtype_name',
1771 qtip : "Select taxtype",
1772 queryParam : 'query[taxtype_id]',
1773 selectOnFocus : true,
1774 tpl : '<div class="x-grid-cell-text x-btn button"><b>{taxtype_name}</b> </div>',
1775 triggerAction : 'all',
1777 valueField : 'taxtype_id',
1783 beforeload : function (_self, o){
1784 o.params = o.params || {};
1787 /* o.params.with_date = _this.form.findField('cohead_orderdate').getValue().format('Y-m-d');
1788 Roo.log("with date?" + o.params.with_date);*/
1794 sortInfo : { direction : 'ASC', field: 'taxtype_name' },
1799 url : baseURL + '/Roo/taxtype.php'
1802 xtype: 'JsonReader',
1806 totalProperty : 'total',
1807 fields : [{'name':'taxtype_id','type':'int'},'taxtype_name']
1814 xtype: 'ColumnModel',
1817 dataIndex : 'cmitem_tax_unitprice',
1818 header : 'Unit Price w. tax',
1820 renderer : function(v,x,r)
1822 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1825 xtype: 'GridEditor',
1828 xtype: 'NumberField',
1831 focus : function (_self)
1833 if (this.value == 0.0) {
1834 this.el.dom.value = '';
1838 decimalPrecision : 2,
1840 style : 'text-align:right'
1845 xtype: 'ColumnModel',
1848 dataIndex : 'cmitem_unitprice',
1849 header : 'Unit Price',
1851 renderer : function(v)
1853 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1856 xtype: 'GridEditor',
1859 xtype: 'NumberField',
1862 focus : function (_self)
1864 if (this.value == 0.0) {
1865 this.el.dom.value = '';
1869 decimalPrecision : 2,
1871 style : 'text-align:right'
1876 xtype: 'ColumnModel',
1879 dataIndex : 'cmitem_line_value',
1882 renderer : function(v)
1884 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1889 dataIndex : 'cmitem_line_tax_value',
1890 header : 'Total w. tax',
1892 renderer : function(v,x,r)
1894 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1905 activate : function() {
1906 _this.cpanel = this;
1908 var id = _this.form.findField('cmhead_id').getValue() * 1;
1910 Roo.MessageBox.alert("Error", "save the credit memo first!");
1911 _this.dialog.layout.getRegion('center').showPanel(0);
1916 _this.cgrid.footer.onClick('first');
1921 fitContainer : true,
1924 tableName : 'checkitem',
1925 title : "Miscellaneous Check",
1933 //_this.dialog = Pman.Dialog.FILL_IN
1934 if (_this.cpanel.active) {
1935 this.footer.onClick('first');
1939 autoExpandColumn : 'checkitem_checkhead_id_checkhead_notes',
1945 beforeload : function (_self, options)
1947 options.params = options.params || {};
1948 options.params.checkitem_cmnumber = _this.form.findField('cmhead_number').getValue();
1952 sortInfo : { field : 'checkitem_id', direction: 'DESC' },
1957 url : baseURL + '/Roo/checkitem.php'
1960 xtype: 'JsonReader',
1964 totalProperty : 'total',
1983 'name': 'leader_id',
1987 'name': 'leader_office_id',
1991 'name': 'leader_name',
1995 'name': 'leader_phone',
1999 'name': 'leader_fax',
2003 'name': 'leader_email',
2007 'name': 'leader_company_id',
2011 'name': 'leader_role',
2015 'name': 'leader_active',
2019 'name': 'leader_remarks',
2023 'name': 'leader_passwd',
2027 'name': 'leader_owner_id',
2031 'name': 'leader_lang',
2035 'name': 'leader_no_reset_sent',
2039 'name': 'leader_action_type',
2043 'name': 'leader_project_id',
2047 'name': 'leader_deleted_by',
2051 'name': 'leader_deleted_dt',
2055 'name': 'leader_firstname',
2059 'name': 'leader_lastname',
2063 'name': 'leader_name_facebook',
2067 'name': 'leader_url_blog',
2071 'name': 'leader_url_twitter',
2075 'name': 'leader_url_linkedin',
2079 'name': 'leader_crm_lead_percentage',
2083 'name': 'leader_crm_industry_id',
2087 'name': 'leader_crm_updated_action_id',
2091 'name': 'leader_crm_created_action_id',
2095 'name': 'leader_crm_type_id',
2102 xtype: 'PagingToolbar',
2105 displayMsg : "Displaying check item{0} - {1} of {2}",
2106 emptyMsg : "No check item found",
2111 xtype: 'ColumnModel',
2113 dataIndex : 'checkitem_docdate',
2116 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
2119 xtype: 'ColumnModel',
2121 dataIndex : 'checkitem_bankaccnt_id_bankaccnt_name',
2122 header : 'Bank Account',
2124 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2127 xtype: 'ColumnModel',
2129 dataIndex : 'checkitem_checkhead_id_checkhead_for',
2132 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2135 xtype: 'ColumnModel',
2137 dataIndex : 'checkitem_checkhead_id_checkhead_notes',
2140 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2143 xtype: 'ColumnModel',
2146 dataIndex : 'checkitem_curr_id_curr_name',
2147 header : 'Currency',
2149 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2152 xtype: 'ColumnModel',
2155 dataIndex : 'checkitem_amount',
2158 renderer : function(v) { return String.format('{0}', v ? parseFloat(v).toFixed(2) : ''); }
2167 activate : function() {
2168 _this.apanel = this;
2170 _this.agrid.footer.onClick('first');
2175 fitContainer : true,
2178 tableName : 'invchead',
2179 title : "Applications",
2187 //_this.dialog = Pman.Dialog.FILL_IN
2188 if (_this.apanel.active) {
2189 this.footer.onClick('first');
2193 autoExpandColumn : 'arapply_target_docnumber',
2199 beforeload : function (_self,o) {
2205 if (!_this.data || !_this.data.cmhead_id) {
2208 o.params = o.params || {};
2210 o.params._application = _this.data.cmhead_id
2215 sortInfo : { field : 'arapply_id', direction: 'ASC' },
2220 url : baseURL + '/Roo/Arapply.php'
2223 xtype: 'JsonReader',
2225 totalProperty : 'total',
2246 'name': 'leader_id',
2250 'name': 'leader_office_id',
2254 'name': 'leader_name',
2258 'name': 'leader_phone',
2262 'name': 'leader_fax',
2266 'name': 'leader_email',
2270 'name': 'leader_company_id',
2274 'name': 'leader_role',
2278 'name': 'leader_active',
2282 'name': 'leader_remarks',
2286 'name': 'leader_passwd',
2290 'name': 'leader_owner_id',
2294 'name': 'leader_lang',
2298 'name': 'leader_no_reset_sent',
2302 'name': 'leader_action_type',
2306 'name': 'leader_project_id',
2310 'name': 'leader_deleted_by',
2314 'name': 'leader_deleted_dt',
2318 'name': 'leader_firstname',
2322 'name': 'leader_lastname',
2326 'name': 'leader_name_facebook',
2330 'name': 'leader_url_blog',
2334 'name': 'leader_url_twitter',
2338 'name': 'leader_url_linkedin',
2342 'name': 'leader_crm_lead_percentage',
2346 'name': 'leader_crm_industry_id',
2350 'name': 'leader_crm_updated_action_id',
2354 'name': 'leader_crm_created_action_id',
2358 'name': 'leader_crm_type_id',
2365 xtype: 'PagingToolbar',
2368 displayMsg : "Displaying application{0} - {1} of {2}",
2369 emptyMsg : "No application found",
2374 xtype: 'ColumnModel',
2376 dataIndex : 'arapply_id',
2379 renderer : function(v) { return String.format('{0}', v); }
2382 xtype: 'ColumnModel',
2384 dataIndex : 'arapply_distdate',
2387 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
2390 xtype: 'ColumnModel',
2392 dataIndex : 'arapply_target_doctype',
2393 header : 'Target Doctype',
2395 renderer : function(v) { return String.format('{0}', v); }
2398 xtype: 'ColumnModel',
2400 dataIndex : 'arapply_target_docnumber',
2401 header : 'Target Docnumber',
2403 renderer : function(v) { return String.format('{0}', v); }
2406 xtype: 'ColumnModel',
2408 dataIndex : 'arapply_curr_id_curr_name',
2409 header : 'Currency',
2411 renderer : function(v) { return String.format('{0}', v); }
2414 xtype: 'ColumnModel',
2416 dataIndex : 'arapply_applied',
2419 renderer : function(v) { return String.format('{0}', v); }
2428 activate : function() {
2429 _this.hpanel = this;
2431 _this.hgrid.footer.onClick('first');
2436 fitContainer : true,
2439 tableName : 'events',
2448 //_this.dialog = Pman.Dialog.FILL_IN
2449 if (_this.hpanel.active) {
2450 this.footer.onClick('first');
2453 rowdblclick : function (_self, rowIndex, e)
2455 if (!_this.dialog) return;
2456 _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
2457 _this.grid.footer.onClick('first');
2461 autoExpandColumn : 'remarks',
2467 beforeload : function (_self, options)
2469 options.params._related_on_table = 'cmhead';
2470 options.params._related_on_id = _this.form.findField('cmhead_id').getValue();
2475 sortInfo : { field : 'event_when', direction: 'DESC' },
2480 url : baseURL + '/Roo/events.php'
2483 xtype: 'JsonReader',
2485 totalProperty : 'total',
2490 'name': 'event_when',
2502 'name': 'person_id_name',
2513 xtype: 'PagingToolbar',
2517 displayMsg : "Displaying events{0} - {1} of {2}",
2518 emptyMsg : "No events found"
2522 xtype: 'ColumnModel',
2524 dataIndex : 'event_when',
2527 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); }
2530 xtype: 'ColumnModel',
2532 dataIndex : 'action',
2535 renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); }
2538 xtype: 'ColumnModel',
2540 dataIndex : 'ipaddr',
2541 header : 'IP address',
2543 renderer : function(v) { return String.format('{0}', v); }
2546 xtype: 'ColumnModel',
2548 dataIndex : 'person_id_name',
2551 renderer : function(v) { return String.format('{0}', v); }
2554 xtype: 'ColumnModel',
2556 dataIndex : 'remarks',
2559 renderer : function(v) { return String.format('{0}', v); }
2566 xtype: 'LayoutRegion',
2568 alwaysShowTabs : true,
2576 click : function (_self, e)
2578 if (_this.grid) _this.grid.stopEditing();
2579 _this.dialog.hide();
2588 click : function (_self, e)
2591 if (_this.grid) _this.grid.stopEditing();
2592 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
2593 Roo.MessageBox.alert("Error", "credit memo is already posted");
2598 if (_this.grid && _this.grid.ds) {
2599 _this.grid.ds.each(function(rec) {
2600 if (!(rec.data.cmitem_itemsite_id * 1) || !(rec.data.cmitem_qtycredit*1) || !(rec.data.cmitem_unitprice*1)) {
2608 Roo.MessageBox.alert("Error", "Some lines do not have product/qty/price set");
2613 _this.form.findField('has_item').setValue(ar.length);
2616 _this.form.doAction("submit");
2618 render : function (_self)
2620 _this.saveBtn = _self;