Exemplo n.º 1
0
 public function actionChart_month($year = null, $month = null)
 {
     $config = new \app\models\Config_system();
     $months = $config->MonthFullKey();
     $title = "ยอดกำไร - ขาดทุน ปี พ.ศ. ";
     $title .= $year + 543;
     $title .= " เดือน " . $months[$month];
     $labels = "รวมทั้งเดือน";
     $report = new Report();
     $result = $report->Report_month($year, $month);
     $sum_expenses_row = 0;
     $sum_total_row = 0;
     $sum_income = 0;
     $sum_outcome = 0;
     $income_month = 0;
     foreach ($result as $rs) {
         $day[] = $rs['DAY'];
         $sum_expenses_row = $rs['oil_price'] + $rs['gas_price'] + $rs['expenses_around'] + $rs['fix_truck'] + $rs['income_driver'] + $rs['truck_period'] + $rs['truck_act'];
         $sum_total_row = $rs['income'] - $sum_expenses_row;
         $income_month = $rs['income'];
         if (empty($income_month)) {
             $income = 0;
         } else {
             $income = $income_month;
         }
         if (empty($sum_expenses_row)) {
             $outcome = 0;
         } else {
             $outcome = $sum_expenses_row;
         }
         $value_income[] = (int) $income;
         $value_outcome[] = (int) $outcome;
         $sum_income = $sum_income + $rs['income'];
         //รายได้รวมทุกเดือน
         $sum_outcome = $sum_outcome + $sum_expenses_row;
         //รายจ่ายรวมทุกเดือน
     }
     //$val_income = implode('', $value_income);
     //$val_outcome = implode('', $value_outcome);
     return $this->renderAjax('chart', ['category' => $day, 'title' => $title, 'labels' => $labels, 'val_income' => $value_income, 'val_outcome' => $value_outcome, 'sumIncome' => (int) $sum_income, 'sumOutcome' => (int) $sum_outcome]);
 }