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) +
644 (1*vals.cmhead_taxfree_value) +
645 (1*vals.cmhead_freight) +
646 (1*vals.cmhead_tax_value) +
661 style : 'width:420px',
673 beforeselect : function (combo, record, index)
675 // set _this.data values ..
677 // just add everything...
678 for(var i in record.data) {
679 // Roo.log('cmhead_billto_cntct_id_' + i +' =' + record.data[i]);
680 _this.data['cmhead_billto_cntct_id_' + i] = record.data[i];
683 _this.form.findField('billto_address').update();
687 add : function (combo)
690 Pman.Dialog.XtupleQuickContact.show(
693 customer_id : _this.form.findField('cmhead_cust_id').getValue()
700 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
703 _this.form.findField('billto_address').update();
704 // fill in the select box..
705 _this.form.setValues( {
706 cmhead_billto_cntct_id : data.cntct_id,
707 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
713 // Pman.Dialog.XtupleCustomer.show(
714 //{ cust_id : _this.form.findField('cohead_cust_id').getValue() },
716 // refresh the data in the pulldown..
723 displayField : 'cntct_name',
725 emptyText : "Select Contact",
726 fieldLabel : 'Bill To (select)',
727 forceSelection : true,
728 hiddenName : 'cmhead_billto_cntct_id',
730 loadingText : "Searching...",
732 name : 'cmhead_billto_cntct_id_cntct_name',
734 qtip : "Select Contact",
735 queryParam : 'query[cntct_name]',
736 selectOnFocus : true,
737 tpl : '<div class="x-grid-cell-text x-btn button"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>',
738 triggerAction : 'all',
740 valueField : 'cntct_id',
746 beforeload : function (_self, o){
747 o.params = o.params || {};
749 o.params._customer_id = _this.data.cmhead_cust_id;
753 sortInfo : { direction : 'ASC', field: 'cntct_name' },
758 url : baseURL + '/Roo/cntct.php'
765 totalProperty : 'total',
766 fields : [{'name':'cntct_id','type':'int'},'cntct_name']
774 render : function (_self)
780 this.el.on('click', function() {
781 var id = _this.form.findField('cmhead_billto_cntct_id').getValue();
782 Pman.Dialog.XtupleQuickContact.show(
785 customer_id : _this.form.findField('cmhead_cust_id').getValue()
792 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
795 _this.form.findField('billto_address').update();
796 // fill in the select box..
797 _this.form.setValues( {
798 cmhead_billto_cntct_id : data.cntct_id,
799 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
807 fieldLabel : 'or enter Address',
808 name : 'billto_address',
810 update : function() {
812 var c = ['first_name', 'last_name' ] ;
813 var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
815 Roo.each(c, function(e) {
816 if (_this.data['cmhead_billto_cntct_id_cntct_' +e] &&
817 _this.data['cmhead_billto_cntct_id_cntct_' +e].length) {
818 v.push(_this.data['cmhead_billto_cntct_id_cntct_' +e]);
821 Roo.each(a, function(e) {
822 if (_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e] &&
823 _this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e].length) {
824 v.push(_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e]);
827 this.setValue(v.join("\n"));
844 name : 'cmhead_billto_addr_id'
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;