Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Charges / Billing

Posted on 2013-07-01
5
Medium Priority
?
239 Views
Last Modified: 2013-07-01
Price: 0.09

I need to charge 0.09 for every 30 seconds.

Say total time are 37 seconds. The charges are 0.18

If it's 1-30 seconds, the charge is 0.09

Basically, every 30 seconds, I am supposed to charge 0.09

How do I translate this into PHP code?
0
Comment
Question by:rolandmy
  • 2
  • 2
5 Comments
 
LVL 2

Author Comment

by:rolandmy
ID: 39289716
I kind of like found a way to do it. Refer to below. Is there a better way of doing it? I kind of feel like I am using the long way to go about it =/

 if ($billing=='xx') {
      $price='0.07';
  }else{
        $price='0.09';
  }
 
  $charge = $durationtime/30;
 
  if ( preg_match("/\./", $charge) ) {
        $actualcharge = intval($charge) + 1;
        }else{
              $actualcharge = intval($charge) + 0;
              }
0
 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 39289767
Use the ceil() function to get your 'multiplier', and then simply do the math:

$charge = 0.09;
$seconds = 39;
$total = ceil($sec/30) * $charge;

echo $total

Open in new window

and don't put quotes around your values - they then become strings!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39289769
Here is how to handle DATETIME information in PHP and MySQL.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

To determine an elapsed time in seconds, create timestamps and subtract.  To determine 30 second intervals or parts of 30 second intervals, use ceil() after dividing the number of seconds by 30.
0
 
LVL 44

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 200 total points
ID: 39289775
Variable mis-match in my previous code:

$charge = 0.09;
$seconds = 39;
$total = ceil($seconds/30) * $charge;

echo $total;

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1000 total points
ID: 39289823
This seems to test out OK.
http://www.laprbass.com/RAY_temp_rolandmy.php

<?php // RAY_temp_rolandmy.php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');

// THE RATE PER PERIOD
$rate = 0.09;

// THE DURATION OF THE PERIOD IN SECONDS
$dura = 30;

// THE ELAPSED TIME PERIOD OF SERVICE
$alpha = 'Today 11:58:03 pm';
$omega = 'Tomorrow 00:00:17';

// CREATE TIMESTAMPS AND GET SECONDS
$a_ts = strtotime($alpha);
$z_ts = strtotime($omega);
$secs  = $z_ts - $a_ts;

// COMPUTE CHARGES
$bill = ceil($secs/$dura) * $rate;

// REPORT THE WORK
echo "FROM $alpha TO $omega THERE ARE $secs SECONDS AND THE CHARGE IS " . '$' . number_format($bill,2);

Open in new window

Best regards, ~Ray
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question