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...?
66 _this.form.findField('cmhead_taxfree_value').setValue(res.data.cmhead_taxfree_value);
67 _this.form.findField('cmhead_tax_value').setValue(res.data.cmhead_tax_value * 1);
68 _this.form.findField('cmhead_taxable_value').setValue(res.data.cmhead_taxable_value * 1);
69 _this.form.findField('cmhead_misc_per').update();
70 _this.form.findField('cmhead_total').recalc();
77 title : "Credit Details",
83 actioncomplete : function(_self,action)
85 if (action.type == 'setdata') {
88 if (_this.data.cmhead_id) {
89 this.load({ method: 'GET', params: { '_id' : _this.data.cmhead_id }});
93 _this.dialog.setTitle("Add New Credit Memo");
95 _this.form.findField('cmhead_docdate').setValue(new Date());
99 if (action.type == 'load') {
101 _this.data = action.result.data;
103 if(_this.data.cmhead_posted){
104 _this.saveBtn.hide();
106 _this.dataloading = true;
107 if (_this.data.cmhead_shipto_cntct_id == _this.data.cmhead_billto_cntct_id) {
108 this.findField('_shipto_same').setValue(1);
109 Roo.log('set shipto 1');
111 // this.findField('_shipto_same').setValue(0);
112 Roo.log('set shipto 0');
114 _this.dataloading = false;
117 this.findField('billto_address').update();
118 // this.findField('shipto_address').update();
119 _this.dialog.setTitle("Edit Credit Memo Order - " + this.findField('cmhead_number').getValue());
121 _this.form.findField('cmhead_misc_per').update();
122 _this.form.findField('cmhead_total').recalc();
125 if (action.type =='submit') {
128 var id = _this.form.findField('cmhead_id').getValue() * 1;
131 _this.data.cmhead_id = action.result.data.cmhead_id;
132 this.load({ method: 'GET', params: { '_id' : _this.data.cmhead_id }});
138 if (_this.callback) {
139 _this.callback.call(_this, _this.form.getValues());
145 rendered : function (form)
149 actionfailed : function (_self, action)
151 if (action.failureType == 'client') {
152 Roo.MessageBox.alert("Error", "Fill in all the required fields");
154 if (action.failureType == 'server') {
156 Roo.MessageBox.alert("Error", action.result.errorMsg);
158 _this.dialog.layout.getRegion('center').showPanel(0);
162 style : 'margin:10px;',
163 url : baseURL + '/Roo/cmhead.php',
175 style : 'width:420px',
187 emptyText : "Automatic",
188 fieldLabel : 'Ref #',
189 name : 'cmhead_number',
197 fieldLabel : 'Customer',
198 name : 'cmhead_cust_id_cust_name',
206 displayField : 'location_name',
208 emptyText : "select location",
209 fieldLabel : 'Return stock to',
210 forceSelection : true,
211 hiddenName : 'cmhead_location_id',
213 loadingText : "Searching...",
215 name : 'cmhead_location_id_location_name',
217 qtip : "Select terms",
218 queryParam : 'query[location_name]',
219 selectOnFocus : true,
220 tpl : '<div class="x-grid-cell-text x-btn button"><b>{location_name}</b> {location_descrip}</div>',
221 triggerAction : 'all',
223 valueField : 'location_id',
229 beforeload : function (_self, o){
230 o.params = o.params || {};
232 o.params.location_netable = 1;
233 o.params._notinternalcompany = 1;
234 o.params.location_restrict = 0;
238 sortInfo : { direction : 'ASC', field: 'location_name' },
243 url : baseURL + '/Roo/location.php'
250 totalProperty : 'total',
251 fields : [{'name':'location_id','type':'int'},'location_name']
261 name : 'cmhead_docdate',
267 displayField : 'salesrep_name',
269 emptyText : "Select salesrep",
270 fieldLabel : 'Staff I.C.',
271 forceSelection : true,
272 hiddenName : 'cmhead_salesrep_id',
274 loadingText : "Searching...",
276 name : 'cmhead_salesrep_id_salesrep_name',
278 qtip : "Select salesrep",
279 queryParam : 'query[salesrep_name]',
280 selectOnFocus : true,
281 tpl : '<div class="x-grid-cell-text x-btn button"><b>{salesrep_name}</b> </div>',
282 triggerAction : 'all',
284 valueField : 'salesrep_id',
290 beforeload : function (_self, o){
291 o.params = o.params || {};
296 sortInfo : { direction : 'ASC', field: 'salesrep_name' },
301 url : baseURL + '/Roo/salesrep.php'
308 totalProperty : 'total',
309 fields : [{'name':'salesrep_id','type':'int'},'salesrep_name']
316 fieldLabel : 'Comments',
318 name : 'cmhead_comments',
330 style : 'margin-left:10px',
336 legend : "Price Details",
337 style : 'width:420px',
343 labelAlign : 'right',
350 labelAlign : 'right',
355 xtype: 'NumberField',
357 allowDecimals : true,
358 cls : 'roo-align-right',
359 decimalPrecision : 3,
360 fieldLabel : 'Taxable Value',
361 name : 'cmhead_taxable_value',
366 xtype: 'NumberField',
368 allowDecimals : true,
369 cls : 'roo-align-right',
370 decimalPrecision : 3,
371 fieldLabel : 'Tax Free Value',
372 name : 'cmhead_taxfree_value',
382 labelSeparator : ' ',
389 displayField : 'curr_name',
391 emptyText : "Select Currency",
392 fieldLabel : 'Currency',
393 forceSelection : true,
394 hiddenName : 'cmhead_curr_id',
396 loadingText : "Searching...",
398 name : 'cmhead_curr_id_curr_name',
400 qtip : "Select Currency",
401 queryParam : 'query[curr_name]',
402 selectOnFocus : true,
403 tpl : '<div class="x-grid-cell-text x-btn button"><b>{curr_name}</b> </div>',
404 triggerAction : 'all',
406 valueField : 'curr_id',
412 beforeload : function (_self, o){
413 o.params = o.params || {};
419 sortInfo : { direction : 'ASC', field: 'curr_symbol' },
424 url : baseURL + '/Roo/curr_symbol.php'
431 totalProperty : 'total',
432 fields : [{'name':'curr_id','type':'int'},'curr_symbol']
437 xtype: 'NumberField',
440 keyup : function (_self, e)
442 _this.form.findField('cmhead_total').recalc();
445 allowDecimals : true,
446 cls : 'roo-align-right',
447 decimalPrecision : 3,
448 fieldLabel : 'Freight',
449 name : 'cmhead_freight',
458 labelSeparator : ' ',
464 fieldLabel : 'Discount Description',
465 name : 'cmhead_misc_descrip',
469 xtype: 'NumberField',
472 keyup : function (_self, e)
474 var m = _this.form.findField('cmhead_misc');
475 var pv = _this.form.findField('cmhead_value').getValue();
476 var n = this.getValue();
477 var discount = parseInt(n * pv * 0.01);
478 m.setValue(discount * -1.000);
481 _this.form.findField('cmhead_total').recalc();
482 var val = discount * -1.0;
484 _this.form.findField('cohead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
488 allowDecimals : true,
489 cls : 'roo-align-right',
490 decimalPrecision : 1,
492 name : 'cmhead_misc_per',
494 update : function() {
495 var m = _this.form.findField('cmhead_misc_per');
496 var pv = parseFloat(_this.form.findField('cmhead_taxfree_value').getValue()) +
497 parseFloat(_this.form.findField('cmhead_taxable_value').getValue()) ;
498 var discount = parseFloat(_this.form.findField('cmhead_misc').getValue());
500 if (discount > 0.0) {
508 var val = ((discount) / pv) * -100;
510 //Roo.log("update discount?" + val);
511 this.setValue(val.toFixed(1));
514 _this.form.findField('cmhead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
522 xtype: 'NumberField',
525 keyup : function (_self, e)
527 _this.form.findField('cmhead_misc_per').update();
528 _this.form.findField('cmhead_total').recalc();
531 allowDecimals : true,
532 cls : 'roo-align-right',
533 decimalPrecision : 3,
534 fieldLabel : ' ',
535 name : 'cmhead_misc',
544 labelSeparator : ' ',
551 select : function (combo, record, index)
553 _this.form.findField('cmhead_tax_value').setValue(
554 record.data.taxzone_rate * _this.form.findField('cmhead_taxable_value').getValue()
559 displayField : 'taxzone_descrip',
561 emptyText : "Select tax zone",
562 fieldLabel : 'Tax Zone',
563 forceSelection : true,
564 hiddenName : 'cmhead_taxzone_id',
566 loadingText : "Searching...",
568 name : 'cmhead_taxzone_id_taxzone_descrip',
570 qtip : "Select tax zone",
571 queryParam : 'query[taxzone_descrip]',
572 selectOnFocus : true,
573 tpl : '<div class="x-grid-cell-text x-btn button"><b>{taxzone_descrip}</b> </div>',
574 triggerAction : 'all',
576 valueField : 'taxzone_id',
582 beforeload : function (_self, o){
583 o.params = o.params || {};
586 o.params.with_date = _this.form.findField('cmhead_docdate').getValue().format('Y-m-d');
587 Roo.log("with date?" + o.params.with_date);
593 sortInfo : { direction : 'ASC', field: 'taxzone_descrip' },
598 url : baseURL + '/Roo/taxzone.php'
605 totalProperty : 'total',
606 fields : [{'name':'taxzone_id','type':'int'},'taxzone_descrip']
611 xtype: 'NumberField',
613 allowDecimals : true,
614 cls : 'roo-align-right',
615 decimalPrecision : 3,
617 name : 'cmhead_tax_value',
626 labelAlign : 'right',
631 xtype: 'NumberField',
633 allowDecimals : true,
634 cls : 'roo-align-right',
635 decimalPrecision : 3,
636 fieldLabel : 'Total',
637 name : 'cmhead_total',
640 recalc : function() {
641 var vals = _this.form.getValues();
643 (1*vals.cmhead_taxable_value) + (1*vals.cmhead_taxfree_value) + (1*vals.cmhead_freight) + (1*vals.cmhead_tax_value) + (1*vals.cmhead_misc)
657 style : 'width:420px',
669 beforeselect : function (combo, record, index)
671 // set _this.data values ..
673 // just add everything...
674 for(var i in record.data) {
675 // Roo.log('cmhead_billto_cntct_id_' + i +' =' + record.data[i]);
676 _this.data['cmhead_billto_cntct_id_' + i] = record.data[i];
679 _this.form.findField('billto_address').update();
683 add : function (combo)
686 Pman.Dialog.XtupleQuickContact.show(
689 customer_id : _this.form.findField('cmhead_cust_id').getValue()
696 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
699 _this.form.findField('billto_address').update();
700 // fill in the select box..
701 _this.form.setValues( {
702 cmhead_billto_cntct_id : data.cntct_id,
703 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
709 // Pman.Dialog.XtupleCustomer.show(
710 //{ cust_id : _this.form.findField('cohead_cust_id').getValue() },
712 // refresh the data in the pulldown..
719 displayField : 'cntct_name',
721 emptyText : "Select Contact",
722 fieldLabel : 'Bill To (select)',
723 forceSelection : true,
724 hiddenName : 'cmhead_billto_cntct_id',
726 loadingText : "Searching...",
728 name : 'cmhead_billto_cntct_id_cntct_name',
730 qtip : "Select Contact",
731 queryParam : 'query[cntct_name]',
732 selectOnFocus : true,
733 tpl : '<div class="x-grid-cell-text x-btn button"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>',
734 triggerAction : 'all',
736 valueField : 'cntct_id',
742 beforeload : function (_self, o){
743 o.params = o.params || {};
745 o.params._customer_id = _this.data.cmhead_cust_id;
749 sortInfo : { direction : 'ASC', field: 'cntct_name' },
754 url : baseURL + '/Roo/cntct.php'
761 totalProperty : 'total',
762 fields : [{'name':'cntct_id','type':'int'},'cntct_name']
770 render : function (_self)
776 this.el.on('click', function() {
777 var id = _this.form.findField('cmhead_billto_cntct_id').getValue();
778 Pman.Dialog.XtupleQuickContact.show(
781 customer_id : _this.form.findField('cmhead_cust_id').getValue()
788 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
791 _this.form.findField('billto_address').update();
792 // fill in the select box..
793 _this.form.setValues( {
794 cmhead_billto_cntct_id : data.cntct_id,
795 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
803 fieldLabel : 'or enter Address',
804 name : 'billto_address',
806 update : function() {
808 var c = ['first_name', 'last_name' ] ;
809 var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
811 Roo.each(c, function(e) {
812 if (_this.data['cmhead_billto_cntct_id_cntct_' +e] &&
813 _this.data['cmhead_billto_cntct_id_cntct_' +e].length) {
814 v.push(_this.data['cmhead_billto_cntct_id_cntct_' +e]);
817 Roo.each(a, function(e) {
818 if (_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e] &&
819 _this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e].length) {
820 v.push(_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e]);
823 this.setValue(v.join("\n"));
840 name : 'cmhead_billto_addr_id'
845 name : 'cmhead_taxable_value'
850 name : 'cmhead_posted'
855 name : 'cmhead_cust_id'
860 name : 'taxzone_rate'
875 deactivate : function (_self)
878 _this.grid.stopEditing();
881 activate : function (_self)
886 try { if (MODULE.isBuilder) {
890 var id = _this.form.findField('cmhead_id').getValue() * 1;
892 Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
893 _this.dialog.layout.getRegion('center').showPanel(0);
897 _this.grid.ds.load({});
906 tableName : 'coitem',
907 title : "Credit Items",
916 //_this.dialog = Pman.Dialog.FILL_IN
917 if (_this.panel.active) {
921 afteredit : function (e)
923 //Roo.log('afteredit');
926 if (e.field == 'item_number' || e.originalValue == e.value) {
927 // afterselect handles this...
932 if ( r && r.data.cmitem_id) {
933 // as we disable update to the display on the ajax callback to
934 // allow editing flow to continue, and not refresh - we can only update
935 // these values after something has actually been edited.
936 r.set('coitem_id', r.data.cmitem_id);
940 if(r.data.cmitem_taxtype_id_taxtype_name == 'Taxable' ){
941 rate = _this.form.findField('taxzone_rate').getValue();
943 if(e.field == 'cmitem_tax_unitprice'){
944 r.set('cmitem_unitprice', r.data.cmitem_tax_unitprice * 1 / (1 + rate * 1));
945 // fields.push('cmitem_unitprice');
947 if(e.field == 'cmitem_unitprice'){
948 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1) );
949 // fields.push('cmitem_tax_unitprice');
951 if(e.field == 'cmitem_taxtype_id'){
952 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1) );
953 // fields.push('cmitem_tax_unitprice');
956 r.set('cmitem_tax_listprice', r.data.cmitem_item_listprice * (1 + rate * 1) );
957 // fields.push('cmitem_tax_listprice');
958 r.set('cmitem_line_value', r.data.cmitem_qtycredit * r.data.cmitem_unitprice );
959 // fields.push('cmitem_line_value');
960 r.set('cmitem_line_tax_value', r.data.cmitem_qtycredit * r.data.cmitem_tax_unitprice );
961 // fields.push('cmitem_line_tax_value');
963 // fields.push('cmitem_id');
967 var doupdate = function() {
968 if (!_this.itemsUpdating) {
969 Roo.log('doupdate...');
975 doupdate.defer(1000);
982 beforeedit : function (e)
984 // we can only edit if nothing is assigned to shipping or invoices..
985 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
986 Roo.MessageBox.alert("Error", "credit memo is already posted");
993 // seems below logic is useless...!!!!
996 if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
997 Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
1002 if (rec.data.coitem_subnumber * 1 > 0) {
1003 Roo.log("Edit container event");
1004 Roo.log(e); // if it's a tab..
1008 // allow editing of source / destination..
1009 case 'coitem_shipto_id':
1010 case 'coitem_location_src':
1015 Roo.MessageBox.alert("Error", "That is a kit item, edit the container.");
1019 // zero off values..
1020 //if (e.field == 'coitem_qtyord' && rec.data.coitem_qtyord == 0) {
1023 // if (e.field == 'coitem_custprice' && rec.data.coitem_qtyord == 0.0) {
1027 if (rec.data.item_type == 'K' && e.field == 'item_number') {
1028 // you can not change the product type on kits' as it messing things up..
1029 Roo.MessageBox.alert("Error", "That is a kit item,if you need to change it, delete it first.");
1035 celldblclick : function (_self, rowIndex, columnIndex, e)
1037 var rec = this.ds.getAt(rowIndex);
1038 var di = this.cm.getDataIndex(columnIndex);
1039 if (di != 'avail_qty') {
1042 Pman.Dialog.XtupleInvHistory.show({
1043 itemsite_item_id_item_number : rec.data.item_number,
1044 // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
1045 location_name : rec.data.coitem_location_src_location_name,
1046 location_descrip : rec.data.coitem_location_src_location_descrip,
1048 invhist_transdate : _this.form.findField('cohead_targetdate').getValue()
1052 rowclass : function (gridview, rowcfg)
1054 if (rowcfg.record.data.coitem_status == 'C' &&
1055 rowcfg.record.data.shipitem_shipped * 1 < 1) {
1057 rowcfg.rowClass = 'strikethrough';
1059 if (rowcfg.record.data.coitem_status == 'X' ) {
1061 rowcfg.rowClass = 'strikethrough';
1067 autoExpandColumn : 'cmitem_comments',
1070 loadAvail : function() {
1075 this.ds.each( function(r) {
1077 // only update if we do not have the details.
1078 if (r.data.avail_qty == 0) {
1082 item : r.data.item_number,
1083 loc: r.data.coitem_location_src_location_name,
1084 id: r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '')
1088 // needs to be a post to allow long lists of products..
1091 url : baseURL + '/Roo/itemloc',
1093 mask : "Loading available qty",
1094 maskel : _this.grid.view.el,
1096 _availqty : Roo.encode(q),
1097 curr_id : _this.form.findField('cohead_curr_id').getValue()
1099 success : function(d)
1101 _this.grid.ds.each(function(r) {
1102 var id = r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '');
1105 if (typeof(d.data[id]) == 'undefined') {
1108 r.set('avail_qty', d.data[id].qty);
1109 if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
1110 r.set('coitem_unitcost_in_order_cur', d.data[id].unitcost);
1122 xtype: 'CellSelectionModel',
1125 tabend : function (_self)
1127 _this.addItemBtn.fireEvent('click', _this.addItemBtn);
1129 beforeeditnext : function (eventdata)
1132 // this does not work, as the reload effect cancels editng.
1133 var rec = _this.grid.ds.getAt(eventdata.cell[0]);
1134 if (rec.data.coitem_subnumber *1 < 0 ) {
1137 var r = eventdata.cell[0] + 1;
1140 if (r > _this.grid.ds.getCount()-1 ) {
1141 eventdata.cell = false;
1144 rec = _this.grid.ds.getAt(r);
1145 if (rec.data.coitem_subnumber *1 < 0 ) {
1146 eventdata.cell = [ r, eventdata.cell[1] ];
1163 beforeload : function (_self,o) {
1169 Roo.log(_this.data);
1170 if (!_this.data || !_this.data.cmhead_id) {
1173 o.params = o.params || {};
1174 Roo.log(_this.data);
1175 o.params.cmitem_cmhead_id = _this.data.cmhead_id;
1176 o.params.limit = 999;
1179 update : function (_self, rec, operation)
1182 if (operation != Roo.data.Record.COMMIT) {
1186 // row has been updated..
1187 // if the qty + item has been filled in, we should try and save it..
1188 if (!(rec.data.cmitem_itemsite_id * 1) || !(rec.data.cmitem_qtycredit*1) || !(rec.data.cmitem_unitprice*1)) {
1189 Roo.log('not saving - row not completed');
1193 if (_this.itemsUpdating) {
1194 Roo.log('currently updating?');
1197 _this.itemsUpdating = true;
1200 Roo.log('Running update');
1203 url : baseURL+'/Roo/Cmitem',
1207 success: function(res)
1209 Roo.log('GOT success');
1210 // update the data...
1211 if (rec.data.item_type == 'K') {
1212 _this.itemsUpdating = false;
1213 _this.grid.ds.load({});
1216 if (_this.grid.activeEditor) {
1219 rec.set('cmitem_id', res.data.cmitem_id);
1221 _this.itemsUpdating = false;
1223 if(_this.hasQuery != 0){
1229 delete rec.modified;
1231 _this.grid.loadAvail();
1234 failure : function(res)
1236 Roo.MessageBox.alert(res.message);
1237 _this.itemsUpdating = false;
1248 load : function (_self, records, options)
1250 // need to fetch availablity from master data..
1251 // build a list of what to ask..
1253 // query: ITEM CODE - LOCATION
1255 //_this.grid.loadAvail.defer(100, _this.grid);
1258 Roo.each(records, function(r){
1260 if(r.data.cmitem_taxtype_id == r.data.cmitem_taxable_id ){
1261 rate = _this.form.findField('taxzone_rate').getValue();
1263 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1));
1264 r.set('cmitem_tax_listprice', r.data.cmitem_item_listprice * (1 + rate * 1));
1265 r.set('cmitem_line_tax_value', r.data.cmitem_line_value * (1 + rate * 1));
1271 sortInfo : { field : 'cmitem_linenumber', direction: 'ASC' },
1276 url : baseURL + '/Roo/Cmitem.php'
1279 xtype: 'JsonReader',
1281 totalProperty : 'total',
1286 'name': 'coitem_linenumber',
1290 'name': 'coitem_itemsite_id',
1294 'name': 'coitem_qtyord'
1297 'name': 'coitem_unitcost'
1300 'name': 'coitem_price'
1303 'name': 'coitem_custprice'
1306 'name': 'coitem_qtyreturned'
1309 'name': 'coitem_prcost'
1312 'name': 'coitem_price_uom_id',
1316 'name': 'coitem_qtyreserved'
1333 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1334 Roo.MessageBox.alert("Error", "credit memo is already posted");
1339 var grid = _this.grid;
1342 _this.grid.ds.each(function(r) {
1343 last = r.data.cmitem_linenumber;
1348 var nr = _this.grid.ds.reader.newRow({
1349 cmitem_linenumber : last,
1352 cmitem_cmhead_id : _this.form.findField('cmhead_id').getValue(),
1353 cmitem_comments : '',
1354 cmitem_taxtype_id : _this.data.default_taxtype_id,
1355 cmitem_taxtype_id_taxtype_name : 'Taxable'
1358 grid.ds.insert(grid.ds.getCount(), nr);
1359 grid.startEditing(grid.ds.getCount()-1, 1); // type..
1361 render : function (_self)
1363 _this.addItemBtn = _self;
1366 cls : 'x-btn-text-icon',
1368 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
1374 click : function (_self, e)
1378 _this.grid.ds.each(function(r) {
1379 last = r.data.cmitem_linenumber +1;
1384 var grid = _this.grid;
1385 var ct = _this.grid.ds.getCount();
\r
1386 var lastrow = ct ? _this.grid.ds.getAt(ct-1) : false;
\r
1388 var cmhead_cust_id = _this.form.findField('cmhead_cust_id').getValue();
1389 var cmhead_id = _this.form.findField('cmhead_id').getValue();
1391 Pman.Dialog.XtupleSalesProductList.show( {cohead_cust_id : cmhead_cust_id, cmhead_id : cmhead_id} , function(res) {
1398 if (!lr.data.cmitem_itemsite_id) {
1399 lr.set('cmitem_itemsite_id', res.item_itemsite_id_itemsite_id);
1400 lr.set('item_number', res.item_number);
1401 lr.set('item_descrip1', res.item_descrip1);
1402 lr.set('cmitem_comments', res.item_descrip1);
1403 lr.set('cmitem_cmhead_id', _this.form.findField('cmhead_id').getValue());
1407 var rate = _this.form.findField('taxzone_rate').getValue();
\r
1408 var nr = grid.ds.reader.newRow({
1409 cmitem_linenumber : last,
1410 cmitem_itemsite_id : res.item_itemsite_id_itemsite_id,
1411 item_number : res.item_number,
1412 item_descrip1 : res.item_descrip1 ,
1413 cmitem_cmhead_id : _this.form.findField('cmhead_id').getValue(),
1414 cmitem_comments : res.item_descrip1,
1415 cmitem_tax_listprice : res.item_price * ( 1 + rate * 1),
1416 cmitem_item_listprice : res.item_price,
1417 cmitem_tax_unitprice : res.item_price * ( 1 + rate * 1),
1418 cmitem_unitprice : res.item_price,
1419 cmitem_qtycredit : 1,
1420 cmitem_line_value : res.item_price,
1421 cmitem_line_tax_value : res.item_price * ( 1 + rate * 1)
1424 grid.ds.insert(grid.ds.getCount(), nr);
1426 var ar = grid.ds.getAt(grid.ds.getCount() - 1);
1432 cls : 'x-btn-text-icon',
1433 text : "Find Products",
1434 icon : rootURL + '/Pman/templates/images/search.gif'
1442 var cmhead_id = 1 * _this.form.findField('cmhead_id').getValue();
1444 Roo.MessageBox.alert("Error", "Save credit memo first!");
1450 url : baseURL + '/Roo/Metasql',
1456 'cmhead_id:number' : cmhead_id,
1466 cls : 'x-btn-text-icon',
1467 text : "Download Excel",
1468 icon : rootURL + '/Pman/templates/images/spreadsheet.gif'
1474 click : function (_self, e)
1477 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1478 Roo.MessageBox.alert("Error", "credit memo is already posted");
1482 Pman.Dialog.Image.show(
1484 _url : baseURL + '/Xtuple/Import/CreditMemo',
1485 onid : _this.form.findField('cmhead_id').getValue()
1489 _this.grid.ds.load({});
\r
1493 render : function (_self)
1495 _this.uploadBtn = _self;
1498 cls : 'x-btn-text-icon',
1499 text : "Upload Excel",
1500 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
1512 _this.grid.stopEditing();
1513 // check that no shipments or invoices are done..
1514 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1515 Roo.MessageBox.alert("Error", "credit memo is already posted");
1518 // check that no shipments or invoices are done..
1519 var rc = _this.grid.getSelectionModel().getSelectedCell();
1521 var rec = _this.grid.ds.getAt(rc[0]);
1523 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that line?", function(r)
1531 if (!rec.data.cmitem_id) {
1532 _this.grid.ds.remove(rec);
1538 url : baseURL + '/Roo/cmitem',
1541 _delete : rec.data.cmitem_id
1544 success : function() {
1545 if (rec.data.item_type == 'K') {
1546 _this.grid.ds.load({});
1549 _this.grid.ds.remove(rec);
1559 cls : 'x-btn-text-icon',
1561 icon : rootURL + '/Pman/templates/images/trash.gif'
1567 xtype: 'ColumnModel',
1569 dataIndex : 'cmitem_linenumber',
1572 renderer : function(v,x,r) {
1574 if (r.data.coitem_subnumber * 1 > 0) {
1575 return String.format('{0}.{1}', v,r.data.coitem_subnumber);
1577 return String.format('{0}', v);
1581 xtype: 'ColumnModel',
1583 dataIndex : 'item_number',
1584 header : 'Item Code',
1586 renderer : function(v) { return String.format('{0}', v); },
1588 xtype: 'GridEditor',
1594 beforeselect : function (combo, record, index)
1596 // set _this.data values ..
1597 var ar = _this.grid.activeEditor.record;
1598 //Roo.log('beforeselect');
1600 var rate = _this.form.findField('taxzone_rate').getValue();
1604 ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
1605 ar.set('cmitem_comments', record.data.itemsite_item_id_item_descrip1);
1606 ar.set('cmitem_tax_listprice', record.data.item_listprice * ( 1 + rate * 1) );
1607 ar.set('cmitem_item_listprice', record.data.item_listprice * 1);
1608 ar.set('cmitem_tax_unitprice', record.data.item_price * ( 1 + rate * 1) );
1609 ar.set('cmitem_unitprice', record.data.item_price * 1);
1610 ar.set('cmitem_qtycredit', 1);
1611 ar.set('cmitem_line_value', record.data.item_price * ar.data.cmitem_qtycredit);
1612 ar.set('cmitem_line_tax_value', ar.data.cmitem_tax_unitprice * ar.data.cmitem_qtycredit);
1613 ar.set('cmitem_itemsite_id', record.data.itemsite_id);
1614 ar.set('item_number', record.data.itemsite_item_id_item_number);
1615 ar.set('item_type', record.data.itemsite_item_id_item_type);
1616 ar.set('avail_qty', 0);
1617 // ar.updateFields = ['All'];
1624 displayField : 'itemsite_item_id_item_number',
1626 emptyText : "Select item",
1627 forceSelection : true,
1628 hiddenName : 'itemsite_item_id_item_number',
1630 loadingText : "Searching...",
1632 name : 'item_number',
1634 qtip : "Select item",
1635 queryParam : 'query[number]',
1636 selectOnFocus : true,
1637 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>',
1638 triggerAction : 'all',
1640 valueField : 'item_number',
1645 beforeload : function (_self, o){
1646 o.params = o.params || {};
1647 o.params.customer_id = _this.form.findField('cmhead_cust_id').getValue();
1648 o.params['query[cmhead_id]'] = _this.form.findField('cmhead_id').getValue();
1649 //o.params.shipto_cust_id = _this.data.cohead_cust_id;
1654 sortInfo : { direction : 'ASC', field: 'item_number' },
1659 url : baseURL + '/Roo/itemsite.php'
1662 xtype: 'JsonReader',
1666 totalProperty : 'total',
1667 fields : [{'name':'item_id','type':'int'},'item_number']
1674 xtype: 'ColumnModel',
1676 dataIndex : 'cmitem_comments',
1677 header : 'Item Description',
1679 renderer : function(v,x,r) {
1682 r.set('cmitem_comments', r.data.item_descrip1);
1683 v = r.data.item_descrip1;
1685 if (v && v.length > 49) {
1686 return String.format('<span style="color:orange" qtip="line may be too long to print">{0}</span>', v);
1688 return String.format('{0}', v);
1692 xtype: 'GridEditor',
1702 xtype: 'ColumnModel',
1705 dataIndex : 'cmitem_qtycredit',
1708 renderer : function(v)
1710 return String.format('{0}', v ? parseInt(v) : '');
1713 xtype: 'GridEditor',
1716 xtype: 'NumberField',
1719 focus : function (_self)
1721 if (this.value == 0) {
1722 this.el.dom.value = '';
1726 allowDecimals : false,
1727 decimalPrecision : 0,
1729 style : 'text-align:right'
1734 xtype: 'ColumnModel',
1737 dataIndex : 'cmitem_tax_listprice',
1738 header : 'List Price w. tax',
1740 renderer : function(v,x,r)
1742 // var rate = _this.form.findField('taxzone_rate').getValue();
1743 // v = v * (1 + rate * 1);
1745 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1749 xtype: 'ColumnModel',
1752 dataIndex : 'cmitem_taxtype_id',
1755 renderer : function(v,x,r) { return String.format('{0}', r.data.cmitem_taxtype_id_taxtype_name); },
1757 xtype: 'GridEditor',
1763 displayField : 'taxtype_name',
1765 emptyText : "Select Tax Type",
1766 forceSelection : true,
1767 hiddenName : 'cmitem_taxtype_id',
1769 loadingText : "Searching...",
1771 name : 'cmitem_taxtype_id_taxtype_name',
1773 qtip : "Select taxtype",
1774 queryParam : 'query[taxtype_id]',
1775 selectOnFocus : true,
1776 tpl : '<div class="x-grid-cell-text x-btn button"><b>{taxtype_name}</b> </div>',
1777 triggerAction : 'all',
1779 valueField : 'taxtype_id',
1785 beforeload : function (_self, o){
1786 o.params = o.params || {};
1789 /* o.params.with_date = _this.form.findField('cohead_orderdate').getValue().format('Y-m-d');
1790 Roo.log("with date?" + o.params.with_date);*/
1796 sortInfo : { direction : 'ASC', field: 'taxtype_name' },
1801 url : baseURL + '/Roo/taxtype.php'
1804 xtype: 'JsonReader',
1808 totalProperty : 'total',
1809 fields : [{'name':'taxtype_id','type':'int'},'taxtype_name']
1816 xtype: 'ColumnModel',
1819 dataIndex : 'cmitem_tax_unitprice',
1820 header : 'Unit Price w. tax',
1822 renderer : function(v,x,r)
1824 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1827 xtype: 'GridEditor',
1830 xtype: 'NumberField',
1833 focus : function (_self)
1835 if (this.value == 0.0) {
1836 this.el.dom.value = '';
1840 decimalPrecision : 2,
1842 style : 'text-align:right'
1847 xtype: 'ColumnModel',
1850 dataIndex : 'cmitem_unitprice',
1851 header : 'Unit Price',
1853 renderer : function(v)
1855 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1858 xtype: 'GridEditor',
1861 xtype: 'NumberField',
1864 focus : function (_self)
1866 if (this.value == 0.0) {
1867 this.el.dom.value = '';
1871 decimalPrecision : 2,
1873 style : 'text-align:right'
1878 xtype: 'ColumnModel',
1881 dataIndex : 'cmitem_line_value',
1884 renderer : function(v)
1886 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1891 dataIndex : 'cmitem_line_tax_value',
1892 header : 'Total w. tax',
1894 renderer : function(v,x,r)
1896 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1907 activate : function() {
1908 _this.cpanel = this;
1910 var id = _this.form.findField('cmhead_id').getValue() * 1;
1912 Roo.MessageBox.alert("Error", "save the credit memo first!");
1913 _this.dialog.layout.getRegion('center').showPanel(0);
1918 _this.cgrid.footer.onClick('first');
1923 fitContainer : true,
1926 tableName : 'checkitem',
1927 title : "Miscellaneous Check",
1935 //_this.dialog = Pman.Dialog.FILL_IN
1936 if (_this.cpanel.active) {
1937 this.footer.onClick('first');
1941 autoExpandColumn : 'checkitem_checkhead_id_checkhead_notes',
1947 beforeload : function (_self, options)
1949 options.params = options.params || {};
1950 options.params.checkitem_cmnumber = _this.form.findField('cmhead_number').getValue();
1954 sortInfo : { field : 'checkitem_id', direction: 'DESC' },
1959 url : baseURL + '/Roo/checkitem.php'
1962 xtype: 'JsonReader',
1966 totalProperty : 'total',
1985 'name': 'leader_id',
1989 'name': 'leader_office_id',
1993 'name': 'leader_name',
1997 'name': 'leader_phone',
2001 'name': 'leader_fax',
2005 'name': 'leader_email',
2009 'name': 'leader_company_id',
2013 'name': 'leader_role',
2017 'name': 'leader_active',
2021 'name': 'leader_remarks',
2025 'name': 'leader_passwd',
2029 'name': 'leader_owner_id',
2033 'name': 'leader_lang',
2037 'name': 'leader_no_reset_sent',
2041 'name': 'leader_action_type',
2045 'name': 'leader_project_id',
2049 'name': 'leader_deleted_by',
2053 'name': 'leader_deleted_dt',
2057 'name': 'leader_firstname',
2061 'name': 'leader_lastname',
2065 'name': 'leader_name_facebook',
2069 'name': 'leader_url_blog',
2073 'name': 'leader_url_twitter',
2077 'name': 'leader_url_linkedin',
2081 'name': 'leader_crm_lead_percentage',
2085 'name': 'leader_crm_industry_id',
2089 'name': 'leader_crm_updated_action_id',
2093 'name': 'leader_crm_created_action_id',
2097 'name': 'leader_crm_type_id',
2104 xtype: 'PagingToolbar',
2107 displayMsg : "Displaying check item{0} - {1} of {2}",
2108 emptyMsg : "No check item found",
2113 xtype: 'ColumnModel',
2115 dataIndex : 'checkitem_docdate',
2118 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
2121 xtype: 'ColumnModel',
2123 dataIndex : 'checkitem_bankaccnt_id_bankaccnt_name',
2124 header : 'Bank Account',
2126 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2129 xtype: 'ColumnModel',
2131 dataIndex : 'checkitem_checkhead_id_checkhead_for',
2134 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2137 xtype: 'ColumnModel',
2139 dataIndex : 'checkitem_checkhead_id_checkhead_notes',
2142 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2145 xtype: 'ColumnModel',
2148 dataIndex : 'checkitem_curr_id_curr_name',
2149 header : 'Currency',
2151 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2154 xtype: 'ColumnModel',
2157 dataIndex : 'checkitem_amount',
2160 renderer : function(v) { return String.format('{0}', v ? parseFloat(v).toFixed(2) : ''); }
2169 activate : function() {
2170 _this.apanel = this;
2172 _this.agrid.footer.onClick('first');
2177 fitContainer : true,
2180 tableName : 'invchead',
2181 title : "Applications",
2189 //_this.dialog = Pman.Dialog.FILL_IN
2190 if (_this.apanel.active) {
2191 this.footer.onClick('first');
2195 autoExpandColumn : 'arapply_target_docnumber',
2201 beforeload : function (_self,o) {
2207 if (!_this.data || !_this.data.cmhead_id) {
2210 o.params = o.params || {};
2212 o.params._application = _this.data.cmhead_id
2217 sortInfo : { field : 'arapply_id', direction: 'ASC' },
2222 url : baseURL + '/Roo/Arapply.php'
2225 xtype: 'JsonReader',
2227 totalProperty : 'total',
2248 'name': 'leader_id',
2252 'name': 'leader_office_id',
2256 'name': 'leader_name',
2260 'name': 'leader_phone',
2264 'name': 'leader_fax',
2268 'name': 'leader_email',
2272 'name': 'leader_company_id',
2276 'name': 'leader_role',
2280 'name': 'leader_active',
2284 'name': 'leader_remarks',
2288 'name': 'leader_passwd',
2292 'name': 'leader_owner_id',
2296 'name': 'leader_lang',
2300 'name': 'leader_no_reset_sent',
2304 'name': 'leader_action_type',
2308 'name': 'leader_project_id',
2312 'name': 'leader_deleted_by',
2316 'name': 'leader_deleted_dt',
2320 'name': 'leader_firstname',
2324 'name': 'leader_lastname',
2328 'name': 'leader_name_facebook',
2332 'name': 'leader_url_blog',
2336 'name': 'leader_url_twitter',
2340 'name': 'leader_url_linkedin',
2344 'name': 'leader_crm_lead_percentage',
2348 'name': 'leader_crm_industry_id',
2352 'name': 'leader_crm_updated_action_id',
2356 'name': 'leader_crm_created_action_id',
2360 'name': 'leader_crm_type_id',
2367 xtype: 'PagingToolbar',
2370 displayMsg : "Displaying application{0} - {1} of {2}",
2371 emptyMsg : "No application found",
2376 xtype: 'ColumnModel',
2378 dataIndex : 'arapply_id',
2381 renderer : function(v) { return String.format('{0}', v); }
2384 xtype: 'ColumnModel',
2386 dataIndex : 'arapply_distdate',
2389 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
2392 xtype: 'ColumnModel',
2394 dataIndex : 'arapply_target_doctype',
2395 header : 'Target Doctype',
2397 renderer : function(v) { return String.format('{0}', v); }
2400 xtype: 'ColumnModel',
2402 dataIndex : 'arapply_target_docnumber',
2403 header : 'Target Docnumber',
2405 renderer : function(v) { return String.format('{0}', v); }
2408 xtype: 'ColumnModel',
2410 dataIndex : 'arapply_curr_id_curr_name',
2411 header : 'Currency',
2413 renderer : function(v) { return String.format('{0}', v); }
2416 xtype: 'ColumnModel',
2418 dataIndex : 'arapply_applied',
2421 renderer : function(v) { return String.format('{0}', v); }
2430 activate : function() {
2431 _this.hpanel = this;
2433 _this.hgrid.footer.onClick('first');
2438 fitContainer : true,
2441 tableName : 'events',
2450 //_this.dialog = Pman.Dialog.FILL_IN
2451 if (_this.hpanel.active) {
2452 this.footer.onClick('first');
2455 rowdblclick : function (_self, rowIndex, e)
2457 if (!_this.dialog) return;
2458 _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
2459 _this.grid.footer.onClick('first');
2463 autoExpandColumn : 'remarks',
2469 beforeload : function (_self, options)
2471 options.params._related_on_table = 'cmhead';
2472 options.params._related_on_id = _this.form.findField('cmhead_id').getValue();
2477 sortInfo : { field : 'event_when', direction: 'DESC' },
2482 url : baseURL + '/Roo/events.php'
2485 xtype: 'JsonReader',
2487 totalProperty : 'total',
2492 'name': 'event_when',
2504 'name': 'person_id_name',
2515 xtype: 'PagingToolbar',
2519 displayMsg : "Displaying events{0} - {1} of {2}",
2520 emptyMsg : "No events found"
2524 xtype: 'ColumnModel',
2526 dataIndex : 'event_when',
2529 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); }
2532 xtype: 'ColumnModel',
2534 dataIndex : 'action',
2537 renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); }
2540 xtype: 'ColumnModel',
2542 dataIndex : 'ipaddr',
2543 header : 'IP address',
2545 renderer : function(v) { return String.format('{0}', v); }
2548 xtype: 'ColumnModel',
2550 dataIndex : 'person_id_name',
2553 renderer : function(v) { return String.format('{0}', v); }
2556 xtype: 'ColumnModel',
2558 dataIndex : 'remarks',
2561 renderer : function(v) { return String.format('{0}', v); }
2568 xtype: 'LayoutRegion',
2570 alwaysShowTabs : true,
2578 click : function (_self, e)
2580 if (_this.grid) _this.grid.stopEditing();
2581 _this.dialog.hide();
2590 click : function (_self, e)
2593 if (_this.grid) _this.grid.stopEditing();
2594 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
2595 Roo.MessageBox.alert("Error", "credit memo is already posted");
2600 if (_this.grid && _this.grid.ds) {
2601 _this.grid.ds.each(function(rec) {
2602 if (!(rec.data.cmitem_itemsite_id * 1) || !(rec.data.cmitem_qtycredit*1) || !(rec.data.cmitem_unitprice*1)) {
2610 Roo.MessageBox.alert("Error", "Some lines do not have product/qty/price set");
2615 _this.form.findField('has_item').setValue(ar.length);
2618 _this.form.doAction("submit");
2620 render : function (_self)
2622 _this.saveBtn = _self;