1 //<script type="text/javascript">
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
5 Pman.Dialog.XtupleInvoice = {
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',
38 title : "Edit / Create Invoice",
42 xtype: 'NestedLayoutPanel',
46 xtype: 'BorderLayout',
53 activate : function() {
63 title : "Apply Credit Memos",
73 cellclick : function (_self, rowIndex, columnIndex, e)
76 if (columnIndex > 0 ) {
79 var d = this.ds.getAt(rowIndex);
80 var f = this.cm.getDataIndex(columnIndex);
84 d.set(f, d.data[f] * 1 ? 0 : 1);
87 _this.form.findField('cobapply_list').update();
91 rowdblclick : function (_self, rowIndex, e)
93 var s = _this.cmgrid.ds.getAt(rowIndex);
95 Pman.Dialog.XtupleCreditMemo.show({
96 cmhead_id : s.data.join_aropen_cmhead_id
98 _this.cmgrid.ds.load({});
103 autoExpandColumn : 'aropen_docnumber',
119 var postit = function(params){
122 url : baseURL + '/Roo/Cmhead',
\r
125 params : params.postdata,
\r
126 success : function(res)
\r
128 _this.cmgrid.ds.load({});
130 _this.cmgrid.ds.each(function(d){
131 if(d.data.join_aropen_cmhead_id == res.data){
140 var opendialog = function(data){
141 Pman.Dialog.XtupleCreditMemo.show( data , function(res) {
143 Roo.MessageBox.confirm(
\r
145 "These is no any credit items in this credit memo! Press YES to reopen the dialog for editing, Press NO will delete this credit memo.",
\r
148 // delete the credit memo
152 _delete : res.cmhead_id
160 opendialog({cmhead_id : res.cmhead_id});
167 Roo.MessageBox.confirm(
\r
169 "Are you sure this credit memo is complete? <B>Voiding a Credit memo involves creating a sales order and invoice </b>, so make sure this is correct before posting! Press YES will post it, Press NO to reopen the dialog for editing.",
\r
172 opendialog({cmhead_id : res.cmhead_id});
178 cmhead_id : res.cmhead_id,
197 cmhead_cust_id : _this.data.cmdata.cm_cust_id,
198 cmhead_cust_id_cust_name : _this.data.cmdata.cm_cust_id_cust_name,
199 cmhead_curr_id : _this.data.cmdata.cm_curr_id,
200 cmhead_curr_id_curr_name : _this.data.cmdata.cm_curr_id_curr_name,
201 cmhead_terms_id : _this.data.cmdata.cm_terms_id,
202 cmhead_terms_id_terms_descrip : _this.data.cmdata.cm_terms_id_terms_descrip,
203 cmhead_salesrep_id : _this.data.cmdata.cm_salesrep_id,
204 cmhead_salesrep_id_salesrep_name : _this.data.cmdata.cm_salesrep_id_salesrep_name,
205 cmhead_docdate : new Date(),
206 cmhead_taxzone_id : _this.data.cmdata.cm_taxzone_id,
207 cmhead_taxzone_id_taxzone_descrip : _this.data.cmdata.cm_taxzone_id_taxzone_descrip,
208 cmhead_billto_cntct_id : _this.data.cmdata.cm_billto_cntct_id,
209 cmhead_billto_cntct_id_cntct_name : _this.data.cmdata.cm_billto_cntct_id_cntct_name,
210 cmhead_location_id : _this.data.cmdata.cm_location_src,
211 cmhead_location_id_location_name : _this.data.cmdata.cm_location_src_location_name,
212 billto_address : _this.data.cmdata.cm_billto_address
221 cls : 'x-btn-text-icon',
223 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
231 beforeload : function (_self, o)
233 o.params = o.params || {};
234 o.params.limit = 999;
235 o.params._opencm = 1;
236 o.params._for_cohead = _this.form.findField('cobmisc_cohead_id').getValue();
237 o.params._for_cobmisc_id = _this.form.findField('cobmisc_id').getValue();
239 load : function (_self, records, options)
241 _this.form.findField('cobapply_list').update();
245 sortInfo : { field : 'aropen_docnumber', direction: 'DESC' },
250 url : baseURL + '/Roo/aropen.php'
255 totalProperty : 'total',
264 'name': 'cmhead_number',
268 'name': 'cmhead_posted',
272 'name': 'cmhead_invcnumber',
276 'name': 'cmhead_custponumber',
280 'name': 'cmhead_cust_id',
284 'name': 'cmhead_docdate',
286 'dateFormat': 'Y-m-d'
289 'name': 'cmhead_shipto_id',
293 'name': 'cmhead_shipto_name',
297 'name': 'cmhead_shipto_address1',
301 'name': 'cmhead_shipto_address2',
305 'name': 'cmhead_shipto_address3',
309 'name': 'cmhead_shipto_city',
313 'name': 'cmhead_shipto_state',
317 'name': 'cmhead_shipto_zipcode',
321 'name': 'cmhead_salesrep_id',
325 'name': 'cmhead_freight',
329 'name': 'cmhead_misc',
333 'name': 'cmhead_comments',
337 'name': 'cmhead_printed',
341 'name': 'cmhead_billtoname',
345 'name': 'cmhead_billtoaddress1',
349 'name': 'cmhead_billtoaddress2',
353 'name': 'cmhead_billtoaddress3',
357 'name': 'cmhead_billtocity',
361 'name': 'cmhead_billtostate',
365 'name': 'cmhead_billtozip',
369 'name': 'cmhead_hold',
373 'name': 'cmhead_commission',
377 'name': 'cmhead_misc_accnt_id',
381 'name': 'cmhead_misc_descrip',
385 'name': 'cmhead_rsncode_id',
389 'name': 'cmhead_curr_id',
393 'name': 'cmhead_freighttaxtype_id',
397 'name': 'cmhead_gldistdate',
399 'dateFormat': 'Y-m-d'
402 'name': 'cmhead_billtocountry',
406 'name': 'cmhead_shipto_country',
410 'name': 'cmhead_rahead_id',
414 'name': 'cmhead_taxzone_id',
418 'name': 'cmhead_prj_id',
422 'name': 'cmhead_curr_id_curr_id',
426 'name': 'cmhead_curr_id_curr_base',
430 'name': 'cmhead_curr_id_curr_name',
434 'name': 'cmhead_curr_id_curr_symbol',
438 'name': 'cmhead_curr_id_curr_abbr',
442 'name': 'cmhead_taxzone_id_taxzone_id',
446 'name': 'cmhead_taxzone_id_taxzone_code',
450 'name': 'cmhead_taxzone_id_taxzone_descrip',
454 'name': 'cmhead_prj_id_prj_id',
458 'name': 'cmhead_prj_id_prj_number',
462 'name': 'cmhead_prj_id_prj_name',
466 'name': 'cmhead_prj_id_prj_descrip',
470 'name': 'cmhead_prj_id_prj_status',
474 'name': 'cmhead_prj_id_prj_so',
478 'name': 'cmhead_prj_id_prj_wo',
482 'name': 'cmhead_prj_id_prj_po',
486 'name': 'cmhead_prj_id_prj_owner_username',
490 'name': 'cmhead_prj_id_prj_start_date',
494 'name': 'cmhead_prj_id_prj_due_date',
498 'name': 'cmhead_prj_id_prj_assigned_date',
502 'name': 'cmhead_prj_id_prj_completed_date',
506 'name': 'cmhead_prj_id_prj_username',
510 'name': 'cmhead_prj_id_prj_recurring_prj_id',
514 'name': 'cmhead_freighttaxtype_id_taxtype_id',
518 'name': 'cmhead_freighttaxtype_id_taxtype_name',
522 'name': 'cmhead_freighttaxtype_id_taxtype_descrip',
526 'name': 'cmhead_freighttaxtype_id_taxtype_sys',
534 xtype: 'ColumnModel',
536 dataIndex : 'toapply',
539 renderer : function(v,x,r) {
541 return '<img class="x-grid-check-icon' +
542 (v*1 ? '-checked' : '') + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
548 xtype: 'ColumnModel',
550 dataIndex : 'aropen_docnumber',
553 renderer : function(v) { return String.format('{0}', v); }
556 xtype: 'ColumnModel',
559 dataIndex : 'balance',
560 header : 'Amount Avail',
562 renderer : function(v,x,r) {
563 if (r.data.applied*1.0 > 0.0) {
564 return String.format('{0}', r.data.applied*1.0);
567 return String.format('{0}', v);
574 xtype: 'ContentPanel',
582 actioncomplete : function (_self,action) {
583 if (action.type == 'setdata') {
584 if (_this.data.cobmisc_id) {
585 this.load({ method: 'GET', params: { '_id' : _this.data.cobmisc_id }});
591 _this.saveBtn.show();
592 // see if we can create an invoice...
594 url : baseURL + '/Roo/Cobmisc',
596 _canCreate : _this.data.cobmisc_cohead_id
599 success: function(r) {
600 if (r.data.canCreate * 1 > 0 ) {
601 Roo.MessageBox.alert(
602 "Error", "An unposted Bill already exists for this order"
608 // _this.form.findField('cobmisc_misc').setValue(r.data.cohead.cohead_misc);
609 _this.form.findField('cobmisc_misc').setValue(r.data.cohead.cohead_pretax_discount);
610 _this.form.findField('cobmisc_cohead_id_cohead_pretax_discount').setValue(r.data.cohead.cohead_pretax_discount);
611 _this.form.findField('cobmisc_posttax_discount').setValue(
612 (1* r.data.cohead.cohead_posttax_discount) //- (1*r.data.cohead.cohead_pretax_discount)
614 // _this.form.findField('cobmisc_cohead_id_cohead_posttax_discount').setValue(r.data.cohead.cohead_posttax_discount);
615 _this.form.findField('cobmisc_misc_descrip').setValue(r.data.cohead.cohead_misc_descrip);
616 _this.grid.ds.load({});
622 if (action.type == 'load') {
623 var d = action.result.data;
626 if(d.cobmisc_misc != 0 && d.cobmisc_posttax_discount == 0 && d.cobmisc_cohead_id_cohead_pretax_discount == 0){
627 _this.form.findField('cobmisc_cohead_id_cohead_pretax_discount').setValue(d.cobmisc_misc);
630 _this.form.findField('cobmisc_posttax_discount').setValue(d.cobmisc_misc - d.cobmisc_cohead_id_cohead_pretax_discount);
632 if (d.cobmisc_invchead_id *1 > 0) {
633 Roo.MessageBox.alert(
634 "Warning", "This invoice has been posted, you must void it before you can edit it"
637 _this.saveBtn.hide();
640 _this.saveBtn.show();
642 _this.grid.ds.load({});
645 if (action.type =='submit') {
649 if (_this.callback) {
650 _this.callback.call(_this, _this.form.getValues());
657 rendered : function (form)
663 style : 'margin:10px;',
664 recalc : function() {
669 _this.grid.ds.each(function(r) {
670 ic += ((r.data.cobill_qty * r.data.coitem_price).toFixed(2) * 1);
671 if (r.data.calc_tax) {
672 // either full, or a proportion of...
673 total_tax += (r.data.cobill_qty == r.data.coitem_qtyord) ?
674 (1*r.data.calc_tax) : (
675 (1*r.data.calc_tax) * (r.data.cobill_qty / r.data.coitem_qtyord)
681 _this.form.findField('cobmisc_itemcost').setValue(ic.toFixed(2));
682 _this.form.findField('cobmisc_total_tax').setValue( total_tax.toFixed(2));
685 var total = (_this.form.findField('cobmisc_itemcost').getValue() * 1.0) +
686 ( _this.form.findField('cobmisc_freight').getValue() * 1.0) +
688 ( _this.form.findField('cobmisc_cohead_id_cohead_pretax_discount').getValue() * 1.0) +
689 ( _this.form.findField('cobmisc_posttax_discount').getValue() * 1.0) +
690 ( _this.form.findField('cobmisc_total_tax').getValue() * 1.0)
693 // special handling for credit memos.
697 _this.cmgrid.ds.each(function(r) {
\r
698 if (r.data.toapply * 1) {
\r
700 if (r.data.applied *1.0 > 0.0) {
\r
701 val += parseFloat(r.data.applied);
\r
704 val += parseFloat(r.data.balance);
\r
708 if(count == 1 && total < val){
712 _this.form.findField('cobmisc_cm_total').setValue( (val * -1).toFixed(2));
713 _this.form.findField('cobmisc_total').setValue((total - val).toFixed(2));
714 _this.form.findField('cobapply_total').setValue((val * -1).toFixed(2));
718 // this is an error condition.
719 _this.form.findField('cobmisc_total').setValue(total);
725 var cmlist = _this.form.findField('cobapply_list').getValue();
726 var cmval = _this.form.findField('cobapply_total').getValue() * 1.0;
728 if (total + cmval >= 0.0 ) {
729 _this.form.findField('cobmisc_total').setValue(((total + cmval) * 1.0).toFixed(2));
732 if (cmlist.length || cmlist.split(',').length > 1) {
733 _this.form.findField('cobmisc_total').setValue(total + cmval);
736 // fixme we need to work out the correct value...
738 _this.form.findField('cobmisc_cm_total').setValue( (total * -1).toFixed(2));
740 _this.form.findField('cobmisc_total').setValue(0.0);
745 url : baseURL + '/Roo/cobmisc.php',
760 legend : "Invoice Details",
761 style : 'width:230px',
766 fieldLabel : 'Invoice Date',
768 name : 'cobmisc_invcdate',
774 fieldLabel : 'Shipment Date',
776 name : 'cobmisc_shipdate',
789 fieldLabel : 'Notes',
791 name : 'cobmisc_notes',
802 style : 'margin-left:10px',
808 labelAlign : 'right',
811 style : 'width:330px',
814 xtype: 'NumberField',
816 allowDecimals : true,
817 cls : 'roo-align-right',
818 decimalPrecision : 3,
819 fieldLabel : 'Item(s) Total',
820 name : 'cobmisc_itemcost',
825 xtype: 'NumberField',
828 keyup : function (_self, e)
833 allowDecimals : true,
834 cls : 'roo-align-right',
835 decimalPrecision : 3,
836 fieldLabel : 'Shipping',
837 name : 'cobmisc_freight',
841 xtype: 'NumberField',
843 allowDecimals : true,
844 cls : 'roo-align-right',
845 decimalPrecision : 3,
846 fieldLabel : 'Pre Tax discount:',
847 name : 'cobmisc_cohead_id_cohead_pretax_discount',
860 fieldLabel : 'Discount after Tax Description ',
861 name : 'cobmisc_misc_descrip',
865 xtype: 'NumberField',
868 keyup : function (_self, e)
871 _this.form.findField('cobmisc_misc').recalc();
874 allowDecimals : true,
875 cls : 'roo-align-right',
876 decimalPrecision : 3,
877 fieldLabel : 'Amount',
878 name : 'cobmisc_posttax_discount',
884 xtype: 'NumberField',
886 allowDecimals : true,
887 cls : 'roo-align-right',
888 decimalPrecision : 3,
890 name : 'cobmisc_total_tax',
895 xtype: 'NumberField',
897 allowDecimals : true,
898 cls : 'roo-align-right',
899 decimalPrecision : 3,
900 fieldLabel : 'Credit Memos Applied',
901 name : 'cobmisc_cm_total',
906 xtype: 'NumberField',
908 allowDecimals : true,
909 cls : 'roo-align-right',
910 decimalPrecision : 3,
911 fieldLabel : 'Total',
913 name : 'cobmisc_total',
926 name : 'cobmisc_misc',
927 recalc : function() {
\r
928 var d = _this.form.getValues();
\r
930 parseFloat(d.cobmisc_cohead_id_cohead_pretax_discount) +
\r
931 parseFloat(d.cobmisc_posttax_discount) );
\r
937 name : 'cobmisc_cohead_id'
947 name : 'cobapply_total'
952 name : 'cobapply_list',
953 update : function() {
957 _this.cmgrid.ds.each(function(r) {
959 if (r.data.toapply * 1) {
961 ret.push(r.data.aropen_id);
962 if (r.data.applied *1.0 > 0.0) {
963 val += parseFloat(r.data.applied);
967 val += parseFloat(r.data.balance);
971 var total = (_this.form.findField('cobmisc_itemcost').getValue() * 1.0) +
\r
972 ( _this.form.findField('cobmisc_freight').getValue() * 1.0) +
\r
974 ( _this.form.findField('cobmisc_cohead_id_cohead_pretax_discount').getValue() * 1.0) +
\r
975 ( _this.form.findField('cobmisc_posttax_discount').getValue() * 1.0) +
\r
976 ( _this.form.findField('cobmisc_total_tax').getValue() * 1.0)
\r
979 if(count > 1 && total < val){
\r
980 Roo.Msg.alert('Error', 'Credit memo total goes over the invoice total');
\r
982 this.setValue(ret.join(','));
983 _this.form.findField('cobmisc_cm_total').setValue( (val * -1).toFixed(2));
984 _this.form.findField('cobapply_total').setValue( (val * -1).toFixed(2));
999 xtype: 'LayoutRegion',
1003 xtype: 'LayoutRegion',
1014 activate : function() {
1017 if (_this.isBuilder) {
1023 _this.grid.ds.load({});
1027 fitContainer : true,
1030 tableName : 'coitem',
1031 title : "Order Items",
1033 xtype: 'EditorGrid',
1039 //_this.dialog = Pman.Dialog.FILL_IN
1040 if (_this.panel.active) {
1044 rowdblclick : function (_self, rowIndex, e)
1048 afteredit : function (e)
1050 //Roo.log('afteredit');
1052 if (e.field == 'item_number') {
1053 // afterselect handles this...
1059 autoExpandColumn : 'item_descrip1',
1063 xtype: 'CellSelectionModel',
1071 beforeload : function (_self,o) {
1072 if (! _this.form.findField('cobmisc_cohead_id').getValue()) {
1075 o.params = o.params || {};
1077 o.params.coitem_cohead_id = _this.form.findField('cobmisc_cohead_id').getValue();
1078 o.params.limit = 999;
1079 o.params.cobmisc_id = _this.form.findField('cobmisc_id').getValue();
1082 load : function (_self, records, options)
1084 (function() { _this.form.recalc(); }).defer(100);
1085 _this.cmgrid.ds.load({});
1087 update : function (_self, record, operation)
1089 _this.form.recalc();
1093 sortInfo : { field : 'coitem_linenumber', direction: 'ASC' },
1098 url : baseURL + '/Roo/coitem.php'
1101 xtype: 'JsonReader',
1103 totalProperty : 'total',
1108 'name': 'coitem_linenumber',
1112 'name': 'coitem_itemsite_id',
1116 'name': 'coitem_qtyord'
1119 'name': 'coitem_unitcost'
1122 'name': 'coitem_price'
1125 'name': 'coitem_custprice'
1128 'name': 'coitem_qtyreturned'
1131 'name': 'coitem_prcost'
1134 'name': 'coitem_price_uom_id',
1138 'name': 'coitem_qtyreserved'
1151 click : function (_self, e)
1153 _this.grid.ds.each(function(r) {
1154 r.set('cobill_qty', Math.max(0, r.data.coitem_qtyord - r.data.cobill_billed));
1158 text : "Invoice all"
1163 text : "Restore from : "
1169 select : function (combo, record, index)
1171 //_this.grid.footer.onClick('first');
1176 var data = record.json.data;
1178 _this.grid.ds.each(function (r) {
1179 if (typeof(data[r.data.coitem_itemsite_id+'']) == 'undefined') {
1182 r.set('cobill_qty', parseInt(data[r.data.coitem_itemsite_id+'']));
1192 displayField : 'name',
1194 emptyText : "Restore from",
1195 forceSelection : true,
1197 loadingText : "Searching...",
1200 qtip : "Select Action",
1201 queryParam : 'query[action]',
1202 selectOnFocus : true,
1203 tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
1204 triggerAction : 'all',
1206 valueField : 'name',
1212 beforeload : function (_self, o)
1214 o.params = o.params || {};
1215 // staff can see all logs, other companies can only see their own.
1217 o.params._stash = _this.form.findField('cobmisc_cohead_id').getValue();
1222 sortInfo : { field : 'action' , direction : 'ASC' },
1227 url : baseURL + '/Roo/Cobmisc.php'
1230 xtype: 'JsonReader',
1234 totalProperty : 'total',
1255 _this.grid.ds.each(function(r) {
1256 r.set('cobill_qty', 0);
1266 xtype: 'ColumnModel',
1270 dataIndex : 'coitem_linenumber',
1271 renderer : function(v) { return String.format('{0}', v); }
1274 xtype: 'ColumnModel',
1276 header : 'Item Code',
1278 dataIndex : 'item_number',
1279 renderer : function(v) { return String.format('{0}', v); }
1282 xtype: 'ColumnModel',
1284 dataIndex : 'item_descrip1',
1285 header : 'Item Description',
1287 renderer : function(v, x, r) {
1290 if (r.data.coitem_memo && r.data.coitem_memo.length) {
1291 vv = r.data.coitem_memo;
1293 return String.format('{0}', vv);
1298 xtype: 'ColumnModel',
1301 dataIndex : 'coitem_custprice',
1302 header : 'List Price',
1304 renderer : function(v) { return String.format('{0}', (v *1.0).toFixed(2)); }
1307 xtype: 'ColumnModel',
1310 dataIndex : 'coitem_price',
1313 renderer : function(v) { return String.format('{0}', (v *1.0).toFixed(2)); }
1316 xtype: 'ColumnModel',
1319 dataIndex : 'calc_tax',
1322 renderer : function(v) { return String.format('{0}', (v *1.0).toFixed(2)); }
1325 xtype: 'ColumnModel',
1328 dataIndex : 'coitem_qtyord',
1329 header : 'Ordered Qty',
1331 renderer : function(v) { return String.format('{0}', v); }
1334 xtype: 'ColumnModel',
1337 dataIndex : 'cobill_billed',
1338 header : 'Not Billed Qty',
1340 renderer : function(v,x,r) {
1343 return String.format('{0}', r.data.coitem_qtyord - v);
1347 xtype: 'ColumnModel',
1350 dataIndex : 'cobill_qty',
1351 header : 'Bill Qty',
1353 renderer : function(v,x,r) {
1355 var vv = parseInt(v);
1356 vv = isNaN(vv) ? 0 : vv;
1357 r.data.cobill_qty = vv; // get rid of decimal.
1358 if (r.data.cobill_billed + vv > r.data.coitem_qtyord) {
1359 return String.format('<b style="background-color:red;color:yellow">{0}</b>', vv);
1361 // not fully fullfilled
1362 if (r.data.cobill_billed + vv != r.data.coitem_qtyord) {
1363 return String.format('<b style="background-color:blue;color:yellow">{0}</b>', vv);
1365 return String.format('{0}', vv);
1369 xtype: 'GridEditor',
1372 xtype: 'NumberField',
1374 allowDecimals : true,
1375 decimalPrecision : 0,
1377 style : 'text-align:right'
1386 xtype: 'LayoutRegion',
1390 xtype: 'LayoutRegion',
1399 click : function (_self, e)
1401 _this.dialog.hide();
1410 click : function (_self, e)
1412 var hasListDiscount = false;
1417 _this.grid.ds.each(function(r) {
1418 if(r.data.item_number == 'Z-LIST-DISCOUNT'){
1419 hasListDiscount = true;
1421 orderQty += r.data.coitem_qtyord;
1422 billQty += r.data.cobill_qty;
1425 cobill_coitem_id : r.data.coitem_id,
1426 cobill_qty : r.data.cobill_qty
1429 var doSubmit = function(){
1430 _this.form.findField('billitems').setValue(JSON.stringify(ar));
1431 _this.form.doAction("submit");
1434 if(hasListDiscount && orderQty != billQty){
1435 Roo.MessageBox.confirm("Confirm", "This Invoice contains a pre-tax discount - you can still invoice the customer however the calculations for discount will be inaccurate.",
1448 render : function (_self)
1450 _this.saveBtn = _self;