Beispiel #1
0
 public function consum_lunar($facturi)
 {
     $out = [];
     /*for($i = 1; $i <= 12; $i++){
           $out[$i] = [];
       }*/
     foreach ($facturi as $k => $factura) {
         $month = (new Carbon($factura->date_bill))->month;
         $year = (new Carbon($factura->date_bill))->year;
         if (array_key_exists($year, $out)) {
             $out[$year]['value'] += (double) $factura->value_witch_tva;
             $out[$year]['months'][$month] = array_key_exists($month, $out[$year]['months']) ? $out[$year]['months'][$month] + (double) $factura->value_witch_tva : (double) $factura->value_witch_tva;
         } else {
             $out[$year] = [];
             $out[$year]['value'] = 0;
             $out[$year]['months'] = [];
             $out[$year]['months'] = _before_out($out[$year]['months'], 1, 12);
             $out[$year]['value'] = (double) $factura->value_witch_tva;
             $out[$year]['months'][$month] = (double) $factura->value_witch_tva;
         }
     }
     /*in out avem lunile si consumul total pe acele luni*/
     return $out;
 }
Beispiel #2
0
function _year_years_total($array, $length)
{
    $out = [];
    if (count($array) != $length) {
        $array = _before_out($array, $length);
    }
    for ($j = 1; $j <= 12; $j++) {
        $out[$j] = $array[$j];
    }
    $index = 13;
    $summ = 0;
    for ($i = 1; $i <= $length; $i++) {
        $summ += $array[$i];
        if ($i % 12 == 0) {
            /*avem un an*/
            $out[$index] = $summ;
            $index++;
            $summ = 0;
        }
    }
    /*
     * $out[1] = value
     * $out[..] = value
     * */
    return $out;
}