1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Improve resolution of decimals

This commit is contained in:
David Bomba 2023-02-08 11:27:38 +11:00
parent ebf99689d1
commit 16b1ec6286
2 changed files with 25 additions and 20 deletions

View File

@ -223,15 +223,15 @@ class Number
/* 08-01-2022 allow increased precision for unit price*/
$v = rtrim(sprintf('%f', $value), '0');
// $precision = strlen(substr(strrchr($v, $decimal), 1));
if ($v < 1) {
/* 08-02-2023 special if block to render $0.5 to $0.50*/
if ($v < 1 && strlen($v) == 3) {
$precision = 2;
}
elseif ($v < 1) {
$precision = strlen($v) - strrpos($v, '.') - 1;
}
// if($precision == 1)
// $precision = 2;
$value = number_format($v, $precision, $decimal, $thousand);
$symbol = $currency->symbol;

View File

@ -43,52 +43,57 @@ class TaskApiTest extends TestCase
Model::reguard();
}
private function checkTimeLog($log)
private function checkTimeLog(array $log): bool
{
if(count($log) == 0)
return true;
/*Get first value of all arrays*/
$result = array_column($log, 0);
/*Sort the array in ascending order*/
asort($result);
$new_array = [];
/*Rebuild the array in order*/
foreach($result as $key => $value)
$new_array[] = $log[$key];
/*Iterate through the array and perform checks*/
foreach($new_array as $key => $array)
{
/*Flag which helps us know if there is a NEXT timelog*/
$next = false;
/* If there are more than 1 time log in the array, ensure the last timestamp is not zero*/
if(count($new_array) >1 && $array[1] == 0)
return false;
/* First test is to check if the start time is greater than the end time */
/* Check if the start time is greater than the end time */
/* Ignore the last value for now, we'll do a separate check for this */
if($array[0] > $array[1] && $array[1] != 0){
if($array[0] > $array[1] && $array[1] != 0)
return false;
}
if(array_key_exists($key+1, $new_array)){
/* Find the next time log value - if it exists */
if(array_key_exists($key+1, $new_array))
$next = $new_array[$key+1];
}
/* check the next time log and ensure the start time is GREATER than the end time of the previous record */
if($next && $next[0] < $array[1]){
if($next && $next[0] < $array[1])
return false;
}
/* Get the last row of the timelog*/
$last_row = end($new_array);
if($last_row[1] != 0 && $last_row[0] > $last_row[1]){
nlog($last_row[0]. " ".$last_row[1]);
/*If the last value is NOT zero, ensure start time is not GREATER than the endtime */
if($last_row[1] != 0 && $last_row[0] > $last_row[1])
return false;
}
return true;
}
}
public function testTimeLogChecker1()
{