예제 #1
0
 public function testext_invoice_round_value()
 {
     $this->assertSame(17.0, ext_invoice_round_value(17, 0.0));
     $this->assertSame(22.0, ext_invoice_round_value(22, 0));
     $this->assertSame(35.0, ext_invoice_round_value(35.37, 0));
     $this->assertSame(45.5, ext_invoice_round_value(45.37, 0.5));
     $this->assertSame(55.5, ext_invoice_round_value(55.25, 0.5));
     $this->assertSame(65.0, ext_invoice_round_value(65.23999999999999, 0.5));
     $this->assertSame(64.5, ext_invoice_round_value(65.23999999999999, 1.5));
     $this->assertSame(67.2, ext_invoice_round_value(66.40000000000001, 1.6));
 }
예제 #2
0
파일: print.php 프로젝트: kimai/kimai
$round = 0;
// do we have to round the time ?
if (isset($_REQUEST['roundValue']) && (double) $_REQUEST['roundValue'] > 0) {
    $round = (double) $_REQUEST['roundValue'];
    $time_index = 0;
    $amount = count($invoiceArray);
    while ($time_index < $amount) {
        if ($invoiceArray[$time_index]['type'] == 'timeSheet') {
            $rounded = ext_invoice_round_value($invoiceArray[$time_index]['hour'], $round / 10);
            // Write a logfile entry for each value that is rounded.
            Kimai_Logger::logfile("Round " . $invoiceArray[$time_index]['hour'] . " to " . $rounded . " with " . $round);
            if ($invoiceArray[$time_index]['hour'] == 0) {
                // make sure we do not raise a "divison by zero" - there might be entries with the zero seconds
                $rate = 0;
            } else {
                $rate = ext_invoice_round_value($invoiceArray[$time_index]['amount'] / $invoiceArray[$time_index]['hour'], 0.05);
            }
            $invoiceArray[$time_index]['hour'] = $rounded;
            $invoiceArray[$time_index]['amount'] = $invoiceArray[$time_index]['hour'] * $rate;
        }
        $time_index++;
    }
}
// calculate invoice sums
$ttltime = 0;
$rawTotalTime = 0;
$total = 0;
while (list($id, $fd) = each($invoiceArray)) {
    $total += $invoiceArray[$id]['amount'];
    $ttltime += $invoiceArray[$id]['hour'];
}