Skip to content

Commit

Permalink
resolve KAZOO-755: update the cdr view with the caculation done for p…
Browse files Browse the repository at this point in the history
…vt_vsn 2 cdrs
  • Loading branch information
k-anderson committed Mar 26, 2013
1 parent 6db953c commit 6eabc38
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion whistle_apps/apps/crossbar/priv/couchdb/account/cdrs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"language": "javascript",
"views": {
"crossbar_listing": {
"map": "function(doc){if(doc.pvt_deleted||doc.pvt_type!='cdr'){return;}var Secs=doc.billing_seconds||0;var cost=0;if(Secs>=1&&doc.custom_channel_vars&&doc.custom_channel_vars.account_billing=='per_minute'){var R=parseFloat(doc.custom_channel_vars.rate)||0;var RInc=parseInt(doc.custom_channel_vars.increment)||60;var RMin=parseInt(doc.custom_channel_vars.rate_minimum)||0;var Sur=parseInt(doc.custom_channel_vars.surcharge)||0;var Sur=parseFloat(doc.custom_channel_vars.surcharge)||0;R=Math.round(R*10000);Sur=Math.round(Sur*10000);if(RInc<1){RInc=60;}if(Secs<=RMin){cost=Sur+((RMin/60)*R);}else{cost=Sur+((RMin/60)*R)+(Math.ceil((Secs-RMin)/RInc)*((RInc/60)*R));}}emit(doc.pvt_created,{id:doc._id,caller_id_name:doc.caller_id_name,caller_id_number:doc.caller_id_number,callee_id_name:doc.callee_id_name,callee_id_number:doc.callee_id_number,duration_seconds:doc.duration_seconds,billing_seconds:doc.billing_seconds,timestamp:doc.timestamp,hangup_cause:doc.hangup_cause,other_leg_call_id:doc.other_leg_call_id,owner_id:doc.custom_channel_vars.owner_id,to:doc.to_uri,from:doc.from_uri,inception:doc.custom_channel_vars.inception,cost:cost});}"
"map": "function (doc) {if (doc.pvt_deleted || doc.pvt_type != 'cdr') return;if (doc.pvt_type == 'cdr' && doc.custom_channel_vars && (doc.custom_channel_vars.account_billing == 'per_minute' || doc.custom_channel_vars.account_billing == 'per_minute_limit') && doc.custom_channel_vars.account_id == doc.pvt_account_id && doc.pvt_vsn && parseInt(doc.pvt_vsn) == 2) {var Secs = (parseInt(doc.billing_seconds) || 0) - (parseInt(doc.custom_channel_vars.billing_seconds_offset) || 0);var Cost = 0;if (Secs >= 1) {var R = parseInt(doc.custom_channel_vars.rate) || 0;var RInc = parseInt(doc.custom_channel_vars.increment) || 60;var RMin = parseInt(doc.custom_channel_vars.rate_minimum) || 0;var Sur = parseInt(doc.custom_channel_vars.surcharge) || 0;if (RInc < 1) {RInc = 60;}if (Secs <= RMin) {Cost = Sur + ((RMin / 60) * R);} else {Cost = Sur + ((RMin / 60) * R) + (Math.ceil((Secs - RMin) / RInc) * ((RInc / 60) * R));}}}if (Cost) {var Discount = (parseInt(doc.custom_channel_vars.discount_percentage) || 0) * 0.01 * Cost;emit(doc.pvt_created, {id: doc._id,caller_id_name: doc.caller_id_name,caller_id_number: doc.caller_id_number,callee_id_name: doc.callee_id_name,callee_id_number: doc.callee_id_number,duration_seconds: doc.duration_seconds,billing_seconds: doc.billing_seconds,timestamp: doc.timestamp,hangup_cause: doc.hangup_cause,other_leg_call_id: doc.other_leg_call_id,owner_id: doc.custom_channel_vars.owner_id,to: doc.to_uri,from: doc.from_uri,inception: doc.custom_channel_vars.inception,cost: Cost - Discount});} else {emit(doc.pvt_created, {id: doc._id,caller_id_name: doc.caller_id_name,caller_id_number: doc.caller_id_number,callee_id_name: doc.callee_id_name,callee_id_number: doc.callee_id_number,duration_seconds: doc.duration_seconds,billing_seconds: doc.billing_seconds,timestamp: doc.timestamp,hangup_cause: doc.hangup_cause,other_leg_call_id: doc.other_leg_call_id,owner_id: doc.custom_channel_vars.owner_id,to: doc.to_uri,from: doc.from_uri,inception: doc.custom_channel_vars.inception});}}"
},
"listing_by_owner" : {
"map": "function(doc) { if(doc.pvt_deleted || !doc.custom_channel_vars.owner_id || doc.pvt_type != 'cdr') return; emit([doc.custom_channel_vars.owner_id, doc.pvt_created], {'id':doc._id, 'caller_id_name': doc.caller_id_name, 'caller_id_number': doc.caller_id_number, 'callee_id_name': doc.callee_id_name, 'callee_id_number': doc.callee_id_number, 'duration_seconds': doc.duration_seconds, 'timestamp': doc.timestamp, 'hangup_cause':doc.hangup_cause, 'other_leg_call_id':doc.other_leg_call_id, 'call_direction':doc.call_direction, 'to': doc.to_uri, 'from': doc.from_uri, 'inception':doc.custom_channel_vars.inception})}"
Expand Down

0 comments on commit 6eabc38

Please sign in to comment.