<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<style>BODY{font:10pt Tahoma, Verdana, sans-serif}</style></head><body>
<DIV>This is a major can of worms. I have an comericial carrier softswitch based on FS, and what I did to be able to imlment billing the right legs to the right account was the following:</DIV>
<DIV>&nbsp;</DIV>
<DIV>Have a flag on your gateways so you can mark them as "pstn-uplink", or whatever you want to call it. This way you know that it's the "other" leg's endpoint is the entity you want to bill. </DIV>
<DIV>&nbsp;</DIV>
<DIV>Next, in your directory, make sure you set a variable for the user that has it's billing identity for example "myapp_user" or "myapp_account". If you use account then you can associate more then one user to the same account, if that's the way you're billing works.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Now, if you make sure all calls to users, use the <A href="mailto:user/username@domain">user/username@domain</A> form of the dial string, you will also have the variable set on calls terminating to that user. Now you can bill, on normal calls both incoming calls (charge for DID usage) and outbound calls.</DIV>
<DIV>&nbsp;</DIV>
<DIV>When you get any inbound call from a gateway that's marked as "PSTN" then set a variable on that leg, when it calls a user, that indicates it's the PAID inbound leg for that user, before bridging to the "user" channel.</DIV>
<DIV>&nbsp;</DIV>
<DIV>To implment forwarding, in your processing of a call to a user, before bridging to the "user" channel, see if the users is forwarding, if so all you have to do, in your dialplan, or external code handling the dialplan is: "set_user to the user they called", then "transfer to: ${Forwarding_number} XML ${user_context}". Because you did the "set_user" first, the call will go back to CS_ROUTING, but look like it's from the user that did the forwarding. This way, if the call is from a gateway that isn't in the right context to dial the forwarding number, it won't matter, and the B-LEG will go through your dialplan logic, like the call is made form the user, and you can set a variable on the B_LEG in the dial string to tell it who the call is on behalf of, if it goes out a gateway that is marked as "PSTN".</DIV>
<DIV>&nbsp;</DIV>
<DIV>This way the same logic of how you tag the PSTN leg as being called from a user, is the same for a call made from the user, or forwared by the user. </DIV>
<DIV>&nbsp;</DIV>
<DIV>Since any users in the middle that are forwarding to internal numbers, it doesn't matter how many forwarding hops you go through, the original A-LEG if PSTN will get billed to the user it called, and the final B-LEG will get biled to the user that did the forwarding, that caused the call to leave your switch.</DIV>
<DIV>&nbsp;</DIV>
<DIV>--Dave</DIV><BR>
<BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
<HR>
<B>From:</B> Jon Schøpzinsky [mailto:jos@firstcom.dk]<BR><B>To:</B> FreeSWITCH Users Help [mailto:freeswitch-users@lists.freeswitch.org]<BR><B>Sent:</B> Mon, 27 May 2013 09:01:49 -0700<BR><B>Subject:</B> [Freeswitch-users] Splitting CDRs on call forward<BR><BR>Hi List,<BR><BR>I am implementing call forwarding on a multi tenant system, and therefore<BR>need to split CDR's when the call forward happens, so that if the<BR>receiving user also has his account call forwarded, he pays for his part<BR>of the call.<BR><BR>A calls B<BR>B forwards to C<BR>C forwards to an external mobile phone.<BR><BR>B has a free call from B to C, but C needs to pay for the forwarding to<BR>the mobile phone. Therefore i need a separate CDR for the C to Mobile<BR>phone call.<BR><BR>Another example would be this<BR><BR>A works in Company A, and B works in Company B<BR>They are both users on our system, and therefore is on the same freeswitch.<BR><BR>A calls B<BR>B Forwards to an external mobile phone.<BR><BR>Here A needs to pay for the call from A to B, and B needs to pay for the<BR>call being forwarded to his mobile phone.<BR><BR>Do anybody have an idea as to how to implement this in freeswitch. Back in<BR>my Asterisk days, this would be done by the ForkCDR command.<BR><BR><BR>Venlig hilsen/kind regards<BR><BR>Jon Leren Schøpzinsky<BR><BR><BR>_________________________________________________________________________<BR>Professional FreeSWITCH Consulting Services:<BR><A href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</A><BR><A href="http://www.freeswitchsolutions.com/" target=_blank>http://www.freeswitchsolutions.com</A><BR><BR>FreeSWITCH-powered IP PBX: The CudaTel Communication Server<BR><A href="http://www.cudatel.com/" target=_blank>http://www.cudatel.com</A><BR><BR>Official FreeSWITCH Sites<BR><A href="http://www.freeswitch.org/" target=_blank>http://www.freeswitch.org</A><BR><A href="http://wiki.freeswitch.org/" target=_blank>http://wiki.freeswitch.org</A><BR><A href="http://www.cluecon.com/" target=_blank>http://www.cluecon.com</A><BR><BR>FreeSWITCH-users mailing list<BR><A href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</A><BR><A href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target=_blank>http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</A><BR>UNSUBSCRIBE:<A href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target=_blank>http://lists.freeswitch.org/mailman/options/freeswitch-users</A><BR><A href="http://www.freeswitch.org/" target=_blank>http://www.freeswitch.org</A><BR></BLOCKQUOTE>
<STYLE>
</STYLE>

<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></body></html>