예제 #1
0
    public function actionGetCartridgeStat($from_date, $till_date)
    {
        $cart_types = CartridgeType::find()->orderBy('used DESC')->all();
        $departments = department::find()->where(['active' => 1])->orderBy('value ASC')->all();
        if ($from_date && $till_date) {
            $cart_history = CartridgeHistory::find()->where(['>=', 'add_date', $from_date])->andWhere(['<=', 'add_date', $till_date])->all();
        } else {
            $cart_history = CartridgeHistory::find()->all();
        }
        echo '<table class = "table table-hover table-condensed"><tr><td>Подразделение / Картридж</td>';
        foreach ($cart_types as $type) {
            echo '<td>' . $type->type . '</td>';
        }
        echo '<td>Все</td>';
        echo '</tr>';
        foreach ($departments as $dep) {
            echo '<tr>
					<td>' . $dep->value . '</td>';
            $all_type_count = 0;
            foreach ($cart_types as $type) {
                $type_count = 0;
                foreach ($cart_history as $cart) {
                    // if ( $cart -> room_id != null ){
                    // $cart_build = building::findOne($cart -> room_id);
                    // // $cart_build_id = $cart_build -> id;
                    // $cart_dep = department::findOne($cart_build['id']);
                    // $cart_dep_id = $cart_dep['id'];
                    // }
                    // else{
                    // if( $cart -> building_id != null ){
                    // $cart_dep = department::findOne( $cart -> building_id );
                    // $cart_dep_id = $cart_dep -> id;
                    // }
                    // else{
                    // if($cart -> department_id != null ){
                    // $cart_dep_id = $cart -> department_id;
                    // }
                    // }
                    // }
                    if ($cart->department_id == $dep->id && $cart->cartridge_type == $type->type) {
                        // if ( $cart_dep_id == $dep -> id && $cart -> cartridge_type == $type -> type ){
                        $type_count++;
                        $all_type_count++;
                    }
                }
                echo $type_count ? '<td style = "color : red"><strong>' . $type_count . '</strong></td>' : '<td>' . $type_count . '</td>';
            }
            echo $all_type_count ? '<td style = "color : red"><strong>' . $all_type_count . '</strong></td>' : '<td>' . $all_type_count . '</td>';
            echo '</tr>';
        }
        echo '<tr><td>Все</td>';
        foreach ($cart_types as $type) {
            $type_count = 0;
            foreach ($cart_history as $cart) {
                if ($cart->cartridge_type == $type->type) {
                    $type_count++;
                }
            }
            echo $type_count ? '<td style = "color : red"><strong>' . $type_count . '</strong></td>' : '<td>' . $type_count . '</td>';
        }
        echo '<td style = "color : red"><strong>' . count($cart_history) . '</strong></td>';
        '</tr>';
        echo '</table>';
    }
예제 #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCartridgeHistories()
 {
     return $this->hasMany(CartridgeHistory::className(), ['cartridge_type' => 'type']);
 }