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 : 'Items Value',
360 name : 'cmhead_value',
370 labelSeparator : ' ',
377 displayField : 'curr_name',
379 emptyText : "Select Currency",
380 fieldLabel : 'Currency',
381 forceSelection : true,
382 hiddenName : 'cmhead_curr_id',
384 loadingText : "Searching...",
386 name : 'cmhead_curr_id_curr_name',
388 qtip : "Select Currency",
389 queryParam : 'query[curr_name]',
390 selectOnFocus : true,
391 tpl : '<div class="x-grid-cell-text x-btn button"><b>{curr_name}</b> </div>',
392 triggerAction : 'all',
394 valueField : 'curr_id',
400 beforeload : function (_self, o){
401 o.params = o.params || {};
407 sortInfo : { direction : 'ASC', field: 'curr_symbol' },
412 url : baseURL + '/Roo/curr_symbol.php'
419 totalProperty : 'total',
420 fields : [{'name':'curr_id','type':'int'},'curr_symbol']
425 xtype: 'NumberField',
428 keyup : function (_self, e)
430 _this.form.findField('cmhead_total').recalc();
433 allowDecimals : true,
434 cls : 'roo-align-right',
435 decimalPrecision : 3,
436 fieldLabel : 'Freight',
437 name : 'cmhead_freight',
446 labelSeparator : ' ',
452 fieldLabel : 'Discount Description',
453 name : 'cmhead_misc_descrip',
457 xtype: 'NumberField',
460 keyup : function (_self, e)
462 var m = _this.form.findField('cmhead_misc');
463 var pv = _this.form.findField('cmhead_value').getValue();
464 var n = this.getValue();
465 var discount = parseInt(n * pv * 0.01);
466 m.setValue(discount * -1.000);
469 _this.form.findField('cmhead_total').recalc();
470 var val = discount * -1.0;
472 _this.form.findField('cohead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
476 allowDecimals : true,
477 cls : 'roo-align-right',
478 decimalPrecision : 1,
480 name : 'cmhead_misc_per',
482 update : function() {
483 var m = _this.form.findField('cmhead_misc_per');
484 var pv = parseFloat(_this.form.findField('cmhead_value').getValue());
485 var discount = parseFloat(_this.form.findField('cmhead_misc').getValue());
487 if (discount > 0.0) {
495 var val = ((discount) / pv) * -100;
497 //Roo.log("update discount?" + val);
498 this.setValue(val.toFixed(1));
501 _this.form.findField('cmhead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
509 xtype: 'NumberField',
512 keyup : function (_self, e)
514 _this.form.findField('cmhead_misc_per').update();
515 _this.form.findField('cmhead_total').recalc();
518 allowDecimals : true,
519 cls : 'roo-align-right',
520 decimalPrecision : 3,
521 fieldLabel : ' ',
522 name : 'cmhead_misc',
531 labelSeparator : ' ',
538 select : function (combo, record, index)
540 _this.form.findField('cmhead_tax_value').setValue(
541 record.data.taxzone_rate * _this.form.findField('cmhead_taxable_value').getValue()
546 displayField : 'taxzone_descrip',
548 emptyText : "Select tax zone",
549 fieldLabel : 'Tax Zone',
550 forceSelection : true,
551 hiddenName : 'cmhead_taxzone_id',
553 loadingText : "Searching...",
555 name : 'cmhead_taxzone_id_taxzone_descrip',
557 qtip : "Select tax zone",
558 queryParam : 'query[taxzone_descrip]',
559 selectOnFocus : true,
560 tpl : '<div class="x-grid-cell-text x-btn button"><b>{taxzone_descrip}</b> </div>',
561 triggerAction : 'all',
563 valueField : 'taxzone_id',
569 beforeload : function (_self, o){
570 o.params = o.params || {};
573 o.params.with_date = _this.form.findField('cmhead_docdate').getValue().format('Y-m-d');
574 Roo.log("with date?" + o.params.with_date);
580 sortInfo : { direction : 'ASC', field: 'taxzone_descrip' },
585 url : baseURL + '/Roo/taxzone.php'
592 totalProperty : 'total',
593 fields : [{'name':'taxzone_id','type':'int'},'taxzone_descrip']
598 xtype: 'NumberField',
600 allowDecimals : true,
601 cls : 'roo-align-right',
602 decimalPrecision : 3,
604 name : 'cmhead_tax_value',
613 labelAlign : 'right',
618 xtype: 'NumberField',
620 allowDecimals : true,
621 cls : 'roo-align-right',
622 decimalPrecision : 3,
623 fieldLabel : 'Total',
624 name : 'cmhead_total',
627 recalc : function() {
628 var vals = _this.form.getValues();
630 (1*vals.cmhead_value) + (1*vals.cmhead_freight) + (1*vals.cmhead_tax_value) + (1*vals.cmhead_misc)
644 style : 'width:420px',
656 beforeselect : function (combo, record, index)
658 // set _this.data values ..
660 // just add everything...
661 for(var i in record.data) {
662 // Roo.log('cmhead_billto_cntct_id_' + i +' =' + record.data[i]);
663 _this.data['cmhead_billto_cntct_id_' + i] = record.data[i];
666 _this.form.findField('billto_address').update();
670 add : function (combo)
673 Pman.Dialog.XtupleQuickContact.show(
676 customer_id : _this.form.findField('cmhead_cust_id').getValue()
683 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
686 _this.form.findField('billto_address').update();
687 // fill in the select box..
688 _this.form.setValues( {
689 cmhead_billto_cntct_id : data.cntct_id,
690 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
696 // Pman.Dialog.XtupleCustomer.show(
697 //{ cust_id : _this.form.findField('cohead_cust_id').getValue() },
699 // refresh the data in the pulldown..
706 displayField : 'cntct_name',
708 emptyText : "Select Contact",
709 fieldLabel : 'Bill To (select)',
710 forceSelection : true,
711 hiddenName : 'cmhead_billto_cntct_id',
713 loadingText : "Searching...",
715 name : 'cmhead_billto_cntct_id_cntct_name',
717 qtip : "Select Contact",
718 queryParam : 'query[cntct_name]',
719 selectOnFocus : true,
720 tpl : '<div class="x-grid-cell-text x-btn button"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>',
721 triggerAction : 'all',
723 valueField : 'cntct_id',
729 beforeload : function (_self, o){
730 o.params = o.params || {};
732 o.params._customer_id = _this.data.cmhead_cust_id;
736 sortInfo : { direction : 'ASC', field: 'cntct_name' },
741 url : baseURL + '/Roo/cntct.php'
748 totalProperty : 'total',
749 fields : [{'name':'cntct_id','type':'int'},'cntct_name']
757 render : function (_self)
763 this.el.on('click', function() {
764 var id = _this.form.findField('cmhead_billto_cntct_id').getValue();
765 Pman.Dialog.XtupleQuickContact.show(
768 customer_id : _this.form.findField('cmhead_cust_id').getValue()
775 _this.data['cmhead_billto_cntct_id_' + i] = data[i];
778 _this.form.findField('billto_address').update();
779 // fill in the select box..
780 _this.form.setValues( {
781 cmhead_billto_cntct_id : data.cntct_id,
782 cmhead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+
790 fieldLabel : 'or enter Address',
791 name : 'billto_address',
793 update : function() {
795 var c = ['first_name', 'last_name' ] ;
796 var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
798 Roo.each(c, function(e) {
799 if (_this.data['cmhead_billto_cntct_id_cntct_' +e] &&
800 _this.data['cmhead_billto_cntct_id_cntct_' +e].length) {
801 v.push(_this.data['cmhead_billto_cntct_id_cntct_' +e]);
804 Roo.each(a, function(e) {
805 if (_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e] &&
806 _this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e].length) {
807 v.push(_this.data['cmhead_billto_cntct_id_cntct_addr_id_addr_' +e]);
810 this.setValue(v.join("\n"));
827 name : 'cmhead_billto_addr_id'
832 name : 'cmhead_taxable_value'
837 name : 'cmhead_posted'
842 name : 'cmhead_cust_id'
847 name : 'taxzone_rate'
862 deactivate : function (_self)
865 _this.grid.stopEditing();
868 activate : function (_self)
873 try { if (MODULE.isBuilder) {
877 var id = _this.form.findField('cmhead_id').getValue() * 1;
879 Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
880 _this.dialog.layout.getRegion('center').showPanel(0);
884 _this.grid.ds.load({});
893 tableName : 'coitem',
894 title : "Credit Items",
903 //_this.dialog = Pman.Dialog.FILL_IN
904 if (_this.panel.active) {
908 afteredit : function (e)
910 //Roo.log('afteredit');
913 if (e.field == 'item_number' || e.originalValue == e.value) {
914 // afterselect handles this...
919 if ( r && r.data.cmitem_id) {
920 // as we disable update to the display on the ajax callback to
921 // allow editing flow to continue, and not refresh - we can only update
922 // these values after something has actually been edited.
923 r.set('coitem_id', r.data.cmitem_id);
927 if(r.data.cmitem_taxtype_id_taxtype_name == 'Taxable' ){
928 rate = _this.form.findField('taxzone_rate').getValue();
930 if(e.field == 'cmitem_tax_unitprice'){
931 r.set('cmitem_unitprice', r.data.cmitem_tax_unitprice * 1 / (1 + rate * 1));
932 // fields.push('cmitem_unitprice');
934 if(e.field == 'cmitem_unitprice'){
935 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1) );
936 // fields.push('cmitem_tax_unitprice');
938 if(e.field == 'cmitem_taxtype_id'){
939 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1) );
940 // fields.push('cmitem_tax_unitprice');
943 r.set('cmitem_tax_listprice', r.data.cmitem_item_listprice * (1 + rate * 1) );
944 // fields.push('cmitem_tax_listprice');
945 r.set('cmitem_line_value', r.data.cmitem_qtycredit * r.data.cmitem_unitprice );
946 // fields.push('cmitem_line_value');
947 r.set('cmitem_line_tax_value', r.data.cmitem_qtycredit * r.data.cmitem_tax_unitprice );
948 // fields.push('cmitem_line_tax_value');
950 // fields.push('cmitem_id');
954 var doupdate = function() {
955 if (!_this.itemsUpdating) {
956 Roo.log('doupdate...');
962 doupdate.defer(1000);
969 beforeedit : function (e)
971 // we can only edit if nothing is assigned to shipping or invoices..
972 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
973 Roo.MessageBox.alert("Error", "credit memo is already posted");
980 // seems below logic is useless...!!!!
983 if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
984 Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
989 if (rec.data.coitem_subnumber * 1 > 0) {
990 Roo.log("Edit container event");
991 Roo.log(e); // if it's a tab..
995 // allow editing of source / destination..
996 case 'coitem_shipto_id':
997 case 'coitem_location_src':
1002 Roo.MessageBox.alert("Error", "That is a kit item, edit the container.");
1006 // zero off values..
1007 //if (e.field == 'coitem_qtyord' && rec.data.coitem_qtyord == 0) {
1010 // if (e.field == 'coitem_custprice' && rec.data.coitem_qtyord == 0.0) {
1014 if (rec.data.item_type == 'K' && e.field == 'item_number') {
1015 // you can not change the product type on kits' as it messing things up..
1016 Roo.MessageBox.alert("Error", "That is a kit item,if you need to change it, delete it first.");
1022 celldblclick : function (_self, rowIndex, columnIndex, e)
1024 var rec = this.ds.getAt(rowIndex);
1025 var di = this.cm.getDataIndex(columnIndex);
1026 if (di != 'avail_qty') {
1029 Pman.Dialog.XtupleInvHistory.show({
1030 itemsite_item_id_item_number : rec.data.item_number,
1031 // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
1032 location_name : rec.data.coitem_location_src_location_name,
1033 location_descrip : rec.data.coitem_location_src_location_descrip,
1035 invhist_transdate : _this.form.findField('cohead_targetdate').getValue()
1039 rowclass : function (gridview, rowcfg)
1041 if (rowcfg.record.data.coitem_status == 'C' &&
1042 rowcfg.record.data.shipitem_shipped * 1 < 1) {
1044 rowcfg.rowClass = 'strikethrough';
1046 if (rowcfg.record.data.coitem_status == 'X' ) {
1048 rowcfg.rowClass = 'strikethrough';
1054 autoExpandColumn : 'cmitem_comments',
1057 loadAvail : function() {
1062 this.ds.each( function(r) {
1064 // only update if we do not have the details.
1065 if (r.data.avail_qty == 0) {
1069 item : r.data.item_number,
1070 loc: r.data.coitem_location_src_location_name,
1071 id: r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '')
1075 // needs to be a post to allow long lists of products..
1078 url : baseURL + '/Roo/itemloc',
1080 mask : "Loading available qty",
1081 maskel : _this.grid.view.el,
1083 _availqty : Roo.encode(q),
1084 curr_id : _this.form.findField('cohead_curr_id').getValue()
1086 success : function(d)
1088 _this.grid.ds.each(function(r) {
1089 var id = r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '');
1092 if (typeof(d.data[id]) == 'undefined') {
1095 r.set('avail_qty', d.data[id].qty);
1096 if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
1097 r.set('coitem_unitcost_in_order_cur', d.data[id].unitcost);
1109 xtype: 'CellSelectionModel',
1112 tabend : function (_self)
1114 _this.addItemBtn.fireEvent('click', _this.addItemBtn);
1116 beforeeditnext : function (eventdata)
1119 // this does not work, as the reload effect cancels editng.
1120 var rec = _this.grid.ds.getAt(eventdata.cell[0]);
1121 if (rec.data.coitem_subnumber *1 < 0 ) {
1124 var r = eventdata.cell[0] + 1;
1127 if (r > _this.grid.ds.getCount()-1 ) {
1128 eventdata.cell = false;
1131 rec = _this.grid.ds.getAt(r);
1132 if (rec.data.coitem_subnumber *1 < 0 ) {
1133 eventdata.cell = [ r, eventdata.cell[1] ];
1150 beforeload : function (_self,o) {
1156 Roo.log(_this.data);
1157 if (!_this.data || !_this.data.cmhead_id) {
1160 o.params = o.params || {};
1161 Roo.log(_this.data);
1162 o.params.cmitem_cmhead_id = _this.data.cmhead_id;
1163 o.params.limit = 999;
1166 update : function (_self, rec, operation)
1169 if (operation != Roo.data.Record.COMMIT) {
1173 // row has been updated..
1174 // if the qty + item has been filled in, we should try and save it..
1175 if (!(rec.data.cmitem_itemsite_id * 1) || !(rec.data.cmitem_qtycredit*1) || !(rec.data.cmitem_unitprice*1)) {
1176 Roo.log('not saving - row not completed');
1180 if (_this.itemsUpdating) {
1181 Roo.log('currently updating?');
1184 _this.itemsUpdating = true;
1187 Roo.log('Running update');
1190 url : baseURL+'/Roo/Cmitem',
1194 success: function(res)
1196 Roo.log('GOT success');
1197 // update the data...
1198 if (rec.data.item_type == 'K') {
1199 _this.itemsUpdating = false;
1200 _this.grid.ds.load({});
1203 if (_this.grid.activeEditor) {
1206 rec.set('cmitem_id', res.data.cmitem_id);
1208 _this.itemsUpdating = false;
1210 if(_this.hasQuery != 0){
1216 delete rec.modified;
1218 _this.grid.loadAvail();
1221 failure : function(res)
1223 Roo.MessageBox.alert(res.message);
1224 _this.itemsUpdating = false;
1235 load : function (_self, records, options)
1237 // need to fetch availablity from master data..
1238 // build a list of what to ask..
1240 // query: ITEM CODE - LOCATION
1242 //_this.grid.loadAvail.defer(100, _this.grid);
1245 Roo.each(records, function(r){
1247 if(r.data.cmitem_taxtype_id == r.data.cmitem_taxable_id ){
1248 rate = _this.form.findField('taxzone_rate').getValue();
1250 r.set('cmitem_tax_unitprice', r.data.cmitem_unitprice * (1 + rate * 1));
1251 r.set('cmitem_tax_listprice', r.data.cmitem_item_listprice * (1 + rate * 1));
1252 r.set('cmitem_line_tax_value', r.data.cmitem_line_value * (1 + rate * 1));
1258 sortInfo : { field : 'cmitem_linenumber', direction: 'ASC' },
1263 url : baseURL + '/Roo/Cmitem.php'
1266 xtype: 'JsonReader',
1268 totalProperty : 'total',
1273 'name': 'coitem_linenumber',
1277 'name': 'coitem_itemsite_id',
1281 'name': 'coitem_qtyord'
1284 'name': 'coitem_unitcost'
1287 'name': 'coitem_price'
1290 'name': 'coitem_custprice'
1293 'name': 'coitem_qtyreturned'
1296 'name': 'coitem_prcost'
1299 'name': 'coitem_price_uom_id',
1303 'name': 'coitem_qtyreserved'
1320 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1321 Roo.MessageBox.alert("Error", "credit memo is already posted");
1326 var grid = _this.grid;
1329 _this.grid.ds.each(function(r) {
1330 last = r.data.cmitem_linenumber;
1335 var nr = _this.grid.ds.reader.newRow({
1336 cmitem_linenumber : last,
1339 cmitem_cmhead_id : _this.form.findField('cmhead_id').getValue(),
1340 cmitem_comments : '',
1341 cmitem_taxtype_id : _this.data.default_taxtype_id,
1342 cmitem_taxtype_id_taxtype_name : 'Taxable'
1345 grid.ds.insert(grid.ds.getCount(), nr);
1346 grid.startEditing(grid.ds.getCount()-1, 1); // type..
1348 render : function (_self)
1350 _this.addItemBtn = _self;
1353 cls : 'x-btn-text-icon',
1355 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
1361 click : function (_self, e)
1365 _this.grid.ds.each(function(r) {
1366 last = r.data.cmitem_linenumber +1;
1371 var grid = _this.grid;
1372 var ct = _this.grid.ds.getCount();
\r
1373 var lastrow = ct ? _this.grid.ds.getAt(ct-1) : false;
\r
1375 var cmhead_cust_id = _this.form.findField('cmhead_cust_id').getValue();
1376 var cmhead_id = _this.form.findField('cmhead_id').getValue();
1378 Pman.Dialog.XtupleSalesProductList.show( {cohead_cust_id : cmhead_cust_id, cmhead_id : cmhead_id} , function(res) {
1385 if (!lr.data.cmitem_itemsite_id) {
1386 lr.set('cmitem_itemsite_id', res.item_itemsite_id_itemsite_id);
1387 lr.set('item_number', res.item_number);
1388 lr.set('item_descrip1', res.item_descrip1);
1389 lr.set('cmitem_comments', res.item_descrip1);
1390 lr.set('cmitem_cmhead_id', _this.form.findField('cmhead_id').getValue());
1394 var rate = _this.form.findField('taxzone_rate').getValue();
\r
1395 var nr = grid.ds.reader.newRow({
1396 cmitem_linenumber : last,
1397 cmitem_itemsite_id : res.item_itemsite_id_itemsite_id,
1398 item_number : res.item_number,
1399 item_descrip1 : res.item_descrip1 ,
1400 cmitem_cmhead_id : _this.form.findField('cmhead_id').getValue(),
1401 cmitem_comments : res.item_descrip1,
1402 cmitem_tax_listprice : res.item_price * ( 1 + rate * 1),
1403 cmitem_item_listprice : res.item_price,
1404 cmitem_tax_unitprice : res.item_price * ( 1 + rate * 1),
1405 cmitem_unitprice : res.item_price,
1406 cmitem_qtycredit : 1,
1407 cmitem_line_value : res.item_price,
1408 cmitem_line_tax_value : res.item_price * ( 1 + rate * 1)
1411 grid.ds.insert(grid.ds.getCount(), nr);
1413 var ar = grid.ds.getAt(grid.ds.getCount() - 1);
1419 cls : 'x-btn-text-icon',
1420 text : "Find Products",
1421 icon : rootURL + '/Pman/templates/images/search.gif'
1429 var cmhead_id = 1 * _this.form.findField('cmhead_id').getValue();
1431 Roo.MessageBox.alert("Error", "Save credit memo first!");
1437 url : baseURL + '/Roo/Metasql',
1443 'cmhead_id:number' : cmhead_id,
1453 cls : 'x-btn-text-icon',
1454 text : "Download Excel",
1455 icon : rootURL + '/Pman/templates/images/spreadsheet.gif'
1461 click : function (_self, e)
1464 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1465 Roo.MessageBox.alert("Error", "credit memo is already posted");
1469 Pman.Dialog.Image.show(
1471 _url : baseURL + '/Xtuple/Import/CreditMemo',
1472 onid : _this.form.findField('cmhead_id').getValue()
1476 _this.grid.ds.load({});
\r
1480 render : function (_self)
1482 _this.uploadBtn = _self;
1485 cls : 'x-btn-text-icon',
1486 text : "Upload Excel",
1487 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
1499 _this.grid.stopEditing();
1500 // check that no shipments or invoices are done..
1501 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
1502 Roo.MessageBox.alert("Error", "credit memo is already posted");
1505 // check that no shipments or invoices are done..
1506 var rc = _this.grid.getSelectionModel().getSelectedCell();
1508 var rec = _this.grid.ds.getAt(rc[0]);
1510 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that line?", function(r)
1518 if (!rec.data.cmitem_id) {
1519 _this.grid.ds.remove(rec);
1525 url : baseURL + '/Roo/cmitem',
1528 _delete : rec.data.cmitem_id
1531 success : function() {
1532 if (rec.data.item_type == 'K') {
1533 _this.grid.ds.load({});
1536 _this.grid.ds.remove(rec);
1546 cls : 'x-btn-text-icon',
1548 icon : rootURL + '/Pman/templates/images/trash.gif'
1554 xtype: 'ColumnModel',
1556 dataIndex : 'cmitem_linenumber',
1559 renderer : function(v,x,r) {
1561 if (r.data.coitem_subnumber * 1 > 0) {
1562 return String.format('{0}.{1}', v,r.data.coitem_subnumber);
1564 return String.format('{0}', v);
1568 xtype: 'ColumnModel',
1570 dataIndex : 'item_number',
1571 header : 'Item Code',
1573 renderer : function(v) { return String.format('{0}', v); },
1575 xtype: 'GridEditor',
1581 beforeselect : function (combo, record, index)
1583 // set _this.data values ..
1584 var ar = _this.grid.activeEditor.record;
1585 //Roo.log('beforeselect');
1587 var rate = _this.form.findField('taxzone_rate').getValue();
1591 ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
1592 ar.set('cmitem_comments', record.data.itemsite_item_id_item_descrip1);
1593 ar.set('cmitem_tax_listprice', record.data.item_listprice * ( 1 + rate * 1) );
1594 ar.set('cmitem_item_listprice', record.data.item_listprice * 1);
1595 ar.set('cmitem_tax_unitprice', record.data.item_price * ( 1 + rate * 1) );
1596 ar.set('cmitem_unitprice', record.data.item_price * 1);
1597 ar.set('cmitem_qtycredit', 1);
1598 ar.set('cmitem_line_value', record.data.item_price * ar.data.cmitem_qtycredit);
1599 ar.set('cmitem_line_tax_value', ar.data.cmitem_tax_unitprice * ar.data.cmitem_qtycredit);
1600 ar.set('cmitem_itemsite_id', record.data.itemsite_id);
1601 ar.set('item_number', record.data.itemsite_item_id_item_number);
1602 ar.set('item_type', record.data.itemsite_item_id_item_type);
1603 ar.set('avail_qty', 0);
1604 // ar.updateFields = ['All'];
1611 displayField : 'itemsite_item_id_item_number',
1613 emptyText : "Select item",
1614 forceSelection : true,
1615 hiddenName : 'itemsite_item_id_item_number',
1617 loadingText : "Searching...",
1619 name : 'item_number',
1621 qtip : "Select item",
1622 queryParam : 'query[number]',
1623 selectOnFocus : true,
1624 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>',
1625 triggerAction : 'all',
1627 valueField : 'item_number',
1632 beforeload : function (_self, o){
1633 o.params = o.params || {};
1634 o.params.customer_id = _this.form.findField('cmhead_cust_id').getValue();
1635 o.params['query[cmhead_id]'] = _this.form.findField('cmhead_id').getValue();
1636 //o.params.shipto_cust_id = _this.data.cohead_cust_id;
1641 sortInfo : { direction : 'ASC', field: 'item_number' },
1646 url : baseURL + '/Roo/itemsite.php'
1649 xtype: 'JsonReader',
1653 totalProperty : 'total',
1654 fields : [{'name':'item_id','type':'int'},'item_number']
1661 xtype: 'ColumnModel',
1663 dataIndex : 'cmitem_comments',
1664 header : 'Item Description',
1666 renderer : function(v,x,r) {
1669 r.set('cmitem_comments', r.data.item_descrip1);
1670 v = r.data.item_descrip1;
1672 if (v && v.length > 49) {
1673 return String.format('<span style="color:orange" qtip="line may be too long to print">{0}</span>', v);
1675 return String.format('{0}', v);
1679 xtype: 'GridEditor',
1689 xtype: 'ColumnModel',
1692 dataIndex : 'cmitem_qtycredit',
1695 renderer : function(v)
1697 return String.format('{0}', v ? parseInt(v) : '');
1700 xtype: 'GridEditor',
1703 xtype: 'NumberField',
1706 focus : function (_self)
1708 if (this.value == 0) {
1709 this.el.dom.value = '';
1713 allowDecimals : false,
1714 decimalPrecision : 0,
1716 style : 'text-align:right'
1721 xtype: 'ColumnModel',
1724 dataIndex : 'cmitem_tax_listprice',
1725 header : 'List Price w. tax',
1727 renderer : function(v,x,r)
1729 // var rate = _this.form.findField('taxzone_rate').getValue();
1730 // v = v * (1 + rate * 1);
1732 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1736 xtype: 'ColumnModel',
1739 dataIndex : 'cmitem_taxtype_id',
1742 renderer : function(v,x,r) { return String.format('{0}', r.data.cmitem_taxtype_id_taxtype_name); },
1744 xtype: 'GridEditor',
1750 displayField : 'taxtype_name',
1752 emptyText : "Select Tax Type",
1753 forceSelection : true,
1754 hiddenName : 'cmitem_taxtype_id',
1756 loadingText : "Searching...",
1758 name : 'cmitem_taxtype_id_taxtype_name',
1760 qtip : "Select taxtype",
1761 queryParam : 'query[taxtype_id]',
1762 selectOnFocus : true,
1763 tpl : '<div class="x-grid-cell-text x-btn button"><b>{taxtype_name}</b> </div>',
1764 triggerAction : 'all',
1766 valueField : 'taxtype_id',
1772 beforeload : function (_self, o){
1773 o.params = o.params || {};
1776 /* o.params.with_date = _this.form.findField('cohead_orderdate').getValue().format('Y-m-d');
1777 Roo.log("with date?" + o.params.with_date);*/
1783 sortInfo : { direction : 'ASC', field: 'taxtype_name' },
1788 url : baseURL + '/Roo/taxtype.php'
1791 xtype: 'JsonReader',
1795 totalProperty : 'total',
1796 fields : [{'name':'taxtype_id','type':'int'},'taxtype_name']
1803 xtype: 'ColumnModel',
1806 dataIndex : 'cmitem_tax_unitprice',
1807 header : 'Unit Price w. tax',
1809 renderer : function(v,x,r)
1811 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1814 xtype: 'GridEditor',
1817 xtype: 'NumberField',
1820 focus : function (_self)
1822 if (this.value == 0.0) {
1823 this.el.dom.value = '';
1827 decimalPrecision : 2,
1829 style : 'text-align:right'
1834 xtype: 'ColumnModel',
1837 dataIndex : 'cmitem_unitprice',
1838 header : 'Unit Price',
1840 renderer : function(v)
1842 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1845 xtype: 'GridEditor',
1848 xtype: 'NumberField',
1851 focus : function (_self)
1853 if (this.value == 0.0) {
1854 this.el.dom.value = '';
1858 decimalPrecision : 2,
1860 style : 'text-align:right'
1865 xtype: 'ColumnModel',
1868 dataIndex : 'cmitem_line_value',
1871 renderer : function(v)
1873 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1878 dataIndex : 'cmitem_line_tax_value',
1879 header : 'Total w. tax',
1881 renderer : function(v,x,r)
1883 return String.format('{0}', v ? parseFloat(v).toFixed(2) : '');
1894 activate : function() {
1895 _this.cpanel = this;
1897 var id = _this.form.findField('cmhead_id').getValue() * 1;
1899 Roo.MessageBox.alert("Error", "save the credit memo first!");
1900 _this.dialog.layout.getRegion('center').showPanel(0);
1905 _this.cgrid.footer.onClick('first');
1910 fitContainer : true,
1913 tableName : 'checkitem',
1914 title : "Miscellaneous Check",
1922 //_this.dialog = Pman.Dialog.FILL_IN
1923 if (_this.cpanel.active) {
1924 this.footer.onClick('first');
1928 autoExpandColumn : 'checkitem_checkhead_id_checkhead_notes',
1934 beforeload : function (_self, options)
1936 options.params = options.params || {};
1937 options.params.checkitem_cmnumber = _this.form.findField('cmhead_number').getValue();
1941 sortInfo : { field : 'checkitem_id', direction: 'DESC' },
1946 url : baseURL + '/Roo/checkitem.php'
1949 xtype: 'JsonReader',
1953 totalProperty : 'total',
1972 'name': 'leader_id',
1976 'name': 'leader_office_id',
1980 'name': 'leader_name',
1984 'name': 'leader_phone',
1988 'name': 'leader_fax',
1992 'name': 'leader_email',
1996 'name': 'leader_company_id',
2000 'name': 'leader_role',
2004 'name': 'leader_active',
2008 'name': 'leader_remarks',
2012 'name': 'leader_passwd',
2016 'name': 'leader_owner_id',
2020 'name': 'leader_lang',
2024 'name': 'leader_no_reset_sent',
2028 'name': 'leader_action_type',
2032 'name': 'leader_project_id',
2036 'name': 'leader_deleted_by',
2040 'name': 'leader_deleted_dt',
2044 'name': 'leader_firstname',
2048 'name': 'leader_lastname',
2052 'name': 'leader_name_facebook',
2056 'name': 'leader_url_blog',
2060 'name': 'leader_url_twitter',
2064 'name': 'leader_url_linkedin',
2068 'name': 'leader_crm_lead_percentage',
2072 'name': 'leader_crm_industry_id',
2076 'name': 'leader_crm_updated_action_id',
2080 'name': 'leader_crm_created_action_id',
2084 'name': 'leader_crm_type_id',
2091 xtype: 'PagingToolbar',
2094 displayMsg : "Displaying check item{0} - {1} of {2}",
2095 emptyMsg : "No check item found",
2100 xtype: 'ColumnModel',
2102 dataIndex : 'checkitem_docdate',
2105 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
2108 xtype: 'ColumnModel',
2110 dataIndex : 'checkitem_bankaccnt_id_bankaccnt_name',
2111 header : 'Bank Account',
2113 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2116 xtype: 'ColumnModel',
2118 dataIndex : 'checkitem_checkhead_id_checkhead_for',
2121 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2124 xtype: 'ColumnModel',
2126 dataIndex : 'checkitem_checkhead_id_checkhead_notes',
2129 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2132 xtype: 'ColumnModel',
2135 dataIndex : 'checkitem_curr_id_curr_name',
2136 header : 'Currency',
2138 renderer : function(v) { return String.format('{0}', v ? v : ''); }
2141 xtype: 'ColumnModel',
2144 dataIndex : 'checkitem_amount',
2147 renderer : function(v) { return String.format('{0}', v ? parseFloat(v).toFixed(2) : ''); }
2156 activate : function() {
2157 _this.apanel = this;
2159 _this.agrid.footer.onClick('first');
2164 fitContainer : true,
2167 tableName : 'invchead',
2168 title : "Applications",
2176 //_this.dialog = Pman.Dialog.FILL_IN
2177 if (_this.apanel.active) {
2178 this.footer.onClick('first');
2182 autoExpandColumn : 'arapply_target_docnumber',
2188 beforeload : function (_self,o) {
2194 if (!_this.data || !_this.data.cmhead_id) {
2197 o.params = o.params || {};
2199 o.params._application = _this.data.cmhead_id
2204 sortInfo : { field : 'arapply_id', direction: 'ASC' },
2209 url : baseURL + '/Roo/Arapply.php'
2212 xtype: 'JsonReader',
2214 totalProperty : 'total',
2235 'name': 'leader_id',
2239 'name': 'leader_office_id',
2243 'name': 'leader_name',
2247 'name': 'leader_phone',
2251 'name': 'leader_fax',
2255 'name': 'leader_email',
2259 'name': 'leader_company_id',
2263 'name': 'leader_role',
2267 'name': 'leader_active',
2271 'name': 'leader_remarks',
2275 'name': 'leader_passwd',
2279 'name': 'leader_owner_id',
2283 'name': 'leader_lang',
2287 'name': 'leader_no_reset_sent',
2291 'name': 'leader_action_type',
2295 'name': 'leader_project_id',
2299 'name': 'leader_deleted_by',
2303 'name': 'leader_deleted_dt',
2307 'name': 'leader_firstname',
2311 'name': 'leader_lastname',
2315 'name': 'leader_name_facebook',
2319 'name': 'leader_url_blog',
2323 'name': 'leader_url_twitter',
2327 'name': 'leader_url_linkedin',
2331 'name': 'leader_crm_lead_percentage',
2335 'name': 'leader_crm_industry_id',
2339 'name': 'leader_crm_updated_action_id',
2343 'name': 'leader_crm_created_action_id',
2347 'name': 'leader_crm_type_id',
2354 xtype: 'PagingToolbar',
2357 displayMsg : "Displaying application{0} - {1} of {2}",
2358 emptyMsg : "No application found",
2363 xtype: 'ColumnModel',
2365 dataIndex : 'arapply_id',
2368 renderer : function(v) { return String.format('{0}', v); }
2371 xtype: 'ColumnModel',
2373 dataIndex : 'arapply_distdate',
2376 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
2379 xtype: 'ColumnModel',
2381 dataIndex : 'arapply_target_doctype',
2382 header : 'Target Doctype',
2384 renderer : function(v) { return String.format('{0}', v); }
2387 xtype: 'ColumnModel',
2389 dataIndex : 'arapply_target_docnumber',
2390 header : 'Target Docnumber',
2392 renderer : function(v) { return String.format('{0}', v); }
2395 xtype: 'ColumnModel',
2397 dataIndex : 'arapply_curr_id_curr_name',
2398 header : 'Currency',
2400 renderer : function(v) { return String.format('{0}', v); }
2403 xtype: 'ColumnModel',
2405 dataIndex : 'arapply_applied',
2408 renderer : function(v) { return String.format('{0}', v); }
2417 activate : function() {
2418 _this.hpanel = this;
2420 _this.hgrid.footer.onClick('first');
2425 fitContainer : true,
2428 tableName : 'events',
2437 //_this.dialog = Pman.Dialog.FILL_IN
2438 if (_this.hpanel.active) {
2439 this.footer.onClick('first');
2442 rowdblclick : function (_self, rowIndex, e)
2444 if (!_this.dialog) return;
2445 _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
2446 _this.grid.footer.onClick('first');
2450 autoExpandColumn : 'remarks',
2456 beforeload : function (_self, options)
2458 options.params._related_on_table = 'cmhead';
2459 options.params._related_on_id = _this.form.findField('cmhead_id').getValue();
2464 sortInfo : { field : 'event_when', direction: 'DESC' },
2469 url : baseURL + '/Roo/events.php'
2472 xtype: 'JsonReader',
2474 totalProperty : 'total',
2479 'name': 'event_when',
2491 'name': 'person_id_name',
2502 xtype: 'PagingToolbar',
2506 displayMsg : "Displaying events{0} - {1} of {2}",
2507 emptyMsg : "No events found"
2511 xtype: 'ColumnModel',
2513 dataIndex : 'event_when',
2516 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); }
2519 xtype: 'ColumnModel',
2521 dataIndex : 'action',
2524 renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); }
2527 xtype: 'ColumnModel',
2529 dataIndex : 'ipaddr',
2530 header : 'IP address',
2532 renderer : function(v) { return String.format('{0}', v); }
2535 xtype: 'ColumnModel',
2537 dataIndex : 'person_id_name',
2540 renderer : function(v) { return String.format('{0}', v); }
2543 xtype: 'ColumnModel',
2545 dataIndex : 'remarks',
2548 renderer : function(v) { return String.format('{0}', v); }
2555 xtype: 'LayoutRegion',
2557 alwaysShowTabs : true,
2565 click : function (_self, e)
2567 if (_this.grid) _this.grid.stopEditing();
2568 _this.dialog.hide();
2577 click : function (_self, e)
2580 if (_this.grid) _this.grid.stopEditing();
2581 if (_this.form.findField('cmhead_posted').getValue() == 'true') {
2582 Roo.MessageBox.alert("Error", "credit memo is already posted");
2587 if (_this.grid && _this.grid.ds) {
2588 _this.grid.ds.each(function(rec) {
2589 if (!(rec.data.cmitem_itemsite_id * 1) || !(rec.data.cmitem_qtycredit*1) || !(rec.data.cmitem_unitprice*1)) {
2597 Roo.MessageBox.alert("Error", "Some lines do not have product/qty/price set");
2602 _this.form.findField('has_item').setValue(ar.length);
2605 _this.form.doAction("submit");
2607 render : function (_self)
2609 _this.saveBtn = _self;