Code Duplication    Length = 26-27 lines in 2 locations

query/BillableFlightQueryHandler.php 2 locations

@@ 80-106 (lines=27) @@
77
        //total orga
78
        $sql = 'SELECT llx_user.lastname as name , llx_user.firstname,llx_user.rowid, count(idBBC_vols) as total FROM llx_bbc_vols LEFT JOIN llx_user ON rowid = fk_organisateur WHERE YEAR(date) = \'' . $query->getFiscalYear() . '\' AND fk_type IN (1,2) GROUP BY fk_organisateur';
79
        $resql = $this->db->query($sql);
80
        if ($resql) {
81
            $num = $this->db->num_rows($resql);
82
            $i = 0;
83
            if ($num) {
84
                while ($i < $num) {
85
                    $obj = $this->db->fetch_object($resql); //vol
86
87
                    if ($obj) {
88
89
                        if (!isset($array[$obj->rowid])) {
90
                            $name = $obj->firstname . ' ' . $obj->name;
91
                            $pilot = Pilot::create($name, $obj->rowid);
92
                            $array[$obj->rowid] = $pilot;
93
                        }
94
95
                        $array[$obj->rowid] = $array[$obj->rowid]->addCount(
96
                            new FlightTypeCount(
97
                                'orga',
98
                                $obj->total,
99
                                $this->getFactorByType('orga')
100
                            )
101
                        );
102
                    }
103
                    $i++;
104
                }
105
            }
106
        }
107
108
        //total orga T6 - instructeur
109
        $sql = 'SELECT llx_user.lastname as name , llx_user.firstname,llx_user.rowid, count(idBBC_vols) as total FROM llx_bbc_vols LEFT JOIN llx_user ON rowid = fk_organisateur WHERE YEAR(date) = \'' . $query->getFiscalYear() . '\' AND fk_type = 6 GROUP BY fk_organisateur';
@@ 111-136 (lines=26) @@
108
        //total orga T6 - instructeur
109
        $sql = 'SELECT llx_user.lastname as name , llx_user.firstname,llx_user.rowid, count(idBBC_vols) as total FROM llx_bbc_vols LEFT JOIN llx_user ON rowid = fk_organisateur WHERE YEAR(date) = \'' . $query->getFiscalYear() . '\' AND fk_type = 6 GROUP BY fk_organisateur';
110
        $resql = $this->db->query($sql);
111
        if ($resql) {
112
            $num = $this->db->num_rows($resql);
113
            $i = 0;
114
            if ($num) {
115
                while ($i < $num) {
116
                    $obj = $this->db->fetch_object($resql); //vol
117
118
                    if ($obj) {
119
                        if (!isset($array[$obj->rowid])) {
120
                            $name = $obj->firstname . ' ' . $obj->name;
121
                            $pilot = Pilot::create($name, $obj->rowid);
122
                            $array[$obj->rowid] = $pilot;
123
                        }
124
125
                        $array[$obj->rowid] = $array[$obj->rowid]->addCount(
126
                            new FlightTypeCount(
127
                                'orga_T6',
128
                                $obj->total,
129
                                $this->getFactorByType('orga_T6')
130
                            )
131
                        );
132
                    }
133
                    $i++;
134
                }
135
            }
136
        }
137
138
        return $array;
139
    }