]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-1874 --resolve
authorMarc Olivier Chouinard <mochouinard@moctel.com>
Mon, 19 Dec 2011 05:14:03 +0000 (00:14 -0500)
committerMarc Olivier Chouinard <mochouinard@moctel.com>
Mon, 19 Dec 2011 05:14:03 +0000 (00:14 -0500)
Warning to nibblebill user.  This patch will change how billing amount is charged by using the previously unused nibble_inrement variable.  If you don't want to increase by increment, then just don't have the increment set

src/mod/applications/mod_nibblebill/mod_nibblebill.c

index 2cd772ece071d784d31a57ec87e1eaf026996040..cb9942e985f01d4586d2f26c278bd0075a03e754 100755 (executable)
@@ -397,6 +397,7 @@ static switch_status_t do_billing(switch_core_session_t *session)
        switch_size_t retsize;
        switch_time_exp_t tm;
        const char *billrate;
+       const char *billincrement;
        const char *billaccount;
        float nobal_amt = globals.nobal_amt;
        //float lowbal_amt = globals.lowbal_amt;
@@ -416,6 +417,7 @@ static switch_status_t do_billing(switch_core_session_t *session)
 
        /* Variables kept in FS but relevant only to this module */
        billrate = switch_channel_get_variable(channel, "nibble_rate");
+       billincrement = switch_channel_get_variable(channel, "nibble_increment");
        billaccount = switch_channel_get_variable(channel, "nibble_account");
        
        if (!zstr(switch_channel_get_variable(channel, "nobal_amt"))) {
@@ -493,8 +495,14 @@ static switch_status_t do_billing(switch_core_session_t *session)
                                          (int) ((ts - nibble_data->lastts) / 1000000), date);
 
        if ((ts - nibble_data->lastts) >= 0) {
-               /* Convert billrate into microseconds and multiply by # of microseconds that have passed since last *successful* bill */
-               billamount = ((float) atof(billrate) / 1000000 / 60) * ((ts - nibble_data->lastts)) - nibble_data->bill_adjustments;
+               /* If billincrement is set we bill by it and not by time elapsed */
+               if (!(switch_strlen_zero(billincrement))) {
+                       float chargedunits = ((int)((ts - nibble_data->lastts) / 1000000) <= (int)atof(billincrement)) ? ((float)atof(billincrement) * 1000000) :  ceil((ts - nibble_data->lastts) / ((float)atof(billincrement) * 1000000)) * ((float)atof(billincrement) * 1000000);
+                       billamount = ((float) atof(billrate) / 1000000 / 60) * chargedunits - nibble_data->bill_adjustments;
+               } else {                
+                       /* Convert billrate into microseconds and multiply by # of microseconds that have passed since last *successful* bill */
+                       billamount = ((float) atof(billrate) / 1000000 / 60) * ((ts - nibble_data->lastts)) - nibble_data->bill_adjustments;
+               }
 
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Billing $%f to %s (Call: %s / %f so far)\n", billamount, billaccount,
                                                  uuid, nibble_data->total);