mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 11:24:34 -04:00
Improve resolution of decimals
This commit is contained in:
parent
ebf99689d1
commit
16b1ec6286
@ -223,15 +223,15 @@ class Number
|
|||||||
|
|
||||||
/* 08-01-2022 allow increased precision for unit price*/
|
/* 08-01-2022 allow increased precision for unit price*/
|
||||||
$v = rtrim(sprintf('%f', $value), '0');
|
$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;
|
$precision = strlen($v) - strrpos($v, '.') - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if($precision == 1)
|
|
||||||
// $precision = 2;
|
|
||||||
|
|
||||||
$value = number_format($v, $precision, $decimal, $thousand);
|
$value = number_format($v, $precision, $decimal, $thousand);
|
||||||
$symbol = $currency->symbol;
|
$symbol = $currency->symbol;
|
||||||
|
|
||||||
|
@ -43,52 +43,57 @@ class TaskApiTest extends TestCase
|
|||||||
Model::reguard();
|
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);
|
$result = array_column($log, 0);
|
||||||
|
|
||||||
|
/*Sort the array in ascending order*/
|
||||||
asort($result);
|
asort($result);
|
||||||
|
|
||||||
$new_array = [];
|
$new_array = [];
|
||||||
|
|
||||||
|
/*Rebuild the array in order*/
|
||||||
foreach($result as $key => $value)
|
foreach($result as $key => $value)
|
||||||
$new_array[] = $log[$key];
|
$new_array[] = $log[$key];
|
||||||
|
|
||||||
|
/*Iterate through the array and perform checks*/
|
||||||
foreach($new_array as $key => $array)
|
foreach($new_array as $key => $array)
|
||||||
{
|
{
|
||||||
|
/*Flag which helps us know if there is a NEXT timelog*/
|
||||||
$next = false;
|
$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)
|
if(count($new_array) >1 && $array[1] == 0)
|
||||||
return false;
|
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 */
|
/* 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;
|
return false;
|
||||||
}
|
|
||||||
|
/* Find the next time log value - if it exists */
|
||||||
if(array_key_exists($key+1, $new_array)){
|
if(array_key_exists($key+1, $new_array))
|
||||||
$next = $new_array[$key+1];
|
$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 */
|
/* 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;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Get the last row of the timelog*/
|
||||||
$last_row = end($new_array);
|
$last_row = end($new_array);
|
||||||
|
|
||||||
if($last_row[1] != 0 && $last_row[0] > $last_row[1]){
|
/*If the last value is NOT zero, ensure start time is not GREATER than the endtime */
|
||||||
nlog($last_row[0]. " ".$last_row[1]);
|
if($last_row[1] != 0 && $last_row[0] > $last_row[1])
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTimeLogChecker1()
|
public function testTimeLogChecker1()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user