Beispiel #1
0
 private function nuGetFieldValue($O)
 {
     $type = '';
     $value = '';
     if (strtoupper(substr($O->fieldName, 0, 4)) == 'SUM(') {
         $type = 's';
         $field = substr($O->fieldName, 4, -1);
     }
     if (strtoupper(substr($O->fieldName, 0, 8)) == 'AVERAGE(') {
         $type = 'p';
         $fields = explode(',', substr($O->fieldName, 8, -1));
     }
     if ($type == '') {
         //-- normal value
         //Add the 'is_array' check by SG 8th May 2015
         if (is_array($this->ROW)) {
             if (array_key_exists($O->fieldName, $this->ROW)) {
                 $v = $this->nuGetFormatting($O);
                 $value = mb_convert_encoding($v['V'], "WINDOWS-1252", "UTF-8");
             }
         }
     } else {
         //-- summed value
         $groups = array();
         $where = '';
         if ($type == 'p') {
             $count = 'SUM(nu_sum_' . trim($fields[0]) . ') AS the_sum_a, SUM(nu_sum_' . trim($fields[1]) . ') AS the_sum_b';
         } else {
             $count = 'SUM(nu_sum_' . trim($field) . ') AS the_sum_a';
         }
         for ($i = 3; $i <= $this->group; $i++) {
             $groups[] = $this->LAY->groups[$i]->sortField . " = '" . str_replace("'", "\\'", $this->ROW[$this->LAY->groups[$i]->sortField]) . "'";
             $where = ' WHERE ';
         }
         $sql = "SELECT {$count} FROM {$this->TABLE_ID}" . "_nu_summary {$where} " . implode(' AND ', $groups);
         $t = nuRunQuery($sql);
         $r = db_fetch_row($t);
         if ($r[1] == 0 and $type == 'p') {
             $value = 0;
         } else {
             if ($type == 'p') {
                 //                    $value  = ($r[0] / $r[1]) * 100;
                 $value = $r[0] / $r[1];
             } else {
                 $value = $r[0];
             }
         }
     }
     if ($O->format != '') {
         //-- format value
         $format = nuTextFormats();
         $datatype = $format[$O->format]->type;
         if ($datatype == 'date') {
             if ($value != '0000-00-00' && $value != '') {
                 $value = date($format[$O->format]->phpdate, strtotime($value));
             } else {
                 $value = '';
             }
         }
         if ($datatype == 'number') {
             $value = number_format($value, $format[$O->format]->format, $format[$O->format]->decimal, $format[$O->format]->separator);
         }
     }
     return $value;
 }
Beispiel #2
0
function nuFormatValue($value, $formatNumber)
{
    if ($formatNumber == '') {
        return $value;
    }
    //-- no format
    if ($value == '') {
        return $value;
    }
    //-- no format
    if (substr($value, 0, 10) == '0000-00-00') {
        return '';
    }
    //-- null date
    $format = nuTextFormats();
    $sql = $format[$formatNumber]->sql;
    $sql = 'SELECT ' . str_replace('??', "'" . $value . "'", $sql);
    $t = nuRunQuery($sql);
    if (nuErrorFound()) {
        return;
    }
    $r = db_fetch_row($t);
    $v = $r[0];
    if ($format[$formatNumber]->type == 'number') {
        $v = str_replace(',', 'sep', $v);
        $v = str_replace('.', 'dec', $v);
        $v = str_replace('sep', $format[$formatNumber]->separator, $v);
        $v = str_replace('dec', $format[$formatNumber]->decimal, $v);
    }
    return $v;
}