Difference between revisions of "Export generator 4"
(→Total Flight hours per pilot with total duration and total amount) |
(→Booking) |
||
(244 intermediate revisions by 5 users not shown) | |||
Line 6: | Line 6: | ||
Please note that you can make "public" a report, ie. allows standard users to see and interact with it. | Please note that you can make "public" a report, ie. allows standard users to see and interact with it. | ||
− | == | + | ==Business field== |
− | + | ||
− | Two | + | For more flexibility, business field can be defined by the user. |
+ | |||
+ | Two business field types are available: | ||
*"external parameters" of following types: | *"external parameters" of following types: | ||
− | |||
− | |||
**Date | **Date | ||
− | |||
**Date and time | **Date and time | ||
− | *database parameters (dbObject::something Value type) advanced options to access | + | **Month |
+ | **Text string | ||
+ | **Time | ||
+ | **Whole number | ||
+ | **Year | ||
+ | *database parameters (dbObject::something or dbObjectMulti::something Value type) advanced options to access to the database field | ||
− | === | + | ===[[OF_doc4-fr::Gestion-des-rapports#Ajouter-un-champ-dans-le-formulaire-des-rapports|Business field creation]]=== |
− | *Go to Menu '''Admin > Reports > | + | *Go to Menu '''Admin > Reports > Custom reports > Business Field(s)''' |
In the bottom line add | In the bottom line add | ||
*Fill the '''name''' field with a name that will be use within the SQL queries (prefixed with the $ character) | *Fill the '''name''' field with a name that will be use within the SQL queries (prefixed with the $ character) | ||
Line 27: | Line 30: | ||
Then within your SQL query, you may add this parameter which will be replace by the value chosen by the user filling the export form. | Then within your SQL query, you may add this parameter which will be replace by the value chosen by the user filling the export form. | ||
− | If you define a parameter as a database parameters (for example dbObject:: | + | If you define a parameter as a database parameters (for example dbObject::Person) then the form will display a combo with the list of users and your parameter will be replace by the id integer of the chosen person. |
− | === | + | ===Business field creation examples=== |
− | We create a new | + | We create a new business field for the current year: |
*Name: $year | *Name: $year | ||
*Label: Year | *Label: Year | ||
*Value type: Year | *Value type: Year | ||
− | Parameter Year must be | + | Parameter Year must be filled in '''Reports/View''' form before to call the query (by default current year is filled when you call the page) |
− | We create a new | + | We create a new business field to list the reservation of a resource: |
− | *Name: $ | + | *Name: $resourceId |
− | *Label: | + | *Label: Resource |
− | *Value type: dbObject:: | + | *Value type: dbObject::Resource |
− | Then in Admin/Reports | + | Then in '''Admin/Reports''' we create a new query labeled "Aircraft booking" with the following query: |
− | <sql>SELECT * FROM booking WHERE booking. | + | <sql>SELECT * FROM booking WHERE booking.resource_id=$resourceId</sql> |
− | To use this report, we just have to select a " | + | To use this report, we just have to select a "Resource" in the '''Reports/View''' form, to check "Resource booking" then to click on "View" |
=SQL tips and tricks= | =SQL tips and tricks= | ||
Line 51: | Line 54: | ||
==Test valid entries== | ==Test valid entries== | ||
− | For | + | For business fields that are text inputs, any entry can be submitted and added to SQL query. In order to test valid entries, it is recommended to use the '''IF''' statement in the '''WHERE''' statement. |
Per example, $occupiedSeat can have following values (0, 1 or NULL) : | Per example, $occupiedSeat can have following values (0, 1 or NULL) : | ||
Line 65: | Line 68: | ||
=French administration Examples= | =French administration Examples= | ||
− | == | + | ==Flight hours total on instruction with specific activity type/profile== |
− | * Variable '''$ | + | Requirement: |
− | * Variable '''$profileId''' | + | * Variable '''$activityTypeId''' of '''dbOjectMulti::ActivityType''' value type |
− | * Variable '''$year''' | + | * Variable '''$profileId''' of '''dbOjectMulti::Profile''' value type |
+ | * Variable '''$year''' of '''Year''' value type | ||
− | <sql>SELECT name, | + | <sql>SELECT tmp_flight.activity_type_name AS name, |
sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS 'Avion', | sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS 'Avion', | ||
sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS 'Hélicoptère', | sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS 'Hélicoptère', | ||
Line 78: | Line 82: | ||
FROM ( | FROM ( | ||
SELECT | SELECT | ||
− | + | flightWithActivityType.activity_type_id, | |
− | + | flightWithActivityType.activity_type_name, | |
− | + | flightWithActivityType.duration, | |
resource_type.category | resource_type.category | ||
− | FROM flight | + | FROM ( |
− | + | SELECT flight.id, flight.duration, flight.aircraft_id, activity_type.id AS activity_type_id, activity_type.name AS activity_type_name | |
− | LEFT JOIN flight_pilot ON (flight_pilot.flight_id= | + | FROM flight |
− | LEFT JOIN person ON (person.id=flight_pilot.pilot_id) | + | LEFT JOIN activity_type ON flight.activity_type_id&activity_type.id |
− | LEFT JOIN resource ON (resource.id= | + | WHERE YEAR(flight.start_date)=$year |
+ | AND flight.airborne=0 | ||
+ | AND ( activity_type.id IN ($activityTypeId) OR '' IN ($activityTypeId) ) | ||
+ | ) AS flightWithActivityType | ||
+ | LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flightWithActivityType.id AND flight_pilot.num=1) | ||
+ | LEFT JOIN ( | ||
+ | SELECT person.* | ||
+ | FROM person | ||
+ | LEFT JOIN profile ON person.profile&profile.id | ||
+ | WHERE ( profile.id IN ($profileId) OR '' IN ($profileId) ) | ||
+ | AND person.activated=1 | ||
+ | GROUP BY person.id | ||
+ | ) AS personWithProfile ON (personWithProfile.id=flight_pilot.pilot_id) | ||
+ | LEFT JOIN resource ON (resource.id=flightWithActivityType.aircraft_id) | ||
LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) | LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) | ||
− | WHERE | + | WHERE personWithProfile.id IS NOT NULL |
− | + | ||
− | + | ||
− | + | ||
) AS tmp_flight | ) AS tmp_flight | ||
− | GROUP BY | + | GROUP BY tmp_flight.activity_type_id</sql> |
− | == | + | ==Flight hours total on non-instruction with specific activity type/profile== |
− | * Variable '''$ | + | Requirement: |
− | * Variable '''$profileId''' | + | * Variable '''$activityTypeId''' of '''dbOjectMulti::ActivityType''' value type |
− | * Variable '''$year''' | + | * Variable '''$profileId''' of '''dbOjectMulti::Profile''' value type |
+ | * Variable '''$year''' of '''Year''' value type | ||
− | <sql>SELECT name, | + | <sql>SELECT tmp_flight.activity_type_name AS name, |
sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS 'Avion', | sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS 'Avion', | ||
sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS 'Hélicoptère', | sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS 'Hélicoptère', | ||
Line 108: | Line 123: | ||
FROM ( | FROM ( | ||
SELECT | SELECT | ||
− | + | flightWithActivityType.activity_type_id, | |
− | + | flightWithActivityType.activity_type_name, | |
− | + | flightWithActivityType.duration, | |
resource_type.category | resource_type.category | ||
− | FROM flight | + | FROM ( |
− | + | SELECT flight.id, flight.duration, flight.aircraft_id, activity_type.id AS activity_type_id, activity_type.name AS activity_type_name | |
− | LEFT JOIN flight_pilot ON (flight_pilot.flight_id= | + | FROM flight |
− | LEFT JOIN person ON (person.id=flight_pilot.pilot_id) | + | LEFT JOIN activity_type ON flight.activity_type_id&activity_type.id |
− | LEFT JOIN resource ON (resource.id= | + | WHERE YEAR(flight.start_date)=$year |
+ | AND flight.airborne=0 | ||
+ | AND ( activity_type.id IN ($activityTypeId) OR '' IN ($activityTypeId) ) | ||
+ | AND flight.id NOT IN (SELECT flight_id FROM flight_pilot WHERE num=1) | ||
+ | ) AS flightWithActivityType | ||
+ | LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flightWithActivityType.id AND flight_pilot.num=0) | ||
+ | LEFT JOIN ( | ||
+ | SELECT person.* | ||
+ | FROM person | ||
+ | LEFT JOIN profile ON person.profile&profile.id | ||
+ | WHERE ( profile.id IN ($profileId) OR '' IN ($profileId) ) | ||
+ | AND person.activated=1 | ||
+ | GROUP BY person.id | ||
+ | ) AS personWithProfile ON (personWithProfile.id=flight_pilot.pilot_id) | ||
+ | LEFT JOIN resource ON (resource.id=flightWithActivityType.aircraft_id) | ||
LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) | LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) | ||
− | WHERE | + | WHERE personWithProfile.id IS NOT NULL |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
) AS tmp_flight | ) AS tmp_flight | ||
− | GROUP BY | + | GROUP BY tmp_flight.activity_type_id</sql> |
− | == | + | ==Users with a specific validity without expiration date== |
− | *Variable '''$validityId''' should be defined first and should be of ''' | + | *Variable '''$validityId''' should be defined first and should be of '''dbOjectMulti::ValidityType''' value type. |
− | <sql>SELECT person.first_name, person.last_name FROM validity | + | <sql>SELECT person.first_name, person.last_name, validity_type.name AS 'Validite' |
+ | FROM validity | ||
+ | LEFT JOIN validity_type ON validity.validity_type_id=validity_type.id | ||
LEFT JOIN person ON person.id=validity.person_id | LEFT JOIN person ON person.id=validity.person_id | ||
− | WHERE validity_type_id | + | WHERE ( validity_type_id IN ($validityTypeId) OR '-' IN ($validityTypeId) ) |
+ | AND expire_date IS NULL | ||
+ | AND person.activated=1</sql> | ||
==Number of movements on based airfield== | ==Number of movements on based airfield== | ||
Line 138: | Line 167: | ||
<sql>SELECT SUM(movement) AS 'Movement' | <sql>SELECT SUM(movement) AS 'Movement' | ||
− | FROM | + | FROM ( |
− | ( | + | |
SELECT COUNT(*) AS movement | SELECT COUNT(*) AS movement | ||
− | FROM flight | + | FROM flight, structure |
− | + | WHERE ( ( flight.departure_icao_id != structure.icao ) OR( flight.arrival_icao_id != structure.icao ) ) AND( flight.departure_icao_id != structure.icao ) AND YEAR(start_date) = $year | |
− | WHERE ( | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
UNION | UNION | ||
− | SELECT SUM(landing_number)*2 AS movement | + | SELECT SUM(landing_number) * 2 AS movement |
− | FROM flight | + | FROM flight, structure |
− | + | WHERE YEAR(flight.start_date) = $year AND flight.departure_icao_id = structure.icao AND flight.arrival_icao_id = structure.icao | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
) AS tmp_movement</sql> | ) AS tmp_movement</sql> | ||
==Number of movements on based airfield on specific profile== | ==Number of movements on based airfield on specific profile== | ||
− | * Variable '''$profileId''' should be defined first and should be of ''' | + | * Variable '''$profileId''' should be defined first and should be of '''dbOjectMulti::Profile''' value type. |
* Variable '''$year''' should be defined first and should be of '''Year''' value type. | * Variable '''$year''' should be defined first and should be of '''Year''' value type. | ||
<sql>SELECT SUM(movement) AS 'Movement' | <sql>SELECT SUM(movement) AS 'Movement' | ||
− | FROM | + | FROM ( |
− | ( | + | SELECT COUNT(*) AS movement |
− | + | FROM structure, flight | |
− | + | LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flight.id) | |
− | + | LEFT JOIN ( | |
− | + | SELECT person.* | |
− | + | FROM person | |
− | + | LEFT JOIN profile ON person.profile&profile.id | |
− | + | WHERE ( profile.id IN ($profileId) OR '' IN ($profileId) ) | |
− | + | AND person.activated=1 | |
− | + | GROUP BY person.id | |
− | + | ) AS personWithProfile ON (personWithProfile.id=flight_pilot.pilot_id AND flight_pilot.num=0) | |
− | + | WHERE ( | |
− | + | ( flight.departure_icao_id != structure.icao) | |
− | + | OR | |
− | + | ( flight.arrival_icao_id != structure.icao) | |
− | + | ) | |
− | + | AND ( flight.departure_icao_id != structure.icao) | |
− | + | AND YEAR(flight.start_date) = 2019 | |
− | + | AND personWithProfile.id IS NOT NULL | |
− | + | UNION | |
− | + | SELECT SUM(flight.landing_number)*2 AS movement | |
− | + | FROM structure, flight | |
− | + | LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flight.id) | |
− | + | LEFT JOIN ( | |
− | + | SELECT person.* | |
− | + | FROM person | |
− | + | LEFT JOIN profile ON person.profile&profile.id | |
− | + | WHERE ( profile.id IN ($profileId) OR '' IN ($profileId) ) | |
− | + | AND person.activated=1 | |
− | + | GROUP BY person.id | |
− | + | ) AS personWithProfile ON (personWithProfile.id=flight_pilot.pilot_id AND flight_pilot.num=0) | |
− | + | WHERE YEAR(flight.start_date) = $year | |
− | + | AND flight.departure_icao_id = structure.icao | |
− | + | AND flight.arrival_icao_id = structure.icao | |
− | + | AND personWithProfile.id IS NOT NULL | |
− | + | ) AS tmp_movement</sql> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
==Number of take-off and landings on based airfield== | ==Number of take-off and landings on based airfield== | ||
− | <SQL>SELECT SUM( landing_number )*2 AS nb_mouvement | + | <SQL>SELECT SUM(flight.landing_number) * 2 AS nb_mouvement |
− | FROM flight | + | FROM flight, structure |
− | WHERE ( | + | WHERE ( flight.departure_icao_id = structure.icao ) AND ( flight.arrival_icao_id = structure.icao ) AND YEAR(start_date) = $year </SQL> |
− | + | ||
− | + | ||
==Number of take-off and landings on based airfield on specific profile== | ==Number of take-off and landings on based airfield on specific profile== | ||
− | * Variable '''$profileId''' should be defined first and should be of ''' | + | * Variable '''$profileId''' should be defined first and should be of '''dbOjectMulti::Profile''' value type. |
* Variable '''$year''' should be defined first and should be of '''Year''' value type. | * Variable '''$year''' should be defined first and should be of '''Year''' value type. | ||
− | <sql>SELECT SUM(landing_number)*2 AS 'Movement' | + | <sql>SELECT SUM(flight.landing_number) * 2 AS 'Movement' |
− | FROM flight | + | FROM structure, flight |
+ | LEFT JOIN flight_pilot ON ( flight_pilot.flight_id = flight.id ) | ||
LEFT JOIN ( | LEFT JOIN ( | ||
− | SELECT | + | SELECT person.* |
− | FROM | + | FROM person |
− | LEFT JOIN | + | LEFT JOIN profile ON person.profile & profile.id |
− | WHERE | + | WHERE (profile.id IN($profileId) OR '-' IN($profileId)) AND person.activated = 1 |
− | + | GROUP BY person.id | |
− | ) | + | ) AS personWithProfile ON ( personWithProfile.id = flight_pilot.pilot_id AND flight_pilot.num = 0 ) |
− | + | WHERE personWithProfile.id IS NOT NULL AND YEAR(flight.start_date) = $year AND flight.departure_icao_id = structure.icao AND flight.arrival_icao_id = structure.icao</sql> | |
− | + | ||
− | WHERE | + | |
− | + | ||
− | + | ||
− | + | ||
==List of movements on based airfield== | ==List of movements on based airfield== | ||
− | <sql>SELECT | + | <sql>SELECT location.icao_name AS ICAO, location.name AS NAME, COUNT(location.icao_name) AS nb_flight |
− | FROM flight | + | FROM structure, flight |
− | LEFT JOIN | + | LEFT JOIN location ON flight.departure_icao_id = location.icao_name |
− | WHERE ( flight. | + | WHERE ( flight.departure_icao_id = structure.icao ) OR( flight.arrival_icao_id = structure.icao ) AND departure_icao_id != arrival_icao_id AND YEAR(start_date) = $year |
− | + | GROUP BY icao_name | |
− | + | ORDER BY nb_flight DESC </sql> | |
− | GROUP BY | + | |
− | == | + | ==User flying without validity== |
− | <sql>SELECT CONCAT( | + | <sql>SELECT |
− | FROM flight_type_mandatory_validity_type | + | CONCAT(person.last_name, ' ', person.first_name) AS _tr(PILOT), |
− | LEFT JOIN | + | validity_type.name AS _tr(VALIDITY) |
− | LEFT JOIN flight | + | FROM flight_type_mandatory_validity_type |
− | LEFT JOIN resource | + | LEFT JOIN activity_type ON activity_type.id = flight_type_mandatory_validity_type.activity_type_id |
− | LEFT JOIN resource_type | + | LEFT JOIN flight ON flight.activity_type_id & activity_type.id |
− | LEFT JOIN aircraft_type_validity_type | + | LEFT JOIN resource ON resource.id = flight.aircraft_id |
− | LEFT JOIN flight_pilot | + | LEFT JOIN resource_type ON resource.resource_type_id = resource_type.id |
− | LEFT JOIN person | + | LEFT JOIN aircraft_type_validity_type ON resource_type.id = aircraft_type_validity_type.aircraft_type_id |
− | LEFT JOIN validity_type | + | LEFT JOIN flight_pilot ON flight.id = flight_pilot.flight_id |
− | WHERE | + | LEFT JOIN person ON person.id = flight_pilot.pilot_id |
− | AND | + | LEFT JOIN validity_type ON (validity_type.id = flight_type_mandatory_validity_type.validity_type_id OR validity_type.id = aircraft_type_validity_type.validity_type_id) |
− | AND | + | LEFT JOIN validity ON validity_type.id = validity.validity_type_id AND person.id = validity.person_id AND validity.is_current_validity = 1 |
− | GROUP BY | + | WHERE flight.airborne = 0 |
− | ORDER BY | + | AND validity_type.id IS NOT NULL |
+ | AND validity_type.experience_formula IS NULL | ||
+ | AND validity.validity_type_id IS NULL | ||
+ | AND person.activated = 1 | ||
+ | AND validity_type.activated = 1 | ||
+ | GROUP BY person.id, validity_type.id | ||
+ | ORDER BY `_tr(PILOT)`, validity_type.name</sql> | ||
==List of pilots who have flown less than X hours during last Y days== | ==List of pilots who have flown less than X hours during last Y days== | ||
Line 302: | Line 304: | ||
ORDER BY pilot</sql> | ORDER BY pilot</sql> | ||
− | ==Pilots without flight in the last | + | ==Pilots without flight in the last X months== |
+ | |||
+ | * Variable '''$numberMonth''' should be defined first and should be of '''integer''' value type. | ||
<sql>SELECT | <sql>SELECT | ||
Line 320: | Line 324: | ||
LEFT JOIN flight_pilot AS fp ON fp.flight_id=f.id | LEFT JOIN flight_pilot AS fp ON fp.flight_id=f.id | ||
LEFT JOIN person AS person2 ON person2.id=fp.pilot_id | LEFT JOIN person AS person2 ON person2.id=fp.pilot_id | ||
− | WHERE f.airborne = 0 AND f.start_date BETWEEN NOW() - INTERVAL | + | WHERE f.airborne = 0 AND f.start_date BETWEEN NOW() - INTERVAL IF($numberMonth='', 1, $numberMonth*30) DAY AND NOW() |
GROUP BY person2.id HAVING SUM(f.duration)/600 > 0 | GROUP BY person2.id HAVING SUM(f.duration)/600 > 0 | ||
) | ) | ||
ORDER BY person.last_name, person.first_name</sql> | ORDER BY person.last_name, person.first_name</sql> | ||
+ | |||
+ | ==Total user per age profile validity: Number of men, women over and under X years for profile P, validity V up to date for year A== | ||
+ | * Variable '''$age''' should be of '''integer''' value type. | ||
+ | * Variable '''$profileId''' should be of '''dbOjectMulti::Profile''' value type. | ||
+ | * Variable '''$validityTypeId''' should be of '''dbObjectMulti::validityType''' value type. | ||
+ | * Variable '''$year''' should be of '''Year''' value type. | ||
+ | |||
+ | <sql>SELECT | ||
+ | IF( personWithProfile.sex=0, _tr(SEX_MALE_INITIAL), IF( personWithProfile.sex=1, _tr(SEX_FEMALE_INITIAL), _tr(UNDEFINED)) ) AS _tr(SEX), | ||
+ | IF( ( $year - YEAR(birthdate) >= $age ) , _tr(YES), _tr(NO)) AS _tr(ADULT), | ||
+ | COUNT(DISTINCT personWithProfile.id) AS _tr(NUMBER) | ||
+ | FROM ( | ||
+ | SELECT person.* | ||
+ | FROM person | ||
+ | LEFT JOIN profile ON person.profile&profile.id | ||
+ | WHERE ( profile.id IN ($profileId) OR '-' IN ($profileId) ) | ||
+ | AND person.activated=1 | ||
+ | ) AS personWithProfile | ||
+ | LEFT JOIN validity ON personWithProfile.id = validity.person_id AND validity.is_current_validity = 1 | ||
+ | LEFT JOIN validity_type ON (validity_type.id=validity.validity_type_id) | ||
+ | WHERE ((validity_type.id IN ($validityTypeId) AND validity.expire_date >= '$year-12-31') OR '-' IN ($validityTypeId)) | ||
+ | AND validity_type.activated = 1 | ||
+ | GROUP BY `_tr(SEX)`, `_tr(ADULT)`</sql> | ||
==Number of landings per pilot, per resource== | ==Number of landings per pilot, per resource== | ||
Line 402: | Line 429: | ||
==Flight hours without up to date validities== | ==Flight hours without up to date validities== | ||
− | <sql>SELECT DATE_FORMAT(start_date, '%d %m %Y' ) AS | + | |
− | first_name AS | + | *Variable '''$year''' |
− | IF ((SELECT COUNT(*) | + | |
− | + | <sql>SELECT | |
− | + | DATE_FORMAT(start_date, '%d %m %Y' ) AS _tr(DATE), | |
− | resource.name AS | + | CONCAT(person.last_name, ' ', person.first_name) AS _tr(FULL_NAME), |
− | + | IF ( (SELECT COUNT(*) FROM flight_pilot AS tmp_flight_pilot WHERE flight_pilot.flight_id=tmp_flight_pilot.flight_id AND tmp_flight_pilot.num=1)=0, 'Solo', 'DC' ) AS DC, | |
− | + | resource.name AS _tr(RESOURCE), | |
− | + | sexa2HoursMinute(duration) AS _tr(DURATION), | |
− | + | activity_type.name AS _tr(ACTIVITY_TYPE), | |
− | + | validity_type.name AS _tr(VALIDITY) | |
FROM flight | FROM flight | ||
− | LEFT JOIN flight_type_mandatory_validity_type | + | LEFT JOIN flight_type_mandatory_validity_type ON flight_type_mandatory_validity_type.activity_type_id & flight.activity_type_id |
− | LEFT JOIN flight_pilot | + | LEFT JOIN flight_pilot ON flight.id = flight_pilot.flight_id |
− | LEFT JOIN person | + | LEFT JOIN person ON flight_pilot.pilot_id = person.id |
− | LEFT JOIN validity_type | + | LEFT JOIN validity_type ON flight_type_mandatory_validity_type.validity_type_id = validity_type.id |
− | LEFT JOIN validity | + | LEFT JOIN validity ON flight_type_mandatory_validity_type.validity_type_id = validity.validity_type_id AND validity.is_current_validity = 1 |
− | LEFT JOIN resource ON | + | LEFT JOIN resource ON flight.aircraft_id = resource.id |
− | LEFT JOIN | + | LEFT JOIN activity_type ON flight_type_mandatory_validity_type.activity_type_id = activity_type.id |
− | WHERE YEAR(start_date) = $year AND | + | WHERE YEAR(start_date) = $year |
− | ORDER BY | + | AND flight_pilot.num = 0 |
+ | AND validity_type.time_limitation=1 | ||
+ | AND validity.person_id = flight_pilot.pilot_id | ||
+ | AND flight.start_date > validity.expire_date | ||
+ | AND person.activated = 1 | ||
+ | AND validity_type.activated = 1 | ||
+ | ORDER BY flight.start_date, `_tr(FULL_NAME)`, validity_type.name</sql> | ||
==Number of men, women over and under 21 years for profile X, validity Y up to date for year Z== | ==Number of men, women over and under 21 years for profile X, validity Y up to date for year Z== | ||
− | * Variable '''$profileId''' should be of ''' | + | * Variable '''$age''' should be of '''integer''' value type. |
− | * Variable '''$validityTypeId''' should be of ''' | + | * Variable '''$profileId''' should be of '''dbOjectMulti::Profile''' value type. |
+ | * Variable '''$validityTypeId''' should be of '''dbObjectMulti::validityType''' value type. | ||
* Variable '''$year''' should be of '''Year''' value type. | * Variable '''$year''' should be of '''Year''' value type. | ||
<sql>SELECT | <sql>SELECT | ||
IF( person.sex=0, 'Male', IF( person.sex=1, 'Female', 'Undefined') ) AS 'Sex', | IF( person.sex=0, 'Male', IF( person.sex=1, 'Female', 'Undefined') ) AS 'Sex', | ||
− | IF( ( $year - YEAR(birthdate) >= | + | IF( ( $year - YEAR(birthdate) >= '$age' ) , 'Yes', 'No') AS 'Adult', |
COUNT(DISTINCT person.id) AS NUMBER | COUNT(DISTINCT person.id) AS NUMBER | ||
FROM person | FROM person | ||
Line 438: | Line 472: | ||
WHERE activated=1 | WHERE activated=1 | ||
AND (profile & '$profileId' OR '-'='$profileId') | AND (profile & '$profileId' OR '-'='$profileId') | ||
− | AND (validity_type.id='$validityTypeId' | + | AND ( |
− | + | (validity_type.id='$validityTypeId' AND validity.expire_date >= '$year-12-31') | |
+ | OR | ||
+ | '-'='$validityTypeId' | ||
+ | ) | ||
GROUP BY Sex, Adult</sql> | GROUP BY Sex, Adult</sql> | ||
− | == | + | ==Total hours by activities and resource categories for an instructor for one year== |
+ | * Variable '''$personId''' should be defined first and should be of '''dbOjectMulti::Person''' value type. | ||
+ | * Variable '''$year''' should be defined first and should be of '''Year''' value type. | ||
+ | |||
+ | <sql>SELECT tmp_flight.activity_type_name AS name, | ||
+ | sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS _tr(AIRCRAFT_CATEGORY), | ||
+ | sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS _tr(HELICOPTER_CATEGORY), | ||
+ | sexa2HoursMinute(SUM(IF(category=19, duration, 0))) AS _tr(GLIDER_CATEGORY), | ||
+ | sexa2HoursMinute(SUM(IF(category=17, duration, 0))) AS _tr(ULTRA_LIGHT_CATEGORY), | ||
+ | sexa2HoursMinute(SUM(IF(category=9, duration, 0))) AS _tr(CLASSROOM_CATEGORY) | ||
+ | FROM ( | ||
+ | SELECT | ||
+ | flightWithActivityType.activity_type_id, | ||
+ | flightWithActivityType.activity_type_name, | ||
+ | flightWithActivityType.duration, | ||
+ | resource_type.category | ||
+ | FROM ( | ||
+ | SELECT flight.id, flight.duration, flight.aircraft_id, activity_type.id AS activity_type_id, activity_type.name AS activity_type_name | ||
+ | FROM flight | ||
+ | LEFT JOIN activity_type ON flight.activity_type_id&activity_type.id | ||
+ | LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flight.id AND flight_pilot.num=1) | ||
+ | WHERE YEAR(flight.start_date)=$year | ||
+ | AND flight.airborne=0 AND flight_pilot.pilot_id=$personId | ||
+ | ) AS flightWithActivityType | ||
+ | LEFT JOIN resource ON (resource.id=flightWithActivityType.aircraft_id) | ||
+ | LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) | ||
+ | ) AS tmp_flight | ||
+ | GROUP BY tmp_flight.activity_type_id</sql> | ||
+ | |||
+ | ==Validity year young specific profile: Total of youngs/adults with specific profile== | ||
− | * Variable '''$profileId''' should be defined first and should be of ''' | + | * Variable '''$profileId''' should be defined first and should be of '''dbOjectMulti::Profile''' value type. |
* Variable '''$year''' should be defined first and should be of '''Year''' value type. | * Variable '''$year''' should be defined first and should be of '''Year''' value type. | ||
* Note: "21" is the limit of age to categorize a young and adult person. Change it according to your need. | * Note: "21" is the limit of age to categorize a young and adult person. Change it according to your need. | ||
− | <sql>SELECT | + | <sql>SELECT |
− | validity_type.name AS ' | + | validity_type.name AS '_tr(VALIDITY)', |
− | SUM( IF( ( $year - YEAR( | + | SUM( IF( ( $year - YEAR(personWithProfile.birthdate) < 21 ), 1, 0 ) ) AS '_tr(YOUNG)', |
− | SUM( IF( ( $year - YEAR( | + | SUM( IF( ( $year - YEAR(personWithProfile.birthdate) >= 21 ), 1, 0 ) ) AS '_tr(ADULT)' |
FROM validity_type | FROM validity_type | ||
− | LEFT JOIN validity ON | + | LEFT JOIN validity ON validity.validity_type_id = validity_type.id AND validity.is_current_validity = 1 |
− | LEFT JOIN person ON | + | LEFT JOIN ( |
+ | SELECT person.* | ||
+ | FROM person | ||
+ | LEFT JOIN profile ON person.profile&profile.id | ||
+ | WHERE ( profile.id IN ($profileId) OR '-' IN ($profileId) ) | ||
+ | AND person.activated=1 | ||
+ | GROUP BY person.id | ||
+ | ) AS personWithProfile ON (validity.person_id=personWithProfile.id) | ||
WHERE YEAR(validity.grant_date)=$year | WHERE YEAR(validity.grant_date)=$year | ||
− | AND | + | AND personWithProfile.id IS NOT NULL |
− | AND | + | AND validity_type.activated = 1 |
GROUP BY validity_type.id | GROUP BY validity_type.id | ||
ORDER BY validity_type.name</sql> | ORDER BY validity_type.name</sql> | ||
==Validities obtained in the year== | ==Validities obtained in the year== | ||
− | *Variable '''$validityId''' should be defined first and should be of ''' | + | *Variable '''$validityId''' should be defined first and should be of '''dbOjectMulti::ValidityType''' value type. |
*'''21''' value is the age limit to be young. Should be changed according local rules | *'''21''' value is the age limit to be young. Should be changed according local rules | ||
+ | |||
<sql>SELECT | <sql>SELECT | ||
last_name AS Last_name, | last_name AS Last_name, | ||
first_name AS First_name, | first_name AS First_name, | ||
IF( ( $year - YEAR( birthdate ) >= 21) , 'No', 'Yes') AS Young, | IF( ( $year - YEAR( birthdate ) >= 21) , 'No', 'Yes') AS Young, | ||
− | IF ( | + | IF( person.sex=0, 'Male', IF( person.sex=1, 'Female', 'Undefined') ) AS 'Sex', DATE_FORMAT( grant_date, '%d/%m/%Y' ) AS Date, validity_type.name AS 'Validity' |
− | + | FROM person | |
− | + | LEFT JOIN validity ON person_id=person.id | |
− | + | LEFT JOIN validity_type ON validity_type.id=validity.validity_type_id | |
− | + | WHERE YEAR(grant_date)=$year | |
+ | AND ( validity_type.id IN ($validityTypeId) OR '-' IN ($validityTypeId) ) | ||
+ | AND person.activated=1 | ||
+ | ORDER BY last_name, first_name</sql> | ||
− | = | + | ==Visited airfields== |
− | = | + | <sql>SELECT location.icao_name AS ICAO, location.name AS NAME, COUNT(location.icao_name) AS Visit |
+ | FROM structure, flight | ||
+ | LEFT JOIN location ON ( flight.departure_icao_id = location.icao_name ) | ||
+ | WHERE ( ( flight.departure_icao_id != structure.icao ) OR ( flight.arrival_icao_id != structure.icao ) ) AND YEAR(start_date) = $year | ||
+ | GROUP BY location.icao_name | ||
+ | ORDER BY Visit | ||
+ | DESC</sql> | ||
− | ==Cumulated maintenance hours | + | ==Visited outsider airfield== |
+ | |||
+ | <sql>SELECT location.icao_name AS ICAO, location.name AS Name, COUNT(location.icao_name) AS nb_visite | ||
+ | FROM structure, flight | ||
+ | LEFT JOIN location ON ( flight.departure_icao_id = location.icao_name ) | ||
+ | WHERE ( ( flight.departure_icao_id !=structure.icao ) OR( flight.arrival_icao_id !=structure.icao ) ) AND YEAR(start_date) = $year | ||
+ | GROUP BY location.icao_name | ||
+ | ORDER BY nb_visite DESC</sql> | ||
+ | |||
+ | ==Young from this year== | ||
+ | |||
+ | <sql>SELECT | ||
+ | CONCAT( '[LINK=index.php[QUESTION_MARK]menuAction=admin_add_modify_user&menuParameter=',person.id,'&menuParameterBis=last_name&menuParameter3=', LEFT(person.last_name, 1),']', person.id, '[/LINK]' ) AS _tr(ID), | ||
+ | person.first_name AS _tr(FIRST_NAME), | ||
+ | person.last_name AS _tr(LAST_NAME), | ||
+ | DATE_FORMAT(birthdate ,'%m-%d-%Y') AS _tr(USER_BIRTHDATE), | ||
+ | IF ( sex = 0, _tr(SEX_MALE), _tr(SEX_FEMALE) ) AS _tr(USER_SEX) | ||
+ | FROM person | ||
+ | WHERE ($year-YEAR(birthdate))<=$age AND activated=1</sql> | ||
+ | |||
+ | =[[Accounting-exports-4|Accounting]]= | ||
+ | |||
+ | =Bookings= | ||
+ | ==Booking== | ||
+ | * Variable '''$endDate''' of '''Date and time''' value type. | ||
+ | * Variable '''$startDate''' of '''Date and time''' value type. | ||
+ | * Variable '''$personId''' of '''dbObject::Person''' value type. | ||
+ | * Variable '''$resourceId''' of '''dbObject::Resource''' value type. | ||
+ | |||
+ | <sql>[OF_DYNAMIC_SQL] | ||
+ | SELECT CONCAT( | ||
+ | 'SELECT booking.id AS _tr(ID), DATE_FORMAT(booking.start_date, \'%Y-%m-%d %H:%i\') AS _tr(START_DATE), DATE_FORMAT(booking.end_date, \'%Y-%m-%d %H:%i\') AS _tr(END_DATE), | ||
+ | ( | ||
+ | SELECT GROUP_CONCAT( activity_type.name SEPARATOR \', \') | ||
+ | FROM booking_activity_type | ||
+ | LEFT JOIN activity_type ON (booking_activity_type.activity_type_id = activity_type.id) | ||
+ | WHERE booking_activity_type.booking_id=booking.id | ||
+ | ) AS _tr(ACTIVITY_TYPE), | ||
+ | resource.name AS _tr(RESOURCE), | ||
+ | left_booking_person.full_name AS _tr(LEFT_PLACE), right_booking_person.full_name AS _tr(RIGHT_PLACE), ', | ||
+ | IFNULL(GROUP_CONCAT( | ||
+ | CONCAT( | ||
+ | ' (SELECT business_field_content.content FROM business_field_content WHERE booking.id=business_field_content.category_id AND business_field_content.business_field_id=', | ||
+ | business_field.id, | ||
+ | ' LIMIT 1) AS \'', | ||
+ | REPLACE(business_field.label, '\'', '\\\''), | ||
+ | '\'' | ||
+ | ) | ||
+ | ), '\'_\''), | ||
+ | 'FROM booking | ||
+ | LEFT JOIN booking_resource ON (booking.id=booking_resource.booking_id) | ||
+ | LEFT JOIN resource ON (resource.id=booking_resource.resource_id) | ||
+ | LEFT JOIN ( | ||
+ | SELECT booking_person.booking_id, booking_person.person_id, CONCAT(person.last_name, \' \', person.first_name) AS full_name | ||
+ | FROM booking_person | ||
+ | LEFT JOIN person ON (person.id=booking_person.person_id) | ||
+ | WHERE booking_person.place_num=0 | ||
+ | AND person.activated=1 | ||
+ | ) AS left_booking_person ON (booking.id=left_booking_person.booking_id) | ||
+ | LEFT JOIN ( | ||
+ | SELECT booking_person.booking_id, booking_person.person_id, CONCAT(person.last_name, \' \', person.first_name) AS full_name | ||
+ | FROM booking_person | ||
+ | LEFT JOIN person ON (person.id=booking_person.person_id) | ||
+ | WHERE booking_person.place_num=1 | ||
+ | AND person.activated=1 | ||
+ | ) AS right_booking_person ON (booking.id=right_booking_person.booking_id) | ||
+ | WHERE booking.start_date >= $startDate AND booking.end_date < $endDate | ||
+ | AND (booking_resource.resource_id=$resourceId OR \'\'=$resourceId) | ||
+ | AND ( | ||
+ | left_booking_person.person_id=$personId OR right_booking_person.person_id=$personId OR \'\'=$personId | ||
+ | ) | ||
+ | ORDER BY booking.start_date, booking.end_date' | ||
+ | ) | ||
+ | FROM business_field | ||
+ | WHERE business_field.category='BOOKING' AND business_field.variable IN ('bookingEstimatedFlightTime', 'bookingComment')</sql> | ||
+ | |||
+ | ==Cumulated maintenance hours on a period== | ||
Following extrafields are needed : | Following extrafields are needed : | ||
Line 484: | Line 643: | ||
*endDate (Type : Date or DateTime) | *endDate (Type : Date or DateTime) | ||
− | <sql>SELECT IF(LEAST( | + | <sql>SELECT IF(LEAST($startDate + INTERVAL 366 DAY, $endDate) <> $endDate, ' Attention la date de fin retenue correspond à la date de début + 366 jours', '') AS 'Ressource', '' AS 'Duree de maintenance en heures', '' AS 'Duree en jours' |
UNION ALL | UNION ALL | ||
SELECT resource.name AS 'Ressource', SUM(TIMESTAMPDIFF(HOUR,booking.start_date, booking.end_date)), SUM(TIMESTAMPDIFF(DAY,booking.start_date, booking.end_date)) | SELECT resource.name AS 'Ressource', SUM(TIMESTAMPDIFF(HOUR,booking.start_date, booking.end_date)), SUM(TIMESTAMPDIFF(DAY,booking.start_date, booking.end_date)) | ||
FROM booking | FROM booking | ||
+ | LEFT JOIN booking_activity_type ON booking.id=booking_activity_type.booking_id | ||
+ | LEFT JOIN activity_type ON activity_type.id=booking_activity_type.activity_type_id | ||
+ | LEFT JOIN booking_resource ON booking.id=booking_resource.booking_id | ||
+ | LEFT JOIN resource ON resource.id = booking_resource.resource_id | ||
LEFT JOIN log ON log.field_value=booking.id | LEFT JOIN log ON log.field_value=booking.id | ||
LEFT JOIN journal ON journal.id=log.journal_id | LEFT JOIN journal ON journal.id=log.journal_id | ||
− | + | WHERE activity_type.name='Maintenance' | |
− | WHERE | + | |
AND (log.action='INSERT') | AND (log.action='INSERT') | ||
AND (log.table_name='booking') | AND (log.table_name='booking') | ||
AND (log.field_name='id') | AND (log.field_name='id') | ||
− | AND (booking.start_date >= | + | AND (booking.start_date >= $startDate) |
− | AND (booking.start_date <= LEAST( | + | AND (booking.start_date <= LEAST($startDate + INTERVAL 366 DAY, $endDate)) |
GROUP BY resource.id | GROUP BY resource.id | ||
ORDER BY 1</sql> | ORDER BY 1</sql> | ||
Line 506: | Line 668: | ||
*endDate (Type : Date or DateTime) | *endDate (Type : Date or DateTime) | ||
− | <sql>SELECT IF(LEAST( | + | <sql>SELECT IF(LEAST($startDate + INTERVAL 366 DAY, $endDate) <> $endDate, ' Attention la date de fin retenue correspond à la date de début + 366 jours', '') AS 'Ressource', '' AS 'Date debut maintenance', '' AS 'Date fin maintenance', '' AS 'Duree de maintenance en heures', '' AS 'Duree en jours' |
UNION ALL | UNION ALL | ||
SELECT resource.name, booking.start_date AS 'Date debut maintenance', booking.end_date, TIMESTAMPDIFF(HOUR,booking.start_date, booking.end_date), TIMESTAMPDIFF(DAY,booking.start_date, booking.end_date) | SELECT resource.name, booking.start_date AS 'Date debut maintenance', booking.end_date, TIMESTAMPDIFF(HOUR,booking.start_date, booking.end_date), TIMESTAMPDIFF(DAY,booking.start_date, booking.end_date) | ||
FROM booking | FROM booking | ||
+ | LEFT JOIN booking_activity_type ON booking.id=booking_activity_type.booking_id | ||
+ | LEFT JOIN activity_type ON activity_type.id=booking_activity_type.activity_type_id | ||
+ | LEFT JOIN booking_resource ON booking.id=booking_resource.booking_id | ||
+ | LEFT JOIN resource ON resource.id = booking_resource.resource_id | ||
LEFT JOIN log ON log.field_value=booking.id | LEFT JOIN log ON log.field_value=booking.id | ||
LEFT JOIN journal ON journal.id=log.journal_id | LEFT JOIN journal ON journal.id=log.journal_id | ||
− | + | WHERE activity_type.name='Maintenance' | |
− | WHERE | + | |
AND (log.action='INSERT') | AND (log.action='INSERT') | ||
− | AND (log. | + | AND (log.TABLE_NAME='booking') |
AND (log.field_name='id') | AND (log.field_name='id') | ||
− | AND (booking.start_date >= | + | AND (booking.start_date >= $startDate) |
− | AND (booking.start_date <= LEAST( | + | AND (booking.start_date <= LEAST($startDate + INTERVAL 366 DAY, $endDate)) |
ORDER BY 1, 2</sql> | ORDER BY 1, 2</sql> | ||
− | == | + | ==Booking for maintenance ordered by resource and date with name of the responsible== |
<sql>SELECT resource.name AS 'Resource name', booking.start_date AS 'Start date', TIMESTAMPDIFF(HOUR,booking.start_date, booking.end_date) AS 'booking duration', person.first_name AS 'First name', person.last_name AS 'Last name' | <sql>SELECT resource.name AS 'Resource name', booking.start_date AS 'Start date', TIMESTAMPDIFF(HOUR,booking.start_date, booking.end_date) AS 'booking duration', person.first_name AS 'First name', person.last_name AS 'Last name' | ||
FROM booking | FROM booking | ||
+ | LEFT JOIN booking_activity_type ON booking.id=booking_activity_type.booking_id | ||
+ | LEFT JOIN activity_type ON activity_type.id=booking_activity_type.activity_type_id | ||
+ | LEFT JOIN booking_resource ON booking.id=booking_resource.booking_id | ||
+ | LEFT JOIN resource ON resource.id = booking_resource.resource_id | ||
LEFT JOIN log ON log.field_value=booking.id | LEFT JOIN log ON log.field_value=booking.id | ||
LEFT JOIN journal ON journal.id=log.journal_id | LEFT JOIN journal ON journal.id=log.journal_id | ||
LEFT JOIN person ON person.name=journal.login | LEFT JOIN person ON person.name=journal.login | ||
− | + | WHERE activity_type.name='Maintenance' | |
− | WHERE | + | AND (log.action='INSERT') |
− | AND YEAR(booking.start_date) = $year | + | AND (log.TABLE_NAME='booking') |
+ | AND (log.field_name='id') | ||
+ | AND YEAR(booking.start_date) = $year | ||
+ | AND person.activated=1 | ||
ORDER BY resource.name, booking.start_date</sql> | ORDER BY resource.name, booking.start_date</sql> | ||
=Flight time management= | =Flight time management= | ||
+ | |||
+ | ==Flight hours total and last recorded counters to the date X== | ||
+ | |||
+ | * Variable '''$endDate''' should be of '''Datetime''' value type. | ||
+ | |||
+ | <sql>SELECT resource.name, sexa2HoursMinute( SUM(duration) + aircraft.ref_hours ) AS 'Total heures', sexa2HoursMinute( MAX(counter_arrival) ) AS 'Dernier compteur' | ||
+ | FROM flight | ||
+ | LEFT JOIN resource ON (resource.id=flight.aircraft_id) | ||
+ | LEFT JOIN aircraft ON (aircraft.id=resource.id) | ||
+ | WHERE flight.start_date <= $endDate | ||
+ | AND resource.activated=1 | ||
+ | GROUP BY resource.id | ||
+ | ORDER BY resource.name</sql> | ||
+ | |||
==Flight hours per month== | ==Flight hours per month== | ||
<sql>SELECT MONTH( start_date) AS months, CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) AS Total | <sql>SELECT MONTH( start_date) AS months, CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) AS Total | ||
Line 576: | Line 762: | ||
GROUP BY year</sql> | GROUP BY year</sql> | ||
− | ==Flights hours total per aircraft per year and per month (for | + | ==Flights hours total per aircraft per year and per month (for an activity type)== |
− | * Variable '''$ | + | * Variable '''$activityTypeId''' should be defined first and should be of '''dbOject::ActivityType''' value type. |
* Variable '''$year''' should be defined first and should be of '''Year''' value type. | * Variable '''$year''' should be defined first and should be of '''Year''' value type. | ||
Line 599: | Line 785: | ||
LEFT JOIN resource ON resource.id = aircraft.id | LEFT JOIN resource ON resource.id = aircraft.id | ||
WHERE YEAR(start_date)= $year AND airborne = 0 | WHERE YEAR(start_date)= $year AND airborne = 0 | ||
− | AND (flight. | + | AND (flight.activity_type_id & $activityTypeId OR ''=$activityTypeId) |
GROUP BY resource.id | GROUP BY resource.id | ||
UNION | UNION | ||
Line 620: | Line 806: | ||
LEFT JOIN resource ON resource.id = aircraft.id | LEFT JOIN resource ON resource.id = aircraft.id | ||
WHERE YEAR(start_date)= $year AND airborne = 0 | WHERE YEAR(start_date)= $year AND airborne = 0 | ||
− | AND (flight. | + | AND (flight.activity_type_id & $activityTypeId OR ''=$activityTypeId) |
UNION | UNION | ||
SELECT "Cumulative","per month", | SELECT "Cumulative","per month", | ||
Line 640: | Line 826: | ||
LEFT JOIN resource ON resource.id = aircraft.id | LEFT JOIN resource ON resource.id = aircraft.id | ||
WHERE YEAR(start_date)= $year AND airborne = 0 | WHERE YEAR(start_date)= $year AND airborne = 0 | ||
− | AND (flight. | + | AND (flight.activity_type_id & $activityTypeId OR ''=$activityTypeId)</sql> |
==Flight hours total per pilot== | ==Flight hours total per pilot== | ||
Line 678: | Line 864: | ||
GROUP BY pilot_id, Solo_DC | GROUP BY pilot_id, Solo_DC | ||
) AS DC ON person.id=DC.pilot_id AND DC.Solo_DC='DC' | ) AS DC ON person.id=DC.pilot_id AND DC.Solo_DC='DC' | ||
− | WHERE Solo.pilot_id IS NOT NULL OR DC.pilot_id IS NOT NULL | + | WHERE (Solo.pilot_id IS NOT NULL OR DC.pilot_id IS NOT NULL) |
+ | AND person.activated=1 | ||
GROUP BY person.id | GROUP BY person.id | ||
ORDER BY Nom</sql> | ORDER BY Nom</sql> | ||
Line 701: | Line 888: | ||
GROUP BY Profil, Nom, Solo_DC</sql> | GROUP BY Profil, Nom, Solo_DC</sql> | ||
− | ==Total Flight hours per pilot with total | + | ==Total Flight hours per pilot with total== |
Following extrafields are needed | Following extrafields are needed | ||
*year (Type : Year) | *year (Type : Year) | ||
*month (Type : Integer) '''OR''' startDate and endDate (Type : Date) | *month (Type : Integer) '''OR''' startDate and endDate (Type : Date) | ||
*$occupiedSeat (Type : Integer) | *$occupiedSeat (Type : Integer) | ||
− | *profileId (Type : | + | *profileId (Type : dbObjectMulti::Profile) |
This report is useful for a group of pilots from a common customer (like DGAC in France) | This report is useful for a group of pilots from a common customer (like DGAC in France) | ||
− | <sql>SELECT CONCAT(person.last_name,' ',person.first_name) AS | + | <sql>SELECT CONCAT(person.last_name,' ',person.first_name) AS _tr(FULL_NAME), |
− | CONCAT(FLOOR(SUM( | + | CONCAT(FLOOR(SUM( flight.duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( flight.duration )/600 - FLOOR(SUM( flight.duration )/600))*3600),'%i')) AS _tr(TOTAL_FLIGHT_TIME), |
− | + | SUM(account_entry.debit) - SUM(account_entry.credit) AS _tr(TOTAL_AMOUNT_ACTIVITIES) | |
− | + | FROM flight | |
− | + | RIGHT JOIN flight_pilot ON flight_pilot.flight_id=flight.id | |
− | + | AND (IF((($occupiedSeat=0) OR ($occupiedSeat='')), 0, -1) = flight_pilot.num | |
− | + | OR IF((($occupiedSeat=1) OR ($occupiedSeat='')), 1, -1) = flight_pilot.num) | |
− | + | RIGHT JOIN person ON person.id=flight_pilot.pilot_id | |
+ | RIGHT JOIN profile ON profile.id&person.profile | ||
+ | AND ( profile.id IN ($profileId) OR '-' IN ($profileId) ) | ||
LEFT JOIN flight_account_entry ON flight_account_entry.flight_id = flight.id | LEFT JOIN flight_account_entry ON flight_account_entry.flight_id = flight.id | ||
LEFT JOIN account_entry ON account_entry.flow_id = flight_account_entry.account_entry_id | LEFT JOIN account_entry ON account_entry.flow_id = flight_account_entry.account_entry_id | ||
LEFT JOIN account ON account.id=account_entry.account_id | LEFT JOIN account ON account.id=account_entry.account_id | ||
− | WHERE | + | WHERE $startDate <= flight.start_date AND flight.start_date <= $endDate AND (account.category = 11 OR account.category = 2) |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
GROUP BY person.id</sql> | GROUP BY person.id</sql> | ||
− | == | + | ==Flight hours per instructor, month (for a flight type)== |
− | Following extrafields are needed: | + | Following extrafields are needed : |
*year (Type : Year) | *year (Type : Year) | ||
+ | *activityTypeId (Type : dbObject::FlightType) | ||
<sql>SELECT | <sql>SELECT | ||
− | + | CONCAT(UPPER(person.last_name), ' ', person.first_name) AS _tr(LAST_NAME), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 1 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_JANUARY), | |
− | CONCAT( | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 2 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_FEBRUARY), |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 3 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_MARCH), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 4 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_APRIL), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 5 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_MAY), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 6 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_JUN), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 7 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_JULY), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 8 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_AUGUST), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 9 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_SEPTEMBER), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 10 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_OCTOBER), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 11 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_NOVEMBER), | |
− | + | (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 12 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_DECEMBER), | |
− | + | sexa2HoursMinute( SUM( duration ) ) AS _tr(TOTAL) | |
− | + | FROM flight | |
− | + | LEFT JOIN flight_pilot fp ON fp.flight_id = flight.id | |
− | + | LEFT JOIN person ON person.id=fp.pilot_id | |
− | + | WHERE flight.airborne=0 | |
− | + | AND person.activated=1 | |
− | + | AND fp.num = 1 | |
− | + | AND YEAR( start_date ) = $year | |
− | + | AND ( flight.activity_type_id & $activityTypeId OR ''=$activityTypeId ) | |
− | + | GROUP BY person.id</sql> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | SELECT | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
==Flights hours following nationality== | ==Flights hours following nationality== | ||
Line 891: | Line 952: | ||
GROUP BY nationality.code</SQL> | GROUP BY nationality.code</SQL> | ||
− | ==Flights hours total per flight type== | + | ==Flights hours total per flight type per month== |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | <sql>SELECT | |
− | + | activity_type.name AS Type_vol, | |
− | IF( | + | flight_pilot_DC.DC, |
− | IF( ( | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 1, duration, 0 ) ) ) AS Janu, |
− | IF (( | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 2, duration, 0 ) ) ) AS Febr, |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 3, duration, 0 ) ) ) AS Marc, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 4, duration, 0 ) ) ) AS Apri, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 5, duration, 0 ) ) ) AS May, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 6, duration, 0 ) ) ) AS June, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 7, duration, 0 ) ) ) AS July, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 8, duration, 0 ) ) ) AS Augu, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 9, duration, 0 ) ) ) AS Sept, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 10, duration, 0 ) ) ) AS Octo, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 11, duration, 0 ) ) ) AS Nove, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 12, duration, 0 ) ) ) AS Dece, | |
− | + | sexa2HoursMinute( SUM( duration ) ) AS Total | |
− | + | FROM flight | |
− | + | LEFT JOIN activity_type ON activity_type.id & flight.activity_type_id | |
− | + | LEFT JOIN ( | |
− | + | SELECT flight_id, IF( MAX(num) = 1, 'Double', 'Solo' ) AS DC | |
− | IF ( | + | FROM flight_pilot |
− | + | WHERE flight_pilot.num <= 1 | |
− | + | GROUP BY flight_id | |
− | + | ) AS flight_pilot_DC ON flight.id=flight_pilot_DC.flight_id | |
− | + | WHERE YEAR(start_date) = $year | |
− | + | AND airborne = 0 | |
− | + | GROUP BY activity_type.id, flight_pilot_DC.DC | |
− | + | HAVING (Name <> 'Instruction' OR flight_pilot_DC.DC <> 'Double') | |
− | + | ORDER BY order_num ASC, DC DESC</sql> | |
− | + | ||
− | + | ==Flights hours : less than 21 years, more than 21 years, male, female, for a given profile== | |
− | + | *Variable '''$profileId''' should be defined first and should be of '''dbOjectMulti::Profile''' value type. | |
− | + | *Variable '''$year''' should be defined first and should be of '''Year''' value type. | |
− | + | ||
− | + | <sql>SELECT Sex, Young, Instruction, | |
− | + | sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS 'Avion', | |
− | + | sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS 'Hélicoptère', | |
− | + | sexa2HoursMinute(SUM(IF(category=19, duration, 0))) AS 'Planeur', | |
− | + | sexa2HoursMinute(SUM(IF(category=17, duration, 0))) AS 'ULM' | |
− | + | FROM ( | |
− | + | SELECT | |
− | + | IF( person.sex=0, 'Male', IF( person.sex=1, 'Female', 'Undefined') ) AS 'Sex', | |
− | + | IF( ( $year - YEAR( birthdate ) >= 21) , 'No', 'Yes') AS Young, | |
− | + | IF ((SELECT COUNT(*) FROM flight_pilot fp2 WHERE fp2.flight_id=fp.flight_id AND fp2.num=1)=0, 'Solo', 'Instruction') AS Instruction, | |
− | + | flight.duration, | |
− | + | resource_type.category | |
− | + | FROM flight_pilot fp | |
− | LEFT JOIN person | + | LEFT JOIN flight ON fp.flight_id=flight.id |
− | + | LEFT JOIN person ON person.id=fp.pilot_id | |
− | + | LEFT JOIN profile ON person.profile&profile.id | |
− | + | LEFT JOIN resource ON (resource.id=flight.aircraft_id) | |
+ | LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) | ||
+ | WHERE YEAR( start_date )=$year | ||
+ | AND fp.num=0 | ||
+ | AND flight.airborne = 0 | ||
+ | AND ( profile.id IN ($profileId) OR '-' IN ($profileId) ) | ||
+ | AND person.activated=1 | ||
+ | GROUP BY flight.id | ||
+ | ) AS tmp_stat | ||
+ | GROUP BY Sex, Young, Instruction WITH ROLLUP</sql> | ||
==Computation of flight time per month of "local flight"== | ==Computation of flight time per month of "local flight"== | ||
"Local flight" is defined as a flight less than 1h30 and with the same departure and destination | "Local flight" is defined as a flight less than 1h30 and with the same departure and destination | ||
− | <sql>SELECT | + | <sql>SELECT flight.aircraft_id AS Num, name AS Immat, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 1 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 1 AND aircraft_id = Num AND | + | ) AS Janv, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 2 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 2 AND aircraft_id = Num AND | + | ) AS Fevr, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 3 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 3 AND aircraft_id = Num AND | + | ) AS Mars, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 4 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 4 AND aircraft_id = Num AND | + | ) AS Avri, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 5 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 5 AND aircraft_id = Num AND | + | ) AS Mai, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 6 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 6 AND aircraft_id = Num AND | + | ) AS Juin, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 7 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 7 AND aircraft_id = Num AND | + | ) AS Juil, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 8 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 8 AND aircraft_id = Num AND | + | ) AS Aout, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 9 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 9 AND aircraft_id = Num AND | + | ) AS Sept, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 10 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 10 AND aircraft_id = Num AND | + | ) AS Octo, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 11 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 11 AND aircraft_id = Num AND | + | ) AS Nove, |
− | (SELECT | + | ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) |
− | + | FROM flight | |
− | FROM flight | + | WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 12 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | WHERE YEAR(start_date)= $year AND MONTH(start_date)= 12 AND aircraft_id = Num ) AS Dece, | + | ) AS Dece, |
− | CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) AS Total | + | CONCAT( FLOOR(SUM(duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) AS Total |
FROM flight | FROM flight | ||
− | LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id | + | LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id |
LEFT JOIN resource ON resource.id = aircraft.id | LEFT JOIN resource ON resource.id = aircraft.id | ||
− | WHERE YEAR(start_date)= $year | + | WHERE YEAR(flight.start_date) = $year AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 |
− | GROUP BY | + | GROUP BY resource.id</sql> |
==Computation of non-"local flight" time per month== | ==Computation of non-"local flight" time per month== | ||
Line 1,074: | Line 1,127: | ||
LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id | LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id | ||
LEFT JOIN resource ON resource.id = aircraft.id | LEFT JOIN resource ON resource.id = aircraft.id | ||
− | WHERE YEAR(start_date)= $year | + | WHERE YEAR(start_date)= $year AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id) |
− | GROUP BY | + | GROUP BY resource.id</sql> |
− | == | + | ==Stats all flight hours per month per year== |
− | + | ||
− | <sql> | + | <sql>SELECT YEAR(start_date) AS Year, 'Monthly' AS Type, |
− | SELECT | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 1, duration, 0 ) ) ) AS Janu, |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 2, duration, 0 ) ) ) AS Febr, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 3, duration, 0 ) ) ) AS Marc, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 4, duration, 0 ) ) ) AS Apri, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 5, duration, 0 ) ) ) AS May, | |
− | FROM flight | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 6, duration, 0 ) ) ) AS June, |
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 7, duration, 0 ) ) ) AS July, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 8, duration, 0 ) ) ) AS Augu, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 9, duration, 0 ) ) ) AS Sept, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 10, duration, 0 ) ) ) AS Octo, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 11, duration, 0 ) ) ) AS Nove, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) = 12, duration, 0 ) ) ) AS Dece, | ||
+ | sexa2HoursMinute( SUM( duration ) ) AS Total | ||
+ | FROM flight | ||
LEFT JOIN resource ON resource.id = flight.aircraft_id | LEFT JOIN resource ON resource.id = flight.aircraft_id | ||
− | + | GROUP BY Year | |
− | + | UNION | |
− | + | SELECT YEAR(start_date) AS Year, 'Accumulation' AS Type, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 1, duration, 0 ) ) ) AS Janu, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 2, duration, 0 ) ) ) AS Febr, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 3, duration, 0 ) ) ) AS Marc, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 4, duration, 0 ) ) ) AS Apri, | |
− | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 5, duration, 0 ) ) ) AS May, | |
− | </sql> | + | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 6, duration, 0 ) ) ) AS June, |
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 7, duration, 0 ) ) ) AS July, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 8, duration, 0 ) ) ) AS Augu, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 9, duration, 0 ) ) ) AS Sept, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 10, duration, 0 ) ) ) AS Octo, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 11, duration, 0 ) ) ) AS Nove, | ||
+ | sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 12, duration, 0 ) ) ) AS Dece, | ||
+ | sexa2HoursMinute( SUM( duration ) ) AS Total | ||
+ | FROM flight | ||
+ | LEFT JOIN resource ON resource.id = flight.aircraft_id | ||
+ | GROUP BY Year | ||
+ | ORDER BY Type DESC, Year</sql> | ||
− | == | + | ==Flight hours per activity type between date== |
− | + | * Variable '''$startDate''' should be defined first and should be of '''Date and time''' value type. | |
− | * | + | * Variable '''$endDate''' should be defined first and should be of '''Date and time''' value type. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | <sql>[OF_DYNAMIC_SQL] | |
− | + | SELECT CONCAT( | |
− | + | 'SELECT resource.name AS _tr(RESOURCE_NAME), ', | |
− | + | GROUP_CONCAT( | |
− | + | CONCAT( | |
− | + | 'sexa2HoursMinute( SUM( IF( tmp_flight.activity_type_id & ', | |
− | + | activity_type.id, | |
− | + | ', tmp_flight.duration, 0 ) ) )', | |
− | + | ' AS ', | |
− | + | QUOTE(activity_type.name) | |
− | + | ) | |
− | + | ), | |
− | + | ', sexa2HoursMinute( SUM( tmp_flight.duration ) ) AS _tr(ALL_ACTIVITY_TYPES) | |
− | + | FROM resource | |
− | + | INNER JOIN | |
− | + | ( | |
− | + | SELECT flight.aircraft_id, flight.activity_type_id, duration | |
− | + | FROM flight | |
− | + | WHERE flight.start_date >= $startDate AND flight.start_date <= $endDate AND flight.airborne = 0 | |
+ | ) AS tmp_flight ON (resource.id=tmp_flight.aircraft_id) | ||
+ | GROUP BY resource.id' | ||
+ | ) | ||
+ | FROM activity_type | ||
+ | WHERE activity_type.activated=1</sql> | ||
+ | |||
+ | =Flight reports= | ||
+ | |||
+ | ==Activities summary for a person on the right place for a given month== | ||
+ | |||
+ | Requirement: | ||
+ | * Variable '''$year''' of '''Year''' value type | ||
+ | * Variable '''$month''' of '''Month''' value type | ||
+ | * Variable '''$personId''' of '''dbOjectMulti::Person''' value type | ||
+ | |||
+ | <sql>SELECT $month AS Mois, CONCAT(left_person.last_name, ' ', left_person.first_name) AS 'Personne en première place', activity_type.name AS 'Type d\'activité', sexa2HoursMinute( SUM( IFNULL(duration, 0) ) ) AS 'Durée' | ||
+ | FROM flight | ||
+ | LEFT JOIN activity_type ON (flight.activity_type_id & activity_type.id) | ||
+ | LEFT JOIN flight_pilot AS left_place ON (flight.id=left_place.flight_id AND left_place.num=0) | ||
+ | LEFT JOIN person AS left_person ON (left_place.pilot_id=left_person.id) | ||
+ | LEFT JOIN flight_pilot AS right_place ON (flight.id=right_place.flight_id AND right_place.num=1) | ||
+ | WHERE YEAR(flight.start_date)=$year | ||
+ | AND MONTH(flight.start_date)=$month | ||
+ | AND (right_place.pilot_id=$personId OR '-'=right_place.pilot_id='$personId') | ||
+ | GROUP BY left_person.id, activity_type.id | ||
+ | ORDER BY left_person.last_name, left_person.first_name, activity_type.name</sql> | ||
==Aircraft(s) which no flight were done for at least 30 day(s)== | ==Aircraft(s) which no flight were done for at least 30 day(s)== | ||
Line 1,156: | Line 1,224: | ||
LEFT JOIN resource ON resource.id = flight.aircraft_id | LEFT JOIN resource ON resource.id = flight.aircraft_id | ||
WHERE start_date < ( NOW() - INTERVAL 30 DAY ) | WHERE start_date < ( NOW() - INTERVAL 30 DAY ) | ||
+ | AND physical=1 AND activated=1 | ||
GROUP BY resource.id</sql> | GROUP BY resource.id</sql> | ||
− | == | + | ==Flight between two dates== |
− | + | Following variables are needed: | |
− | + | *startDate (Type : Datetime) | |
− | + | *endDate (Type : Datetime) | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | == | + | <sql>[OF_DYNAMIC_SQL] |
− | <sql>SELECT resource.name AS | + | SELECT CONCAT( |
− | FROM | + | 'SELECT |
− | LEFT JOIN | + | flight.id AS _tr(ID), |
− | LEFT JOIN | + | IF(flight.validated=1, _tr(YES), _tr(NO)) AS _tr(VALIDATED), |
− | LEFT JOIN flight ON (flight.id = | + | flight.start_date AS _tr(START_DATE), |
− | LEFT JOIN resource ON | + | resource.name AS _tr(RESOURCE), |
− | WHERE YEAR(flight.start_date) = $ | + | ( |
− | GROUP BY resource.id, | + | SELECT CONCAT(UPPER(tmp_person.last_name), \' \', tmp_person.first_name) |
+ | FROM flight_pilot AS tmp_flight_pilot | ||
+ | LEFT JOIN person AS tmp_person ON tmp_flight_pilot.pilot_id = tmp_person.id | ||
+ | WHERE tmp_flight_pilot.flight_id = flight.id AND tmp_flight_pilot.num = 0 | ||
+ | ) AS _tr(LEFT_PLACE), | ||
+ | ( | ||
+ | SELECT CONCAT(UPPER(tmp_person.last_name), \' \', tmp_person.first_name) | ||
+ | FROM flight_pilot AS tmp_flight_pilot | ||
+ | LEFT JOIN person AS tmp_person ON tmp_flight_pilot.pilot_id = tmp_person.id | ||
+ | WHERE tmp_flight_pilot.flight_id = flight.id AND tmp_flight_pilot.num = 1 | ||
+ | ) AS _tr(RIGHT_PLACE), | ||
+ | ( | ||
+ | SELECT GROUP_CONCAT( activity_type.name SEPARATOR \', \') | ||
+ | FROM flight AS tmp_flight | ||
+ | LEFT JOIN activity_type ON (tmp_flight.activity_type_id & activity_type.id) | ||
+ | WHERE flight.id=tmp_flight.id | ||
+ | ) AS _tr(ACTIVITY_TYPE), | ||
+ | ( | ||
+ | SELECT location.name | ||
+ | FROM location | ||
+ | WHERE location.icao_name=flight.departure_icao_id | ||
+ | ) AS _tr(DEPARTURE), | ||
+ | ( | ||
+ | SELECT location.name | ||
+ | FROM location | ||
+ | WHERE location.icao_name=flight.arrival_icao_id | ||
+ | ) AS _tr(ARRIVAL), | ||
+ | flight.landing_number AS _tr(FLIGHT_LANDING_NUMBER), | ||
+ | flight.people_onboard AS _tr(FLIGHT_PEOPLE_ON_BOARD), | ||
+ | sexa2HoursMinute(flight.counter_departure) AS _tr(FLIGHT_COUNTER_DEPARTURE), | ||
+ | sexa2HoursMinute(flight.counter_arrival) AS _tr(FLIGHT_COUNTER_ARRIVAL), | ||
+ | sexa2HoursMinute(flight.duration) AS _tr(DURATION_IN_HOURS_AND_MINUTES), | ||
+ | sexa2HoursHundredths(flight.duration) AS _tr(DURATION_IN_HOURS_AND_HUNDREDTHS),', | ||
+ | IFNULL(GROUP_CONCAT( | ||
+ | CONCAT( | ||
+ | IF(business_field.value_type LIKE ('dbObject::Person%'), | ||
+ | ' (SELECT CONCAT (UPPER(tmp_person.last_name), \' \', tmp_person.first_name) | ||
+ | FROM business_field_content | ||
+ | RIGHT JOIN business_field ON (business_field.id=business_field_content.business_field_id) | ||
+ | RIGHT JOIN person AS tmp_person ON (tmp_person.id=business_field_content.content) | ||
+ | WHERE business_field_content.category_id=flight.id AND business_field_content.business_field_id=', | ||
+ | ' (SELECT GROUP_CONCAT(business_field_content.content SEPARATOR \', \') | ||
+ | FROM business_field_content | ||
+ | RIGHT JOIN business_field ON (business_field.id=business_field_content.business_field_id) | ||
+ | WHERE business_field_content.category_id=flight.id AND business_field_content.business_field_id='), | ||
+ | business_field.id, | ||
+ | ') AS \'', | ||
+ | REPLACE(business_field.label, '\'', '\\\''), | ||
+ | '\'' | ||
+ | ) | ||
+ | ), '\'_\''), | ||
+ | ',( | ||
+ | SELECT SUM(account_entry.debit) - SUM(account_entry.credit) | ||
+ | FROM account_entry | ||
+ | RIGHT JOIN account ON (account.id=account_entry.account_id AND (account.category = 11 OR account.category = 2)) | ||
+ | WHERE account_entry.flow_id = flight_account_entry.account_entry_id | ||
+ | ) AS _tr(AMOUNT) | ||
+ | FROM flight | ||
+ | LEFT JOIN resource ON resource.id = flight.aircraft_id | ||
+ | LEFT JOIN flight_account_entry ON flight_account_entry.flight_id = flight.id | ||
+ | WHERE flight.start_date >= $startDate AND flight.start_date <= $endDate | ||
+ | ORDER BY flight.start_date; | ||
+ | ' | ||
+ | ) | ||
+ | FROM business_field | ||
+ | WHERE business_field.category='FLIGHT' </sql> | ||
+ | |||
+ | ==Flight log book== | ||
+ | <sql>SELECT | ||
+ | DATE_FORMAT(start_date, '%d/%m/%Y %H:%i') AS _tr(START_DATE), | ||
+ | resource.name AS _tr(RESOURCE), | ||
+ | CONCAT(last_name, ' ', first_name) AS _tr(LEFT_PLACE), | ||
+ | ( | ||
+ | SELECT CONCAT(person.last_name, ' ', person.first_name) AS _tr(RIGHT_PLACE) | ||
+ | FROM flight_pilot AS tmp2_flight_pilot | ||
+ | LEFT JOIN person ON person.id=tmp2_flight_pilot.pilot_id | ||
+ | WHERE tmp2_flight_pilot.flight_id=flight_pilot.flight_id AND tmp2_flight_pilot.num=1 | ||
+ | ) AS _tr(RIGHT_PLACE), | ||
+ | IF ( (SELECT COUNT(*) FROM flight_pilot AS tmp_flight_pilot WHERE tmp_flight_pilot.flight_id=flight_pilot.flight_id AND tmp_flight_pilot.num=1)=0, 'S', 'D' ) AS 'Solo / DC', | ||
+ | sexa2HoursMinute(flight.duration) AS _tr(DURATION), | ||
+ | ( | ||
+ | SELECT GROUP_CONCAT( activity_type.name SEPARATOR ', ') | ||
+ | FROM flight AS tmp_flight | ||
+ | LEFT JOIN activity_type ON (tmp_flight.activity_type_id & activity_type.id) | ||
+ | WHERE tmp_flight.id=flight.id | ||
+ | ) AS _tr(ACTIVITY_TYPE), | ||
+ | flight.departure_icao_id AS _tr(DEPARTURE), | ||
+ | flight.arrival_icao_id AS _tr(ARRIVAL), | ||
+ | flight.landing_number AS _tr(FLIGHT_LANDING_NUMBER), | ||
+ | flight.people_onboard AS _tr(FLIGHT_PEOPLE_ON_BOARD), | ||
+ | business_field_comment.content AS _tr(COMMENT) | ||
+ | FROM flight_pilot | ||
+ | LEFT JOIN flight ON flight_pilot.flight_id=flight.id | ||
+ | LEFT JOIN activity_type ON (activity_type.id & flight.activity_type_id) | ||
+ | LEFT JOIN person ON person.id=flight_pilot.pilot_id | ||
+ | LEFT JOIN resource ON resource.id = flight.aircraft_id | ||
+ | LEFT JOIN ( | ||
+ | SELECT business_field_content.category_id, business_field_content.content | ||
+ | FROM business_field_content | ||
+ | LEFT JOIN business_field ON (business_field.id=business_field_content.business_field_id) | ||
+ | WHERE business_field.variable='activityComment' | ||
+ | ) AS business_field_comment ON (business_field_comment.category_id=flight.id) | ||
+ | WHERE YEAR( start_date ) = $year | ||
+ | AND flight_pilot.num=0 | ||
+ | AND flight.airborne=0 | ||
+ | GROUP BY flight.id | ||
+ | ORDER BY CONCAT(last_name, ' ', first_name), start_date</sql> | ||
+ | |||
+ | ==Flights which have landed elsewhere than the base field== | ||
+ | Variable $icao shall be defined (dbObject:Location) | ||
+ | <sql>SELECT DATE_FORMAT(flight.start_date, '%d/%m/%Y') AS Date, | ||
+ | resource.name AS Immatriculation, | ||
+ | CONCAT(FLOOR( duration/600),':',TIME_FORMAT(SEC_TO_TIME((duration/600 - FLOOR(duration/600))*3600),'%i')) AS Durée, | ||
+ | person.last_name AS Nom, | ||
+ | person.first_name AS Prénom, | ||
+ | flight.departure_icao_id AS Départ, | ||
+ | flight.arrival_icao_id AS Arrivée | ||
+ | FROM flight | ||
+ | LEFT JOIN resource ON resource.id = flight.aircraft_id | ||
+ | LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id | ||
+ | LEFT JOIN person ON person.id = flight_pilot.pilot_id | ||
+ | WHERE flight_pilot.num = 0 AND( flight.departure_icao_id LIKE $icao OR flight.arrival_icao_id LIKE $icao ) | ||
+ | GROUP BY flight.id </sql> | ||
+ | |||
+ | ==Flights with mechanic remark== | ||
+ | Following variables are needed: | ||
+ | *Business field '''$maintenanceUserComment''' should be defined first and should be of '''Text multi line''' value type and '''Flight''' category. | ||
+ | *Business field '''$mechanicAnswer''' should be defined first and should be of '''Text multi line''' value type and '''Flight''' category. | ||
+ | *Business field '''$resourceId''' should be defined first and should be of '''dbObject::Resource''' value type and '''Report''' category. | ||
+ | *Business field '''$numberMonth''' should be defined first and should be of '''integer''' value type and '''Report''' category. | ||
+ | |||
+ | <sql>SELECT CONCAT( | ||
+ | '[LINK=index.php[QUESTION_MARK]menuAction=flight_record&menuParameter=', | ||
+ | flight.id, | ||
+ | '&menuParameterBis=flight_resource_logbook&menuParameter3=1]', | ||
+ | flight.start_date, | ||
+ | '[/LINK]' | ||
+ | ) AS _tr(DATE), | ||
+ | resource.name AS _tr(RESOURCE), | ||
+ | sexa2HoursMinute(flight.duration) AS _tr(DURATION), | ||
+ | person.last_name AS Nom, | ||
+ | person.first_name AS _tr(FIRST_NAME), | ||
+ | departure_location.icao_name AS _tr(DEPARTURE), | ||
+ | arrival_location.icao_name AS _tr(ARRIVAL), | ||
+ | maintenanceUserComment.content AS _tr(REMARK), | ||
+ | mechanicAnswer.content AS _tr(ANSWER) | ||
+ | FROM flight | ||
+ | LEFT JOIN resource ON resource.id = flight.aircraft_id | ||
+ | LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id | ||
+ | LEFT JOIN person ON person.id = flight_pilot.pilot_id | ||
+ | LEFT JOIN location AS departure_location ON departure_location.icao_name = flight.departure_icao_id | ||
+ | LEFT JOIN location AS arrival_location ON arrival_location.icao_name = flight.arrival_icao_id | ||
+ | LEFT JOIN business_field_content AS maintenanceUserComment ON maintenanceUserComment.category_id = flight.id | ||
+ | LEFT JOIN business_field_content AS mechanicAnswer ON mechanicAnswer.category_id = flight.id | ||
+ | WHERE flight_pilot.num = 0 | ||
+ | AND maintenanceUserComment.business_field_id =( SELECT business_field.id FROM business_field WHERE ( business_field.variable = "maintenanceUserComment" ) ) | ||
+ | AND mechanicAnswer.business_field_id =( SELECT business_field.id FROM business_field WHERE ( business_field.variable = "mechanicAnswer" ) ) | ||
+ | AND ( maintenanceUserComment.content <> "" OR mechanicAnswer.content <> "" ) | ||
+ | AND start_date > DATE_SUB( NOW(), INTERVAL $numberMonth MONTH) | ||
+ | AND ( (resource.id = $resourceId) OR($resourceId < '1') ) | ||
+ | GROUP BY flight.id | ||
+ | ORDER BY resource.name, start_date DESC </sql> | ||
+ | |||
+ | ==Flight with their location code (ICAO)== | ||
+ | <sql>SELECT flight.* | ||
+ | FROM flight</sql> | ||
+ | |||
+ | ==Flight hours total per person== | ||
+ | Following variables are needed: | ||
+ | * Variable '''$endDate''' of '''Date and time''' value type. | ||
+ | * Variable '''$startDate''' of '''Date and time''' value type. | ||
− | |||
<sql>SELECT | <sql>SELECT | ||
− | aircraft_type_name AS | + | CONCAT(person.last_name,' ',person.first_name) AS _tr(LAST_NAME), |
+ | sexa2HoursMinute( SUM( IFNULL( Solo.sum_duration, 0 ) ) ) AS _tr(ALONE), | ||
+ | sexa2HoursMinute( SUM( IFNULL( DC.sum_duration, 0 ) ) ) AS _tr(LEGEND_INSTRUCTION), | ||
+ | sexa2HoursMinute( SUM( IFNULL( Solo.sum_duration, 0 ) ) + SUM( IFNULL( DC.sum_duration, 0 ) ) ) AS _tr(TOTAL) | ||
+ | FROM person | ||
+ | LEFT JOIN ( | ||
+ | SELECT | ||
+ | pilot_id, | ||
+ | IF ( | ||
+ | (SELECT COUNT(*) FROM flight_pilot flight_pilot_2 WHERE flight_pilot_2.flight_id=flight_pilot_1.flight_id AND flight_pilot_2.num=1)=0, | ||
+ | 'Solo', | ||
+ | 'DC' | ||
+ | ) AS Solo_DC, | ||
+ | SUM(flight.duration) AS sum_duration | ||
+ | FROM flight_pilot flight_pilot_1 | ||
+ | LEFT JOIN flight ON flight_pilot_1.flight_id=flight.id | ||
+ | WHERE flight.airborne=0 AND flight.start_date >= $startDate AND flight.start_date <= $endDate AND flight_pilot_1.num=0 | ||
+ | GROUP BY pilot_id, Solo_DC | ||
+ | ) AS Solo ON person.id=Solo.pilot_id AND Solo.Solo_DC='Solo' | ||
+ | LEFT JOIN ( | ||
+ | SELECT | ||
+ | pilot_id, | ||
+ | IF ( | ||
+ | (SELECT COUNT(*) FROM flight_pilot flight_pilot_2 WHERE flight_pilot_2.flight_id=flight_pilot_1.flight_id AND flight_pilot_2.num=1)=0, | ||
+ | 'Solo', | ||
+ | 'DC' | ||
+ | ) AS Solo_DC, | ||
+ | SUM(flight.duration) AS sum_duration | ||
+ | FROM flight_pilot flight_pilot_1 | ||
+ | LEFT JOIN flight ON flight_pilot_1.flight_id=flight.id | ||
+ | WHERE flight.airborne=0 AND flight.start_date >= $startDate AND flight.start_date <= $endDate AND flight_pilot_1.num=0 | ||
+ | GROUP BY pilot_id, Solo_DC | ||
+ | ) AS DC ON person.id=DC.pilot_id AND DC.Solo_DC='DC' | ||
+ | WHERE (Solo.pilot_id IS NOT NULL OR DC.pilot_id IS NOT NULL) | ||
+ | AND person.activated=1 | ||
+ | GROUP BY person.id | ||
+ | ORDER BY Nom</sql> | ||
+ | |||
+ | =Fuel/Oil reports= | ||
+ | ==Hourly consumption== | ||
+ | Unit is: unit of the tank per hour | ||
+ | <SQL>SELECT | ||
+ | resource_name AS '_tr(REPORT_RESOURCE)', | ||
+ | CASE tank_type | ||
+ | WHEN 1 THEN "AVGAS" | ||
+ | WHEN 2 THEN "JET A1" | ||
+ | WHEN 3 THEN "Oil" | ||
+ | WHEN 4 THEN "SP95" | ||
+ | WHEN 5 THEN "SP98" | ||
+ | WHEN 6 THEN "GAZOLE" | ||
+ | END AS '_tr(TANK)', | ||
+ | CAST(SUM(IF (month_num=1, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_JAN)', | ||
+ | CAST(SUM(IF (month_num=2, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_FEB)', | ||
+ | CAST(SUM(IF (month_num=3, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_MAR)', | ||
+ | CAST(SUM(IF (month_num=4, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_APR)', | ||
+ | CAST(SUM(IF (month_num=5, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_MAY)', | ||
+ | CAST(SUM(IF (month_num=6, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_JUN)', | ||
+ | CAST(SUM(IF (month_num=7, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_JUL)', | ||
+ | CAST(SUM(IF (month_num=8, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_AUG)', | ||
+ | CAST(SUM(IF (month_num=9, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_SEP)', | ||
+ | CAST(SUM(IF (month_num=10, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_OCT)', | ||
+ | CAST(SUM(IF (month_num=11, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_NOV)', | ||
+ | CAST(SUM(IF (month_num=12, IF (flight_time >0 ,quantity/flight_time*600 , 0), 0)) AS DECIMAL(10,2) ) AS '_tr(MONTH_DEC)', | ||
+ | CAST(SUM(quantity)/(SELECT SUM(duration) FROM flight WHERE aircraft_id = resource_id AND YEAR (start_date) = $year)*600 AS DECIMAL(10,2) ) AS '_tr(ANNUAL_AVERAGE)' | ||
+ | FROM | ||
+ | (SELECT resource.name AS resource_name, | ||
+ | resource.id AS resource_id, | ||
+ | tank.tank_type_id AS tank_type, | ||
+ | flight_tank_qty.quantity AS quantity, | ||
+ | MONTH(flight.start_date) AS month_num, | ||
+ | (SELECT SUM(flight.duration) FROM flight WHERE aircraft_id = resource_id AND YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = month_num ) AS flight_time | ||
+ | FROM tank | ||
+ | LEFT JOIN flight_tank_qty ON flight_tank_qty.tank_id = tank.id | ||
+ | LEFT JOIN flight ON flight.id = flight_tank_qty.flight_id | ||
+ | LEFT JOIN resource ON resource.id = flight.aircraft_id | ||
+ | WHERE YEAR(flight.start_date) = $year | ||
+ | ) AS my_table | ||
+ | GROUP BY resource_name, tank_type</SQL> | ||
+ | |||
+ | ==Monthly refueling by resource type== | ||
+ | <sql>SELECT | ||
+ | aircraft_type_name AS _tr(RESOURCE_TYPE), tank_label AS _tr(TANK), | ||
SUM(IF (month_num=1, quantity, 0)) AS Janu, | SUM(IF (month_num=1, quantity, 0)) AS Janu, | ||
SUM(IF (month_num=2, quantity, 0)) AS Febr, | SUM(IF (month_num=2, quantity, 0)) AS Febr, | ||
Line 1,192: | Line 1,507: | ||
SUM(IF (month_num=11, quantity, 0)) AS Nove, | SUM(IF (month_num=11, quantity, 0)) AS Nove, | ||
SUM(IF (month_num=12, quantity, 0)) AS Dece, | SUM(IF (month_num=12, quantity, 0)) AS Dece, | ||
− | SUM(quantity) AS | + | SUM(quantity) AS _tr(QUANTITY) |
FROM | FROM | ||
( | ( | ||
Line 1,218: | Line 1,533: | ||
WHEN 4 THEN "SP95" | WHEN 4 THEN "SP95" | ||
WHEN 5 THEN "SP98" | WHEN 5 THEN "SP98" | ||
+ | WHEN 6 THEN "GAZOLE" | ||
END AS Tank, | END AS Tank, | ||
SUM(IF (month_num=1, quantity, 0)) AS Janu, | SUM(IF (month_num=1, quantity, 0)) AS Janu, | ||
Line 1,231: | Line 1,547: | ||
SUM(IF (month_num=11, quantity, 0)) AS Nove, | SUM(IF (month_num=11, quantity, 0)) AS Nove, | ||
SUM(IF (month_num=12, quantity, 0)) AS Dece, | SUM(IF (month_num=12, quantity, 0)) AS Dece, | ||
− | SUM(quantity) AS | + | SUM(quantity) AS SUM, |
CAST(SUM(quantity)/(SELECT SUM(duration) FROM flight WHERE aircraft_id = resource_id AND YEAR (start_date) = $year)*600 AS DECIMAL(10,2) ) AS Consumption | CAST(SUM(quantity)/(SELECT SUM(duration) FROM flight WHERE aircraft_id = resource_id AND YEAR (start_date) = $year)*600 AS DECIMAL(10,2) ) AS Consumption | ||
FROM | FROM | ||
Line 1,247: | Line 1,563: | ||
GROUP BY resource_name, tank_type</SQL> | GROUP BY resource_name, tank_type</SQL> | ||
− | == | + | ==Total refuelings by resource over a year== |
− | + | <sql>SELECT resource.name AS _tr(RESOURCE), tank.label AS _tr(TANK), SUM( quantity ) AS _tr(QUANTITY) | |
− | < | + | FROM tank |
− | + | LEFT JOIN resource_type ON ( resource_type.id = tank.aircraft_type_id ) | |
− | + | LEFT JOIN flight_tank_qty ON ( tank.id = flight_tank_qty.tank_id ) | |
− | + | LEFT JOIN flight ON (flight.id = flight_tank_qty.flight_id) | |
− | + | LEFT JOIN resource ON (flight.aircraft_id = resource.id) | |
− | + | WHERE YEAR(flight.start_date) = $year | |
− | + | GROUP BY resource.id, tank_type_id</sql> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | GROUP BY | + | |
− | == | + | ==Total refuelings by resource type over a year== |
− | <sql>SELECT | + | <sql>SELECT resource_type.name AS _tr(RESOURCE_TYPE), tank.label AS _tr(TANK), SUM( quantity ) AS _tr(QUANTITY) |
− | + | FROM tank | |
− | + | LEFT JOIN resource_type ON ( resource_type.id = tank.aircraft_type_id ) | |
− | + | LEFT JOIN flight_tank_qty ON ( tank.id = flight_tank_qty.tank_id ) | |
− | + | LEFT JOIN flight ON (flight.id = flight_tank_qty.flight_id) | |
− | + | WHERE YEAR(flight.start_date) = $year | |
− | + | GROUP BY aircraft_type_id, tank_type_id</sql> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | FROM | + | |
− | LEFT JOIN | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
=Error message queries= | =Error message queries= | ||
Line 1,450: | Line 1,609: | ||
=[[Users exports 4|Users]]= | =[[Users exports 4|Users]]= | ||
− |
Revision as of 18:03, 18 February 2022
Contents
- 1 Introduction
- 2 SQL tips and tricks
- 3 French administration Examples
- 3.1 Flight hours total on instruction with specific activity type/profile
- 3.2 Flight hours total on non-instruction with specific activity type/profile
- 3.3 Users with a specific validity without expiration date
- 3.4 Number of movements on based airfield
- 3.5 Number of movements on based airfield on specific profile
- 3.6 Number of take-off and landings on based airfield
- 3.7 Number of take-off and landings on based airfield on specific profile
- 3.8 List of movements on based airfield
- 3.9 User flying without validity
- 3.10 List of pilots who have flown less than X hours during last Y days
- 3.11 List of pilots who have flown less than X hours during last Y days on aircraft type Z
- 3.12 Pilots without flight in the last X months
- 3.13 Total user per age profile validity: Number of men, women over and under X years for profile P, validity V up to date for year A
- 3.14 Number of landings per pilot, per resource
- 3.15 Flight hours without up to date validities
- 3.16 Number of men, women over and under 21 years for profile X, validity Y up to date for year Z
- 3.17 Total hours by activities and resource categories for an instructor for one year
- 3.18 Validity year young specific profile: Total of youngs/adults with specific profile
- 3.19 Validities obtained in the year
- 3.20 Visited airfields
- 3.21 Visited outsider airfield
- 3.22 Young from this year
- 4 Accounting
- 5 Bookings
- 6 Flight time management
- 6.1 Flight hours total and last recorded counters to the date X
- 6.2 Flight hours per month
- 6.3 Flight hours total over a 12 months period
- 6.4 Flights hours total per aircraft per year
- 6.5 Flights hours total per aircraft per year and per month (for an activity type)
- 6.6 Flight hours total per pilot
- 6.7 Flight hours total per pilot per profile
- 6.8 Total Flight hours per pilot with total
- 6.9 Flight hours per instructor, month (for a flight type)
- 6.10 Flights hours following nationality
- 6.11 Flights hours total per flight type per month
- 6.12 Flights hours : less than 21 years, more than 21 years, male, female, for a given profile
- 6.13 Computation of flight time per month of "local flight"
- 6.14 Computation of non-"local flight" time per month
- 6.15 Stats all flight hours per month per year
- 6.16 Flight hours per activity type between date
- 7 Flight reports
- 7.1 Activities summary for a person on the right place for a given month
- 7.2 Aircraft(s) which no flight were done for at least 30 day(s)
- 7.3 Flight between two dates
- 7.4 Flight log book
- 7.5 Flights which have landed elsewhere than the base field
- 7.6 Flights with mechanic remark
- 7.7 Flight with their location code (ICAO)
- 7.8 Flight hours total per person
- 8 Fuel/Oil reports
- 9 Error message queries
- 10 Users
Introduction
The goal of this page is to propose a list of statistic generation queries (SQL).
Do not forget to read the OpenFlyers SQL stored functions and procedures page.
Please note that you can make "public" a report, ie. allows standard users to see and interact with it.
Business field
For more flexibility, business field can be defined by the user.
Two business field types are available:
- "external parameters" of following types:
- Date
- Date and time
- Month
- Text string
- Time
- Whole number
- Year
- database parameters (dbObject::something or dbObjectMulti::something Value type) advanced options to access to the database field
Business field creation
- Go to Menu Admin > Reports > Custom reports > Business Field(s)
In the bottom line add
- Fill the name field with a name that will be use within the SQL queries (prefixed with the $ character)
- Fill the label field with a name used to describe the parameter as you want it to appear within the export query form.
- Choose a Value type (the most common are at the beginning of the list).
- Click on "Add"
Then within your SQL query, you may add this parameter which will be replace by the value chosen by the user filling the export form.
If you define a parameter as a database parameters (for example dbObject::Person) then the form will display a combo with the list of users and your parameter will be replace by the id integer of the chosen person.
Business field creation examples
We create a new business field for the current year:
- Name: $year
- Label: Year
- Value type: Year
Parameter Year must be filled in Reports/View form before to call the query (by default current year is filled when you call the page)
We create a new business field to list the reservation of a resource:
- Name: $resourceId
- Label: Resource
- Value type: dbObject::Resource
Then in Admin/Reports we create a new query labeled "Aircraft booking" with the following query:
SELECT * FROM booking WHERE booking.resource_id=$resourceId
To use this report, we just have to select a "Resource" in the Reports/View form, to check "Resource booking" then to click on "View"
SQL tips and tricks
Return only last entry
Example with last entry from variable #1 in variable_value table:
SELECT * FROM `variable_value` WHERE variable_id=1 ORDER BY start_date DESC LIMIT 1
Test valid entries
For business fields that are text inputs, any entry can be submitted and added to SQL query. In order to test valid entries, it is recommended to use the IF statement in the WHERE statement.
Per example, $occupiedSeat can have following values (0, 1 or NULL) :
SELECT * FROM flight_pilot WHERE ( IF((('$occupiedSeat'=0)OR('$occupiedSeat'='')), 0, -1) = flight_pilot.num OR IF((('$occupiedSeat'=1)OR('$occupiedSeat'='')), 1, -1) = flight_pilot.num )
French administration Examples
Flight hours total on instruction with specific activity type/profile
Requirement:
- Variable $activityTypeId of dbOjectMulti::ActivityType value type
- Variable $profileId of dbOjectMulti::Profile value type
- Variable $year of Year value type
SELECT tmp_flight.activity_type_name AS name, sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS 'Avion', sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS 'Hélicoptère', sexa2HoursMinute(SUM(IF(category=19, duration, 0))) AS 'Planeur', sexa2HoursMinute(SUM(IF(category=17, duration, 0))) AS 'ULM' FROM ( SELECT flightWithActivityType.activity_type_id, flightWithActivityType.activity_type_name, flightWithActivityType.duration, resource_type.category FROM ( SELECT flight.id, flight.duration, flight.aircraft_id, activity_type.id AS activity_type_id, activity_type.name AS activity_type_name FROM flight LEFT JOIN activity_type ON flight.activity_type_id&activity_type.id WHERE YEAR(flight.start_date)=$year AND flight.airborne=0 AND ( activity_type.id IN ($activityTypeId) OR '' IN ($activityTypeId) ) ) AS flightWithActivityType LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flightWithActivityType.id AND flight_pilot.num=1) LEFT JOIN ( SELECT person.* FROM person LEFT JOIN profile ON person.profile&profile.id WHERE ( profile.id IN ($profileId) OR '' IN ($profileId) ) AND person.activated=1 GROUP BY person.id ) AS personWithProfile ON (personWithProfile.id=flight_pilot.pilot_id) LEFT JOIN resource ON (resource.id=flightWithActivityType.aircraft_id) LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) WHERE personWithProfile.id IS NOT NULL ) AS tmp_flight GROUP BY tmp_flight.activity_type_id
Flight hours total on non-instruction with specific activity type/profile
Requirement:
- Variable $activityTypeId of dbOjectMulti::ActivityType value type
- Variable $profileId of dbOjectMulti::Profile value type
- Variable $year of Year value type
SELECT tmp_flight.activity_type_name AS name, sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS 'Avion', sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS 'Hélicoptère', sexa2HoursMinute(SUM(IF(category=19, duration, 0))) AS 'Planeur', sexa2HoursMinute(SUM(IF(category=17, duration, 0))) AS 'ULM' FROM ( SELECT flightWithActivityType.activity_type_id, flightWithActivityType.activity_type_name, flightWithActivityType.duration, resource_type.category FROM ( SELECT flight.id, flight.duration, flight.aircraft_id, activity_type.id AS activity_type_id, activity_type.name AS activity_type_name FROM flight LEFT JOIN activity_type ON flight.activity_type_id&activity_type.id WHERE YEAR(flight.start_date)=$year AND flight.airborne=0 AND ( activity_type.id IN ($activityTypeId) OR '' IN ($activityTypeId) ) AND flight.id NOT IN (SELECT flight_id FROM flight_pilot WHERE num=1) ) AS flightWithActivityType LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flightWithActivityType.id AND flight_pilot.num=0) LEFT JOIN ( SELECT person.* FROM person LEFT JOIN profile ON person.profile&profile.id WHERE ( profile.id IN ($profileId) OR '' IN ($profileId) ) AND person.activated=1 GROUP BY person.id ) AS personWithProfile ON (personWithProfile.id=flight_pilot.pilot_id) LEFT JOIN resource ON (resource.id=flightWithActivityType.aircraft_id) LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) WHERE personWithProfile.id IS NOT NULL ) AS tmp_flight GROUP BY tmp_flight.activity_type_id
Users with a specific validity without expiration date
- Variable $validityId should be defined first and should be of dbOjectMulti::ValidityType value type.
SELECT person.first_name, person.last_name, validity_type.name AS 'Validite' FROM validity LEFT JOIN validity_type ON validity.validity_type_id=validity_type.id LEFT JOIN person ON person.id=validity.person_id WHERE ( validity_type_id IN ($validityTypeId) OR '-' IN ($validityTypeId) ) AND expire_date IS NULL AND person.activated=1
Number of movements on based airfield
- Variable $year should be defined first and should be of Year value type.
SELECT SUM(movement) AS 'Movement' FROM ( SELECT COUNT(*) AS movement FROM flight, structure WHERE ( ( flight.departure_icao_id != structure.icao ) OR( flight.arrival_icao_id != structure.icao ) ) AND( flight.departure_icao_id != structure.icao ) AND YEAR(start_date) = $year UNION SELECT SUM(landing_number) * 2 AS movement FROM flight, structure WHERE YEAR(flight.start_date) = $year AND flight.departure_icao_id = structure.icao AND flight.arrival_icao_id = structure.icao ) AS tmp_movement
Number of movements on based airfield on specific profile
- Variable $profileId should be defined first and should be of dbOjectMulti::Profile value type.
- Variable $year should be defined first and should be of Year value type.
SELECT SUM(movement) AS 'Movement' FROM ( SELECT COUNT(*) AS movement FROM structure, flight LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flight.id) LEFT JOIN ( SELECT person.* FROM person LEFT JOIN profile ON person.profile&profile.id WHERE ( profile.id IN ($profileId) OR '' IN ($profileId) ) AND person.activated=1 GROUP BY person.id ) AS personWithProfile ON (personWithProfile.id=flight_pilot.pilot_id AND flight_pilot.num=0) WHERE ( ( flight.departure_icao_id != structure.icao) OR ( flight.arrival_icao_id != structure.icao) ) AND ( flight.departure_icao_id != structure.icao) AND YEAR(flight.start_date) = 2019 AND personWithProfile.id IS NOT NULL UNION SELECT SUM(flight.landing_number)*2 AS movement FROM structure, flight LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flight.id) LEFT JOIN ( SELECT person.* FROM person LEFT JOIN profile ON person.profile&profile.id WHERE ( profile.id IN ($profileId) OR '' IN ($profileId) ) AND person.activated=1 GROUP BY person.id ) AS personWithProfile ON (personWithProfile.id=flight_pilot.pilot_id AND flight_pilot.num=0) WHERE YEAR(flight.start_date) = $year AND flight.departure_icao_id = structure.icao AND flight.arrival_icao_id = structure.icao AND personWithProfile.id IS NOT NULL ) AS tmp_movement
Number of take-off and landings on based airfield
SELECT SUM(flight.landing_number) * 2 AS nb_mouvement FROM flight, structure WHERE ( flight.departure_icao_id = structure.icao ) AND ( flight.arrival_icao_id = structure.icao ) AND YEAR(start_date) = $year
Number of take-off and landings on based airfield on specific profile
- Variable $profileId should be defined first and should be of dbOjectMulti::Profile value type.
- Variable $year should be defined first and should be of Year value type.
SELECT SUM(flight.landing_number) * 2 AS 'Movement' FROM structure, flight LEFT JOIN flight_pilot ON ( flight_pilot.flight_id = flight.id ) LEFT JOIN ( SELECT person.* FROM person LEFT JOIN profile ON person.profile & profile.id WHERE (profile.id IN($profileId) OR '-' IN($profileId)) AND person.activated = 1 GROUP BY person.id ) AS personWithProfile ON ( personWithProfile.id = flight_pilot.pilot_id AND flight_pilot.num = 0 ) WHERE personWithProfile.id IS NOT NULL AND YEAR(flight.start_date) = $year AND flight.departure_icao_id = structure.icao AND flight.arrival_icao_id = structure.icao
List of movements on based airfield
SELECT location.icao_name AS ICAO, location.name AS NAME, COUNT(location.icao_name) AS nb_flight FROM structure, flight LEFT JOIN location ON flight.departure_icao_id = location.icao_name WHERE ( flight.departure_icao_id = structure.icao ) OR( flight.arrival_icao_id = structure.icao ) AND departure_icao_id != arrival_icao_id AND YEAR(start_date) = $year GROUP BY icao_name ORDER BY nb_flight DESC
User flying without validity
SELECT CONCAT(person.last_name, ' ', person.first_name) AS _tr(PILOT), validity_type.name AS _tr(VALIDITY) FROM flight_type_mandatory_validity_type LEFT JOIN activity_type ON activity_type.id = flight_type_mandatory_validity_type.activity_type_id LEFT JOIN flight ON flight.activity_type_id & activity_type.id LEFT JOIN resource ON resource.id = flight.aircraft_id LEFT JOIN resource_type ON resource.resource_type_id = resource_type.id LEFT JOIN aircraft_type_validity_type ON resource_type.id = aircraft_type_validity_type.aircraft_type_id LEFT JOIN flight_pilot ON flight.id = flight_pilot.flight_id LEFT JOIN person ON person.id = flight_pilot.pilot_id LEFT JOIN validity_type ON (validity_type.id = flight_type_mandatory_validity_type.validity_type_id OR validity_type.id = aircraft_type_validity_type.validity_type_id) LEFT JOIN validity ON validity_type.id = validity.validity_type_id AND person.id = validity.person_id AND validity.is_current_validity = 1 WHERE flight.airborne = 0 AND validity_type.id IS NOT NULL AND validity_type.experience_formula IS NULL AND validity.validity_type_id IS NULL AND person.activated = 1 AND validity_type.activated = 1 GROUP BY person.id, validity_type.id ORDER BY `_tr(PILOT)`, validity_type.name
List of pilots who have flown less than X hours during last Y days
SELECT CONCAT(au.last_name, ' ', au.first_name) AS pilot, TIME_FORMAT( SEC_TO_TIME( SUM(f.duration)*6 ), '%H:%i' ) AS total_time FROM flight AS f RIGHT JOIN flight_pilot AS fp ON fp.flight_id=f.id LEFT JOIN aircraft AS ai ON ai.id = f.aircraft_id LEFT JOIN person AS au ON fp.pilot_id = au.id WHERE f.airborne = 0 AND start_date BETWEEN NOW() - INTERVAL Y DAY AND NOW() GROUP BY au.id HAVING SUM(f.duration)/600 < X ORDER BY pilot
List of pilots who have flown less than X hours during last Y days on aircraft type Z
SELECT CONCAT(au.last_name, ' ', au.first_name) AS pilot, TIME_FORMAT( SEC_TO_TIME( SUM(f.duration)*6 ), '%H:%i' ) AS total_time FROM flight AS f RIGHT JOIN flight_pilot AS fp ON fp.flight_id=f.id LEFT JOIN resource AS ai ON ai.id = f.aircraft_id LEFT JOIN resource_type AS at ON ai.resource_type_id = at.id LEFT JOIN person AS au ON fp.pilot_id = au.id WHERE f.airborne = 0 AND start_date BETWEEN NOW() - INTERVAL Y DAY AND NOW() AND at.id IN ( Z1, Z2, Z3, Z... ) GROUP BY au.id HAVING SUM(f.duration)/600 <= X ORDER BY pilot
Pilots without flight in the last X months
- Variable $numberMonth should be defined first and should be of integer value type.
SELECT person.last_name, person.first_name, IFNULL((SELECT CONCAT(DATE_FORMAT( f1.start_date, '%d/%m/%Y' ),' ', resource.name,' Duration: ', TIME_FORMAT(SEC_TO_TIME(f1.duration*6 ) ,'%H h %i')) FROM flight AS f1 LEFT JOIN flight_pilot AS fp ON fp.flight_id=f1.id LEFT JOIN resource ON resource.id=f1.aircraft_id WHERE fp.pilot_id=person.id ORDER BY f1.start_date DESC LIMIT 1),'UNKNOWN') AS 'Last flight' FROM person WHERE person.activated=1 AND person.id NOT IN ( SELECT person2.id FROM flight AS f LEFT JOIN flight_pilot AS fp ON fp.flight_id=f.id LEFT JOIN person AS person2 ON person2.id=fp.pilot_id WHERE f.airborne = 0 AND f.start_date BETWEEN NOW() - INTERVAL IF($numberMonth='', 1, $numberMonth*30) DAY AND NOW() GROUP BY person2.id HAVING SUM(f.duration)/600 > 0 ) ORDER BY person.last_name, person.first_name
Total user per age profile validity: Number of men, women over and under X years for profile P, validity V up to date for year A
- Variable $age should be of integer value type.
- Variable $profileId should be of dbOjectMulti::Profile value type.
- Variable $validityTypeId should be of dbObjectMulti::validityType value type.
- Variable $year should be of Year value type.
SELECT IF( personWithProfile.sex=0, _tr(SEX_MALE_INITIAL), IF( personWithProfile.sex=1, _tr(SEX_FEMALE_INITIAL), _tr(UNDEFINED)) ) AS _tr(SEX), IF( ( $year - YEAR(birthdate) >= $age ) , _tr(YES), _tr(NO)) AS _tr(ADULT), COUNT(DISTINCT personWithProfile.id) AS _tr(NUMBER) FROM ( SELECT person.* FROM person LEFT JOIN profile ON person.profile&profile.id WHERE ( profile.id IN ($profileId) OR '-' IN ($profileId) ) AND person.activated=1 ) AS personWithProfile LEFT JOIN validity ON personWithProfile.id = validity.person_id AND validity.is_current_validity = 1 LEFT JOIN validity_type ON (validity_type.id=validity.validity_type_id) WHERE ((validity_type.id IN ($validityTypeId) AND validity.expire_date >= '$year-12-31') OR '-' IN ($validityTypeId)) AND validity_type.activated = 1 GROUP BY `_tr(SEX)`, `_tr(ADULT)`
Number of landings per pilot, per resource
SELECT last_name as "Last_name", first_name as "First_name", (IF(DATE(valid.grant_date) < date(NOW()),'B', 'E')) as 'S', -- (IF(DATE(valid.grant_date) < date(NOW()),valid_typ.name, 'Eleve')) as 'S2', (SELECT SUM(landing_number) FROM flight LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE flight_pilot.pilot_id = a.id AND flight.start_date BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()) AS atterrissages, (SELECT SUM(landing_number) FROM flight LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE flight_pilot.pilot_id = a.id -- AND flight.aircraft_id = 1 AND flight.aircraft_id = 18 AND flight.start_date BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()) AS KT, (SELECT SUM(landing_number) FROM flight LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE flight_pilot.pilot_id = a.id -- AND flight.aircraft_id = 10 AND flight.aircraft_id = 2 AND flight.start_date BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()) AS QR, (SELECT SUM(landing_number) FROM flight LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE flight_pilot.pilot_id = a.id -- AND flight.aircraft_id = 2 AND flight.aircraft_id = 3 AND flight.start_date BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()) AS KH, (SELECT SUM(landing_number) FROM flight LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE flight_pilot.pilot_id = a.id -- AND flight.aircraft_id = 3 AND flight.aircraft_id = 4 AND flight.start_date BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()) AS XF, (SELECT SUM(landing_number) FROM flight LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE flight_pilot.pilot_id = a.id AND (flight.aircraft_id = 2 OR flight.aircraft_id = 3 OR flight.aircraft_id = 4 OR flight.aircraft_id = 18) AND flight.start_date BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()) AS DR400, (SELECT SUM(landing_number) FROM flight LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE flight_pilot.pilot_id = a.id AND flight.aircraft_id = 23 AND flight.start_date BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()) AS DR500, (SELECT SUM(landing_number) FROM flight LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE flight_pilot.pilot_id = a.id AND flight.aircraft_id = 8 AND flight.start_date BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()) AS 'MC-IP', (SELECT SUM(landing_number) FROM flight LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE flight_pilot.pilot_id = a.id AND flight.aircraft_id = 21 AND flight.start_date BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()) AS 'CAP10-DL' FROM person a LEFT JOIN profile AS p1 ON (a.profile & p1.id) LEFT JOIN validity valid ON valid.person_id = a.id LEFT JOIN validity_type valid_typ ON valid_typ.id = valid.validity_type_id WHERE YEAR(grant_date) >= YEAR(NOW()) AND a.activated=1 AND p1.name='Pilot' GROUP BY last_name, first_name ORDER BY last_name
Flight hours without up to date validities
- Variable $year
SELECT DATE_FORMAT(start_date, '%d %m %Y' ) AS _tr(DATE), CONCAT(person.last_name, ' ', person.first_name) AS _tr(FULL_NAME), IF ( (SELECT COUNT(*) FROM flight_pilot AS tmp_flight_pilot WHERE flight_pilot.flight_id=tmp_flight_pilot.flight_id AND tmp_flight_pilot.num=1)=0, 'Solo', 'DC' ) AS DC, resource.name AS _tr(RESOURCE), sexa2HoursMinute(duration) AS _tr(DURATION), activity_type.name AS _tr(ACTIVITY_TYPE), validity_type.name AS _tr(VALIDITY) FROM flight LEFT JOIN flight_type_mandatory_validity_type ON flight_type_mandatory_validity_type.activity_type_id & flight.activity_type_id LEFT JOIN flight_pilot ON flight.id = flight_pilot.flight_id LEFT JOIN person ON flight_pilot.pilot_id = person.id LEFT JOIN validity_type ON flight_type_mandatory_validity_type.validity_type_id = validity_type.id LEFT JOIN validity ON flight_type_mandatory_validity_type.validity_type_id = validity.validity_type_id AND validity.is_current_validity = 1 LEFT JOIN resource ON flight.aircraft_id = resource.id LEFT JOIN activity_type ON flight_type_mandatory_validity_type.activity_type_id = activity_type.id WHERE YEAR(start_date) = $year AND flight_pilot.num = 0 AND validity_type.time_limitation=1 AND validity.person_id = flight_pilot.pilot_id AND flight.start_date > validity.expire_date AND person.activated = 1 AND validity_type.activated = 1 ORDER BY flight.start_date, `_tr(FULL_NAME)`, validity_type.name
Number of men, women over and under 21 years for profile X, validity Y up to date for year Z
- Variable $age should be of integer value type.
- Variable $profileId should be of dbOjectMulti::Profile value type.
- Variable $validityTypeId should be of dbObjectMulti::validityType value type.
- Variable $year should be of Year value type.
SELECT IF( person.sex=0, 'Male', IF( person.sex=1, 'Female', 'Undefined') ) AS 'Sex', IF( ( $year - YEAR(birthdate) >= '$age' ) , 'Yes', 'No') AS 'Adult', COUNT(DISTINCT person.id) AS NUMBER FROM person LEFT JOIN validity ON (person.id=validity.person_id) LEFT JOIN validity_type ON (validity_type.id=validity.validity_type_id) WHERE activated=1 AND (profile & '$profileId' OR '-'='$profileId') AND ( (validity_type.id='$validityTypeId' AND validity.expire_date >= '$year-12-31') OR '-'='$validityTypeId' ) GROUP BY Sex, Adult
Total hours by activities and resource categories for an instructor for one year
- Variable $personId should be defined first and should be of dbOjectMulti::Person value type.
- Variable $year should be defined first and should be of Year value type.
SELECT tmp_flight.activity_type_name AS name, sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS _tr(AIRCRAFT_CATEGORY), sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS _tr(HELICOPTER_CATEGORY), sexa2HoursMinute(SUM(IF(category=19, duration, 0))) AS _tr(GLIDER_CATEGORY), sexa2HoursMinute(SUM(IF(category=17, duration, 0))) AS _tr(ULTRA_LIGHT_CATEGORY), sexa2HoursMinute(SUM(IF(category=9, duration, 0))) AS _tr(CLASSROOM_CATEGORY) FROM ( SELECT flightWithActivityType.activity_type_id, flightWithActivityType.activity_type_name, flightWithActivityType.duration, resource_type.category FROM ( SELECT flight.id, flight.duration, flight.aircraft_id, activity_type.id AS activity_type_id, activity_type.name AS activity_type_name FROM flight LEFT JOIN activity_type ON flight.activity_type_id&activity_type.id LEFT JOIN flight_pilot ON (flight_pilot.flight_id=flight.id AND flight_pilot.num=1) WHERE YEAR(flight.start_date)=$year AND flight.airborne=0 AND flight_pilot.pilot_id=$personId ) AS flightWithActivityType LEFT JOIN resource ON (resource.id=flightWithActivityType.aircraft_id) LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) ) AS tmp_flight GROUP BY tmp_flight.activity_type_id
Validity year young specific profile: Total of youngs/adults with specific profile
- Variable $profileId should be defined first and should be of dbOjectMulti::Profile value type.
- Variable $year should be defined first and should be of Year value type.
- Note: "21" is the limit of age to categorize a young and adult person. Change it according to your need.
SELECT validity_type.name AS '_tr(VALIDITY)', SUM( IF( ( $year - YEAR(personWithProfile.birthdate) < 21 ), 1, 0 ) ) AS '_tr(YOUNG)', SUM( IF( ( $year - YEAR(personWithProfile.birthdate) >= 21 ), 1, 0 ) ) AS '_tr(ADULT)' FROM validity_type LEFT JOIN validity ON validity.validity_type_id = validity_type.id AND validity.is_current_validity = 1 LEFT JOIN ( SELECT person.* FROM person LEFT JOIN profile ON person.profile&profile.id WHERE ( profile.id IN ($profileId) OR '-' IN ($profileId) ) AND person.activated=1 GROUP BY person.id ) AS personWithProfile ON (validity.person_id=personWithProfile.id) WHERE YEAR(validity.grant_date)=$year AND personWithProfile.id IS NOT NULL AND validity_type.activated = 1 GROUP BY validity_type.id ORDER BY validity_type.name
Validities obtained in the year
- Variable $validityId should be defined first and should be of dbOjectMulti::ValidityType value type.
- 21 value is the age limit to be young. Should be changed according local rules
SELECT last_name AS Last_name, first_name AS First_name, IF( ( $year - YEAR( birthdate ) >= 21) , 'No', 'Yes') AS Young, IF( person.sex=0, 'Male', IF( person.sex=1, 'Female', 'Undefined') ) AS 'Sex', DATE_FORMAT( grant_date, '%d/%m/%Y' ) AS Date, validity_type.name AS 'Validity' FROM person LEFT JOIN validity ON person_id=person.id LEFT JOIN validity_type ON validity_type.id=validity.validity_type_id WHERE YEAR(grant_date)=$year AND ( validity_type.id IN ($validityTypeId) OR '-' IN ($validityTypeId) ) AND person.activated=1 ORDER BY last_name, first_name
Visited airfields
SELECT location.icao_name AS ICAO, location.name AS NAME, COUNT(location.icao_name) AS Visit FROM structure, flight LEFT JOIN location ON ( flight.departure_icao_id = location.icao_name ) WHERE ( ( flight.departure_icao_id != structure.icao ) OR ( flight.arrival_icao_id != structure.icao ) ) AND YEAR(start_date) = $year GROUP BY location.icao_name ORDER BY Visit DESC
Visited outsider airfield
SELECT location.icao_name AS ICAO, location.name AS Name, COUNT(location.icao_name) AS nb_visite FROM structure, flight LEFT JOIN location ON ( flight.departure_icao_id = location.icao_name ) WHERE ( ( flight.departure_icao_id !=structure.icao ) OR( flight.arrival_icao_id !=structure.icao ) ) AND YEAR(start_date) = $year GROUP BY location.icao_name ORDER BY nb_visite DESC
Young from this year
SELECT CONCAT( '[LINK=index.php[QUESTION_MARK]menuAction=admin_add_modify_user&menuParameter=',person.id,'&menuParameterBis=last_name&menuParameter3=', LEFT(person.last_name, 1),']', person.id, '[/LINK]' ) AS _tr(ID), person.first_name AS _tr(FIRST_NAME), person.last_name AS _tr(LAST_NAME), DATE_FORMAT(birthdate ,'%m-%d-%Y') AS _tr(USER_BIRTHDATE), IF ( sex = 0, _tr(SEX_MALE), _tr(SEX_FEMALE) ) AS _tr(USER_SEX) FROM person WHERE ($year-YEAR(birthdate))<=$age AND activated=1
Accounting
Bookings
Booking
- Variable $endDate of Date and time value type.
- Variable $startDate of Date and time value type.
- Variable $personId of dbObject::Person value type.
- Variable $resourceId of dbObject::Resource value type.
[OF_DYNAMIC_SQL] SELECT CONCAT( 'SELECT booking.id AS _tr(ID), DATE_FORMAT(booking.start_date, \'%Y-%m-%d %H:%i\') AS _tr(START_DATE), DATE_FORMAT(booking.end_date, \'%Y-%m-%d %H:%i\') AS _tr(END_DATE), ( SELECT GROUP_CONCAT( activity_type.name SEPARATOR \', \') FROM booking_activity_type LEFT JOIN activity_type ON (booking_activity_type.activity_type_id = activity_type.id) WHERE booking_activity_type.booking_id=booking.id ) AS _tr(ACTIVITY_TYPE), resource.name AS _tr(RESOURCE), left_booking_person.full_name AS _tr(LEFT_PLACE), right_booking_person.full_name AS _tr(RIGHT_PLACE), ', IFNULL(GROUP_CONCAT( CONCAT( ' (SELECT business_field_content.content FROM business_field_content WHERE booking.id=business_field_content.category_id AND business_field_content.business_field_id=', business_field.id, ' LIMIT 1) AS \'', REPLACE(business_field.label, '\'', '\\\''), '\'' ) ), '\'_\''), 'FROM booking LEFT JOIN booking_resource ON (booking.id=booking_resource.booking_id) LEFT JOIN resource ON (resource.id=booking_resource.resource_id) LEFT JOIN ( SELECT booking_person.booking_id, booking_person.person_id, CONCAT(person.last_name, \' \', person.first_name) AS full_name FROM booking_person LEFT JOIN person ON (person.id=booking_person.person_id) WHERE booking_person.place_num=0 AND person.activated=1 ) AS left_booking_person ON (booking.id=left_booking_person.booking_id) LEFT JOIN ( SELECT booking_person.booking_id, booking_person.person_id, CONCAT(person.last_name, \' \', person.first_name) AS full_name FROM booking_person LEFT JOIN person ON (person.id=booking_person.person_id) WHERE booking_person.place_num=1 AND person.activated=1 ) AS right_booking_person ON (booking.id=right_booking_person.booking_id) WHERE booking.start_date >= $startDate AND booking.end_date < $endDate AND (booking_resource.resource_id=$resourceId OR \'\'=$resourceId) AND ( left_booking_person.person_id=$personId OR right_booking_person.person_id=$personId OR \'\'=$personId ) ORDER BY booking.start_date, booking.end_date' ) FROM business_field WHERE business_field.category='BOOKING' AND business_field.variable IN ('bookingEstimatedFlightTime', 'bookingComment')
Cumulated maintenance hours on a period
Following extrafields are needed :
- startDate (Type : Date)
- endDate (Type : Date or DateTime)
SELECT IF(LEAST($startDate + INTERVAL 366 DAY, $endDate) <> $endDate, ' Attention la date de fin retenue correspond à la date de début + 366 jours', '') AS 'Ressource', '' AS 'Duree de maintenance en heures', '' AS 'Duree en jours' UNION ALL SELECT resource.name AS 'Ressource', SUM(TIMESTAMPDIFF(HOUR,booking.start_date, booking.end_date)), SUM(TIMESTAMPDIFF(DAY,booking.start_date, booking.end_date)) FROM booking LEFT JOIN booking_activity_type ON booking.id=booking_activity_type.booking_id LEFT JOIN activity_type ON activity_type.id=booking_activity_type.activity_type_id LEFT JOIN booking_resource ON booking.id=booking_resource.booking_id LEFT JOIN resource ON resource.id = booking_resource.resource_id LEFT JOIN log ON log.field_value=booking.id LEFT JOIN journal ON journal.id=log.journal_id WHERE activity_type.name='Maintenance' AND (log.action='INSERT') AND (log.table_name='booking') AND (log.field_name='id') AND (booking.start_date >= $startDate) AND (booking.start_date <= LEAST($startDate + INTERVAL 366 DAY, $endDate)) GROUP BY resource.id ORDER BY 1
Maintenance hours per resource on a period
Following extrafields are needed :
- startDate (Type : Date)
- endDate (Type : Date or DateTime)
SELECT IF(LEAST($startDate + INTERVAL 366 DAY, $endDate) <> $endDate, ' Attention la date de fin retenue correspond à la date de début + 366 jours', '') AS 'Ressource', '' AS 'Date debut maintenance', '' AS 'Date fin maintenance', '' AS 'Duree de maintenance en heures', '' AS 'Duree en jours' UNION ALL SELECT resource.name, booking.start_date AS 'Date debut maintenance', booking.end_date, TIMESTAMPDIFF(HOUR,booking.start_date, booking.end_date), TIMESTAMPDIFF(DAY,booking.start_date, booking.end_date) FROM booking LEFT JOIN booking_activity_type ON booking.id=booking_activity_type.booking_id LEFT JOIN activity_type ON activity_type.id=booking_activity_type.activity_type_id LEFT JOIN booking_resource ON booking.id=booking_resource.booking_id LEFT JOIN resource ON resource.id = booking_resource.resource_id LEFT JOIN log ON log.field_value=booking.id LEFT JOIN journal ON journal.id=log.journal_id WHERE activity_type.name='Maintenance' AND (log.action='INSERT') AND (log.TABLE_NAME='booking') AND (log.field_name='id') AND (booking.start_date >= $startDate) AND (booking.start_date <= LEAST($startDate + INTERVAL 366 DAY, $endDate)) ORDER BY 1, 2
Booking for maintenance ordered by resource and date with name of the responsible
SELECT resource.name AS 'Resource name', booking.start_date AS 'Start date', TIMESTAMPDIFF(HOUR,booking.start_date, booking.end_date) AS 'booking duration', person.first_name AS 'First name', person.last_name AS 'Last name' FROM booking LEFT JOIN booking_activity_type ON booking.id=booking_activity_type.booking_id LEFT JOIN activity_type ON activity_type.id=booking_activity_type.activity_type_id LEFT JOIN booking_resource ON booking.id=booking_resource.booking_id LEFT JOIN resource ON resource.id = booking_resource.resource_id LEFT JOIN log ON log.field_value=booking.id LEFT JOIN journal ON journal.id=log.journal_id LEFT JOIN person ON person.name=journal.login WHERE activity_type.name='Maintenance' AND (log.action='INSERT') AND (log.TABLE_NAME='booking') AND (log.field_name='id') AND YEAR(booking.start_date) = $year AND person.activated=1 ORDER BY resource.name, booking.start_date
Flight time management
Flight hours total and last recorded counters to the date X
- Variable $endDate should be of Datetime value type.
SELECT resource.name, sexa2HoursMinute( SUM(duration) + aircraft.ref_hours ) AS 'Total heures', sexa2HoursMinute( MAX(counter_arrival) ) AS 'Dernier compteur' FROM flight LEFT JOIN resource ON (resource.id=flight.aircraft_id) LEFT JOIN aircraft ON (aircraft.id=resource.id) WHERE flight.start_date <= $endDate AND resource.activated=1 GROUP BY resource.id ORDER BY resource.name
Flight hours per month
SELECT MONTH( start_date) AS months, CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) AS Total FROM flight LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id WHERE YEAR(start_date) = $year GROUP BY months
Flight hours total over a 12 months period
SELECT CONCAT(last_name,' ',first_name) AS 'Person', IF (( SELECT COUNT(*) FROM flight_pilot fp2 WHERE fp2.flight_id=fp.flight_id AND fp2.num=1)=0, 'Solo', 'double') AS Solo_DC, CONCAT(FLOOR(SUM( flight.duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( flight.duration )/600 - FLOOR(SUM( flight.duration )/600))*3600),'%i')) AS Total FROM flight_pilot fp LEFT JOIN flight ON fp.flight_id=flight.id LEFT JOIN person a ON a.id=fp.pilot_id WHERE start_date > DATE_SUB(NOW(), INTERVAL 1 YEAR) AND fp.num=0 GROUP BY Person, Solo_DC
Flights hours total per aircraft per year
SELECT name AS Callsign, YEAR( start_date ) AS Year, CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) AS Total FROM flight LEFT JOIN resource ON resource.id = flight.aircraft_id WHERE YEAR(start_date) = $year AND airborne = 0 GROUP BY name UNION SELECT "Total", $year AS year, CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) AS Total FROM flight WHERE YEAR(start_date) = $year AND airborne = 0 GROUP BY year
Flights hours total per aircraft per year and per month (for an activity type)
- Variable $activityTypeId should be defined first and should be of dbOject::ActivityType value type.
- Variable $year should be defined first and should be of Year value type.
SELECT aircraft_id AS Num, resource.name, sexa2HoursMinute( SUM( IF( MONTH(start_date)=1, duration, 0 ) ) ) AS Janu, sexa2HoursMinute( SUM( IF( MONTH(start_date)=2, duration, 0 ) ) ) AS Febr, sexa2HoursMinute( SUM( IF( MONTH(start_date)=3, duration, 0 ) ) ) AS Marc, sexa2HoursMinute( SUM( IF( MONTH(start_date)=4, duration, 0 ) ) ) AS Apri, sexa2HoursMinute( SUM( IF( MONTH(start_date)=5, duration, 0 ) ) ) AS May, sexa2HoursMinute( SUM( IF( MONTH(start_date)=6, duration, 0 ) ) ) AS June, sexa2HoursMinute( SUM( IF( MONTH(start_date)=7, duration, 0 ) ) ) AS July, sexa2HoursMinute( SUM( IF( MONTH(start_date)=8, duration, 0 ) ) ) AS Augu, sexa2HoursMinute( SUM( IF( MONTH(start_date)=9, duration, 0 ) ) ) AS Sept, sexa2HoursMinute( SUM( IF( MONTH(start_date)=10, duration, 0 ) ) ) AS Octo, sexa2HoursMinute( SUM( IF( MONTH(start_date)=11, duration, 0 ) ) ) AS Nove, sexa2HoursMinute( SUM( IF( MONTH(start_date)=12, duration, 0 ) ) ) AS Dece, sexa2HoursMinute( SUM( duration ) ) AS SUM FROM flight LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id LEFT JOIN resource ON resource.id = aircraft.id WHERE YEAR(start_date)= $year AND airborne = 0 AND (flight.activity_type_id & $activityTypeId OR ''=$activityTypeId) GROUP BY resource.id UNION SELECT "Sum per","month", sexa2HoursMinute( SUM( IF( MONTH(start_date)=1, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=2, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=3, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=4, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=5, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=6, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=7, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=8, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=9, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=10, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=11, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)=12, duration, 0 ) ) ), sexa2HoursMinute( SUM( duration ) ) AS Total FROM flight LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id LEFT JOIN resource ON resource.id = aircraft.id WHERE YEAR(start_date)= $year AND airborne = 0 AND (flight.activity_type_id & $activityTypeId OR ''=$activityTypeId) UNION SELECT "Cumulative","per month", sexa2HoursMinute( SUM( IF( MONTH(start_date)<=1, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=2, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=3, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=4, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=5, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=6, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=7, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=8, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=9, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=10, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=11, duration, 0 ) ) ), sexa2HoursMinute( SUM( IF( MONTH(start_date)<=12, duration, 0 ) ) ), sexa2HoursMinute( SUM( duration ) ) AS Total FROM flight LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id LEFT JOIN resource ON resource.id = aircraft.id WHERE YEAR(start_date)= $year AND airborne = 0 AND (flight.activity_type_id & $activityTypeId OR ''=$activityTypeId)
Flight hours total per pilot
SELECT CONCAT(last_name,' ',first_name) AS Nom, sexa2HoursMinute( SUM( IFNULL( Solo.sum_duration, 0 ) ) ) AS 'Solo', sexa2HoursMinute( SUM( IFNULL( DC.sum_duration, 0 ) ) ) AS 'Double', sexa2HoursMinute( SUM( IFNULL( Solo.sum_duration, 0 ) ) + SUM( IFNULL( DC.sum_duration, 0 ) ) ) AS 'Total' FROM person LEFT JOIN ( SELECT pilot_id, IF ( (SELECT COUNT(*) FROM flight_pilot fp2 WHERE fp2.flight_id=fp.flight_id AND fp2.num=1)=0, 'Solo', 'DC' ) AS Solo_DC, SUM(flight.duration) AS sum_duration FROM flight_pilot fp LEFT JOIN flight ON fp.flight_id=flight.id WHERE flight.airborne=0 AND YEAR(start_date) = $year AND fp.num=0 GROUP BY pilot_id, Solo_DC ) AS Solo ON person.id=Solo.pilot_id AND Solo.Solo_DC='Solo' LEFT JOIN ( SELECT pilot_id, IF ( (SELECT COUNT(*) FROM flight_pilot fp2 WHERE fp2.flight_id=fp.flight_id AND fp2.num=1)=0, 'Solo', 'DC' ) AS Solo_DC, SUM(flight.duration) AS sum_duration FROM flight_pilot fp LEFT JOIN flight ON fp.flight_id=flight.id WHERE flight.airborne=0 AND YEAR(start_date) = $year AND fp.num=0 GROUP BY pilot_id, Solo_DC ) AS DC ON person.id=DC.pilot_id AND DC.Solo_DC='DC' WHERE (Solo.pilot_id IS NOT NULL OR DC.pilot_id IS NOT NULL) AND person.activated=1 GROUP BY person.id ORDER BY Nom
Flight hours total per pilot per profile
SELECT profile.name AS Profil, CONCAT(last_name,' ',first_name) AS Nom, IF (( SELECT COUNT(*) FROM flight_pilot fp2 WHERE fp2.flight_id=fp.flight_id AND fp2.num=1)=0, 'Solo', 'double') AS Solo_DC, sexa2HoursMinute( SUM( flight.duration ) ) AS Total FROM flight_pilot fp LEFT JOIN flight ON fp.flight_id=flight.id LEFT JOIN person ON person.id=fp.pilot_id LEFT JOIN profile ON (person.profile & profile.id) WHERE flight.airborne=0 AND YEAR( start_date ) = $year AND fp.num=0 GROUP BY Profil, Nom, Solo_DC
Total Flight hours per pilot with total
Following extrafields are needed
- year (Type : Year)
- month (Type : Integer) OR startDate and endDate (Type : Date)
- $occupiedSeat (Type : Integer)
- profileId (Type : dbObjectMulti::Profile)
This report is useful for a group of pilots from a common customer (like DGAC in France)
SELECT CONCAT(person.last_name,' ',person.first_name) AS _tr(FULL_NAME), CONCAT(FLOOR(SUM( flight.duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( flight.duration )/600 - FLOOR(SUM( flight.duration )/600))*3600),'%i')) AS _tr(TOTAL_FLIGHT_TIME), SUM(account_entry.debit) - SUM(account_entry.credit) AS _tr(TOTAL_AMOUNT_ACTIVITIES) FROM flight RIGHT JOIN flight_pilot ON flight_pilot.flight_id=flight.id AND (IF((($occupiedSeat=0) OR ($occupiedSeat='')), 0, -1) = flight_pilot.num OR IF((($occupiedSeat=1) OR ($occupiedSeat='')), 1, -1) = flight_pilot.num) RIGHT JOIN person ON person.id=flight_pilot.pilot_id RIGHT JOIN profile ON profile.id&person.profile AND ( profile.id IN ($profileId) OR '-' IN ($profileId) ) LEFT JOIN flight_account_entry ON flight_account_entry.flight_id = flight.id LEFT JOIN account_entry ON account_entry.flow_id = flight_account_entry.account_entry_id LEFT JOIN account ON account.id=account_entry.account_id WHERE $startDate <= flight.start_date AND flight.start_date <= $endDate AND (account.category = 11 OR account.category = 2) GROUP BY person.id
Flight hours per instructor, month (for a flight type)
Following extrafields are needed :
- year (Type : Year)
- activityTypeId (Type : dbObject::FlightType)
SELECT CONCAT(UPPER(person.last_name), ' ', person.first_name) AS _tr(LAST_NAME), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 1 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_JANUARY), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 2 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_FEBRUARY), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 3 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_MARCH), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 4 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_APRIL), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 5 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_MAY), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 6 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_JUN), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 7 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_JULY), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 8 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_AUGUST), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 9 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_SEPTEMBER), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 10 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_OCTOBER), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 11 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_NOVEMBER), (SELECT sexa2HoursMinute( SUM( duration ) ) FROM flight INNER JOIN flight_pilot ON flight_pilot.flight_id = flight.id WHERE YEAR(start_date)= $year AND MONTH(start_date)= 12 AND flight_pilot.pilot_id = person.id AND flight_pilot.num = 1 AND ( flight.activity_type_id & $activityTypeId != 0 OR ''=$activityTypeId ) ) AS _tr(MONTH_DECEMBER), sexa2HoursMinute( SUM( duration ) ) AS _tr(TOTAL) FROM flight LEFT JOIN flight_pilot fp ON fp.flight_id = flight.id LEFT JOIN person ON person.id=fp.pilot_id WHERE flight.airborne=0 AND person.activated=1 AND fp.num = 1 AND YEAR( start_date ) = $year AND ( flight.activity_type_id & $activityTypeId OR ''=$activityTypeId ) GROUP BY person.id
Flights hours following nationality
SELECT nationality.label, CONCAT(FLOOR(SUM( flight.duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( flight.duration )/600 - FLOOR(SUM( flight.duration )/600))*3600),'%i')) AS Total FROM flight , flight_pilot fp, person a, nationality WHERE flight.id = fp.flight_id AND fp.pilot_id = a.id AND a.nationality = nationality.code GROUP BY nationality.code
Flights hours total per flight type per month
SELECT activity_type.name AS Type_vol, flight_pilot_DC.DC, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 1, duration, 0 ) ) ) AS Janu, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 2, duration, 0 ) ) ) AS Febr, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 3, duration, 0 ) ) ) AS Marc, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 4, duration, 0 ) ) ) AS Apri, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 5, duration, 0 ) ) ) AS May, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 6, duration, 0 ) ) ) AS June, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 7, duration, 0 ) ) ) AS July, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 8, duration, 0 ) ) ) AS Augu, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 9, duration, 0 ) ) ) AS Sept, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 10, duration, 0 ) ) ) AS Octo, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 11, duration, 0 ) ) ) AS Nove, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 12, duration, 0 ) ) ) AS Dece, sexa2HoursMinute( SUM( duration ) ) AS Total FROM flight LEFT JOIN activity_type ON activity_type.id & flight.activity_type_id LEFT JOIN ( SELECT flight_id, IF( MAX(num) = 1, 'Double', 'Solo' ) AS DC FROM flight_pilot WHERE flight_pilot.num <= 1 GROUP BY flight_id ) AS flight_pilot_DC ON flight.id=flight_pilot_DC.flight_id WHERE YEAR(start_date) = $year AND airborne = 0 GROUP BY activity_type.id, flight_pilot_DC.DC HAVING (Name <> 'Instruction' OR flight_pilot_DC.DC <> 'Double') ORDER BY order_num ASC, DC DESC
Flights hours : less than 21 years, more than 21 years, male, female, for a given profile
- Variable $profileId should be defined first and should be of dbOjectMulti::Profile value type.
- Variable $year should be defined first and should be of Year value type.
SELECT Sex, Young, Instruction, sexa2HoursMinute(SUM(IF(category=1, duration, 0))) AS 'Avion', sexa2HoursMinute(SUM(IF(category=18, duration, 0))) AS 'Hélicoptère', sexa2HoursMinute(SUM(IF(category=19, duration, 0))) AS 'Planeur', sexa2HoursMinute(SUM(IF(category=17, duration, 0))) AS 'ULM' FROM ( SELECT IF( person.sex=0, 'Male', IF( person.sex=1, 'Female', 'Undefined') ) AS 'Sex', IF( ( $year - YEAR( birthdate ) >= 21) , 'No', 'Yes') AS Young, IF ((SELECT COUNT(*) FROM flight_pilot fp2 WHERE fp2.flight_id=fp.flight_id AND fp2.num=1)=0, 'Solo', 'Instruction') AS Instruction, flight.duration, resource_type.category FROM flight_pilot fp LEFT JOIN flight ON fp.flight_id=flight.id LEFT JOIN person ON person.id=fp.pilot_id LEFT JOIN profile ON person.profile&profile.id LEFT JOIN resource ON (resource.id=flight.aircraft_id) LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id) WHERE YEAR( start_date )=$year AND fp.num=0 AND flight.airborne = 0 AND ( profile.id IN ($profileId) OR '-' IN ($profileId) ) AND person.activated=1 GROUP BY flight.id ) AS tmp_stat GROUP BY Sex, Young, Instruction WITH ROLLUP
Computation of flight time per month of "local flight"
"Local flight" is defined as a flight less than 1h30 and with the same departure and destination
SELECT flight.aircraft_id AS Num, name AS Immat, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 1 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Janv, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 2 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Fevr, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 3 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Mars, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 4 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Avri, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 5 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Mai, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 6 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Juin, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 7 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Juil, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 8 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Aout, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 9 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Sept, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 10 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Octo, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 11 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Nove, ( SELECT CONCAT( FLOOR(SUM(flight.duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) FROM flight WHERE YEAR(flight.start_date) = $year AND MONTH(flight.start_date) = 12 AND flight.aircraft_id = Num AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 ) AS Dece, CONCAT( FLOOR(SUM(duration) / 600), ':', TIME_FORMAT( SEC_TO_TIME( ( SUM(flight.duration) / 600 - FLOOR(SUM(flight.duration) / 600) ) * 3600 ), '%i' ) ) AS Total FROM flight LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id LEFT JOIN resource ON resource.id = aircraft.id WHERE YEAR(flight.start_date) = $year AND flight.departure_icao_id = flight.arrival_icao_id AND flight.duration < 90 * 600 GROUP BY resource.id
Computation of non-"local flight" time per month
SELECT aircraft_id AS Num, name AS Immat, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 1 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Janv, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 2 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Fevr, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 3 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Mars, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 4 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Avri, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 5 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Mai, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 6 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Juin, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 7 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Juil, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 8 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Aout, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 9 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Sept, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 10 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Octo, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 11 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Nove, (SELECT CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) FROM flight WHERE YEAR(start_date)= $year AND MONTH(start_date)= 12 AND aircraft_id = Num AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id)) AS Dece, CONCAT(FLOOR(SUM( duration )/600),':',TIME_FORMAT(SEC_TO_TIME((SUM( duration )/600 - FLOOR(SUM( duration )/600))*3600),'%i')) AS Total FROM flight LEFT JOIN aircraft ON aircraft.id = flight.aircraft_id LEFT JOIN resource ON resource.id = aircraft.id WHERE YEAR(start_date)= $year AND ((departure_location_id = arrival_location_id AND duration >= 90*600) OR departure_location_id <> arrival_location_id) GROUP BY resource.id
Stats all flight hours per month per year
SELECT YEAR(start_date) AS Year, 'Monthly' AS Type, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 1, duration, 0 ) ) ) AS Janu, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 2, duration, 0 ) ) ) AS Febr, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 3, duration, 0 ) ) ) AS Marc, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 4, duration, 0 ) ) ) AS Apri, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 5, duration, 0 ) ) ) AS May, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 6, duration, 0 ) ) ) AS June, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 7, duration, 0 ) ) ) AS July, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 8, duration, 0 ) ) ) AS Augu, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 9, duration, 0 ) ) ) AS Sept, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 10, duration, 0 ) ) ) AS Octo, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 11, duration, 0 ) ) ) AS Nove, sexa2HoursMinute( SUM( IF( MONTH(start_date) = 12, duration, 0 ) ) ) AS Dece, sexa2HoursMinute( SUM( duration ) ) AS Total FROM flight LEFT JOIN resource ON resource.id = flight.aircraft_id GROUP BY Year UNION SELECT YEAR(start_date) AS Year, 'Accumulation' AS Type, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 1, duration, 0 ) ) ) AS Janu, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 2, duration, 0 ) ) ) AS Febr, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 3, duration, 0 ) ) ) AS Marc, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 4, duration, 0 ) ) ) AS Apri, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 5, duration, 0 ) ) ) AS May, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 6, duration, 0 ) ) ) AS June, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 7, duration, 0 ) ) ) AS July, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 8, duration, 0 ) ) ) AS Augu, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 9, duration, 0 ) ) ) AS Sept, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 10, duration, 0 ) ) ) AS Octo, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 11, duration, 0 ) ) ) AS Nove, sexa2HoursMinute( SUM( IF( MONTH(start_date) <= 12, duration, 0 ) ) ) AS Dece, sexa2HoursMinute( SUM( duration ) ) AS Total FROM flight LEFT JOIN resource ON resource.id = flight.aircraft_id GROUP BY Year ORDER BY Type DESC, Year
Flight hours per activity type between date
- Variable $startDate should be defined first and should be of Date and time value type.
- Variable $endDate should be defined first and should be of Date and time value type.
[OF_DYNAMIC_SQL] SELECT CONCAT( 'SELECT resource.name AS _tr(RESOURCE_NAME), ', GROUP_CONCAT( CONCAT( 'sexa2HoursMinute( SUM( IF( tmp_flight.activity_type_id & ', activity_type.id, ', tmp_flight.duration, 0 ) ) )', ' AS ', QUOTE(activity_type.name) ) ), ', sexa2HoursMinute( SUM( tmp_flight.duration ) ) AS _tr(ALL_ACTIVITY_TYPES) FROM resource INNER JOIN ( SELECT flight.aircraft_id, flight.activity_type_id, duration FROM flight WHERE flight.start_date >= $startDate AND flight.start_date <= $endDate AND flight.airborne = 0 ) AS tmp_flight ON (resource.id=tmp_flight.aircraft_id) GROUP BY resource.id' ) FROM activity_type WHERE activity_type.activated=1
Flight reports
Activities summary for a person on the right place for a given month
Requirement:
- Variable $year of Year value type
- Variable $month of Month value type
- Variable $personId of dbOjectMulti::Person value type
SELECT $month AS Mois, CONCAT(left_person.last_name, ' ', left_person.first_name) AS 'Personne en première place', activity_type.name AS 'Type d\'activité', sexa2HoursMinute( SUM( IFNULL(duration, 0) ) ) AS 'Durée' FROM flight LEFT JOIN activity_type ON (flight.activity_type_id & activity_type.id) LEFT JOIN flight_pilot AS left_place ON (flight.id=left_place.flight_id AND left_place.num=0) LEFT JOIN person AS left_person ON (left_place.pilot_id=left_person.id) LEFT JOIN flight_pilot AS right_place ON (flight.id=right_place.flight_id AND right_place.num=1) WHERE YEAR(flight.start_date)=$year AND MONTH(flight.start_date)=$month AND (right_place.pilot_id=$personId OR '-'=right_place.pilot_id='$personId') GROUP BY left_person.id, activity_type.id ORDER BY left_person.last_name, left_person.first_name, activity_type.name
Aircraft(s) which no flight were done for at least 30 day(s)
SELECT resource.id, resource.name FROM flight LEFT JOIN resource ON resource.id = flight.aircraft_id WHERE start_date < ( NOW() - INTERVAL 30 DAY ) AND physical=1 AND activated=1 GROUP BY resource.id
Flight between two dates
Following variables are needed:
- startDate (Type : Datetime)
- endDate (Type : Datetime)
[OF_DYNAMIC_SQL] SELECT CONCAT( 'SELECT flight.id AS _tr(ID), IF(flight.validated=1, _tr(YES), _tr(NO)) AS _tr(VALIDATED), flight.start_date AS _tr(START_DATE), resource.name AS _tr(RESOURCE), ( SELECT CONCAT(UPPER(tmp_person.last_name), \' \', tmp_person.first_name) FROM flight_pilot AS tmp_flight_pilot LEFT JOIN person AS tmp_person ON tmp_flight_pilot.pilot_id = tmp_person.id WHERE tmp_flight_pilot.flight_id = flight.id AND tmp_flight_pilot.num = 0 ) AS _tr(LEFT_PLACE), ( SELECT CONCAT(UPPER(tmp_person.last_name), \' \', tmp_person.first_name) FROM flight_pilot AS tmp_flight_pilot LEFT JOIN person AS tmp_person ON tmp_flight_pilot.pilot_id = tmp_person.id WHERE tmp_flight_pilot.flight_id = flight.id AND tmp_flight_pilot.num = 1 ) AS _tr(RIGHT_PLACE), ( SELECT GROUP_CONCAT( activity_type.name SEPARATOR \', \') FROM flight AS tmp_flight LEFT JOIN activity_type ON (tmp_flight.activity_type_id & activity_type.id) WHERE flight.id=tmp_flight.id ) AS _tr(ACTIVITY_TYPE), ( SELECT location.name FROM location WHERE location.icao_name=flight.departure_icao_id ) AS _tr(DEPARTURE), ( SELECT location.name FROM location WHERE location.icao_name=flight.arrival_icao_id ) AS _tr(ARRIVAL), flight.landing_number AS _tr(FLIGHT_LANDING_NUMBER), flight.people_onboard AS _tr(FLIGHT_PEOPLE_ON_BOARD), sexa2HoursMinute(flight.counter_departure) AS _tr(FLIGHT_COUNTER_DEPARTURE), sexa2HoursMinute(flight.counter_arrival) AS _tr(FLIGHT_COUNTER_ARRIVAL), sexa2HoursMinute(flight.duration) AS _tr(DURATION_IN_HOURS_AND_MINUTES), sexa2HoursHundredths(flight.duration) AS _tr(DURATION_IN_HOURS_AND_HUNDREDTHS),', IFNULL(GROUP_CONCAT( CONCAT( IF(business_field.value_type LIKE ('dbObject::Person%'), ' (SELECT CONCAT (UPPER(tmp_person.last_name), \' \', tmp_person.first_name) FROM business_field_content RIGHT JOIN business_field ON (business_field.id=business_field_content.business_field_id) RIGHT JOIN person AS tmp_person ON (tmp_person.id=business_field_content.content) WHERE business_field_content.category_id=flight.id AND business_field_content.business_field_id=', ' (SELECT GROUP_CONCAT(business_field_content.content SEPARATOR \', \') FROM business_field_content RIGHT JOIN business_field ON (business_field.id=business_field_content.business_field_id) WHERE business_field_content.category_id=flight.id AND business_field_content.business_field_id='), business_field.id, ') AS \'', REPLACE(business_field.label, '\'', '\\\''), '\'' ) ), '\'_\''), ',( SELECT SUM(account_entry.debit) - SUM(account_entry.credit) FROM account_entry RIGHT JOIN account ON (account.id=account_entry.account_id AND (account.category = 11 OR account.category = 2)) WHERE account_entry.flow_id = flight_account_entry.account_entry_id ) AS _tr(AMOUNT) FROM flight LEFT JOIN resource ON resource.id = flight.aircraft_id LEFT JOIN flight_account_entry ON flight_account_entry.flight_id = flight.id WHERE flight.start_date >= $startDate AND flight.start_date <= $endDate ORDER BY flight.start_date; ' ) FROM business_field WHERE business_field.category='FLIGHT'
Flight log book
SELECT DATE_FORMAT(start_date, '%d/%m/%Y %H:%i') AS _tr(START_DATE), resource.name AS _tr(RESOURCE), CONCAT(last_name, ' ', first_name) AS _tr(LEFT_PLACE), ( SELECT CONCAT(person.last_name, ' ', person.first_name) AS _tr(RIGHT_PLACE) FROM flight_pilot AS tmp2_flight_pilot LEFT JOIN person ON person.id=tmp2_flight_pilot.pilot_id WHERE tmp2_flight_pilot.flight_id=flight_pilot.flight_id AND tmp2_flight_pilot.num=1 ) AS _tr(RIGHT_PLACE), IF ( (SELECT COUNT(*) FROM flight_pilot AS tmp_flight_pilot WHERE tmp_flight_pilot.flight_id=flight_pilot.flight_id AND tmp_flight_pilot.num=1)=0, 'S', 'D' ) AS 'Solo / DC', sexa2HoursMinute(flight.duration) AS _tr(DURATION), ( SELECT GROUP_CONCAT( activity_type.name SEPARATOR ', ') FROM flight AS tmp_flight LEFT JOIN activity_type ON (tmp_flight.activity_type_id & activity_type.id) WHERE tmp_flight.id=flight.id ) AS _tr(ACTIVITY_TYPE), flight.departure_icao_id AS _tr(DEPARTURE), flight.arrival_icao_id AS _tr(ARRIVAL), flight.landing_number AS _tr(FLIGHT_LANDING_NUMBER), flight.people_onboard AS _tr(FLIGHT_PEOPLE_ON_BOARD), business_field_comment.content AS _tr(COMMENT) FROM flight_pilot LEFT JOIN flight ON flight_pilot.flight_id=flight.id LEFT JOIN activity_type ON (activity_type.id & flight.activity_type_id) LEFT JOIN person ON person.id=flight_pilot.pilot_id LEFT JOIN resource ON resource.id = flight.aircraft_id LEFT JOIN ( SELECT business_field_content.category_id, business_field_content.content FROM business_field_content LEFT JOIN business_field ON (business_field.id=business_field_content.business_field_id) WHERE business_field.variable='activityComment' ) AS business_field_comment ON (business_field_comment.category_id=flight.id) WHERE YEAR( start_date ) = $year AND flight_pilot.num=0 AND flight.airborne=0 GROUP BY flight.id ORDER BY CONCAT(last_name, ' ', first_name), start_date
Flights which have landed elsewhere than the base field
Variable $icao shall be defined (dbObject:Location)
SELECT DATE_FORMAT(flight.start_date, '%d/%m/%Y') AS Date, resource.name AS Immatriculation, CONCAT(FLOOR( duration/600),':',TIME_FORMAT(SEC_TO_TIME((duration/600 - FLOOR(duration/600))*3600),'%i')) AS Durée, person.last_name AS Nom, person.first_name AS Prénom, flight.departure_icao_id AS Départ, flight.arrival_icao_id AS Arrivée FROM flight LEFT JOIN resource ON resource.id = flight.aircraft_id LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id LEFT JOIN person ON person.id = flight_pilot.pilot_id WHERE flight_pilot.num = 0 AND( flight.departure_icao_id LIKE $icao OR flight.arrival_icao_id LIKE $icao ) GROUP BY flight.id
Flights with mechanic remark
Following variables are needed:
- Business field $maintenanceUserComment should be defined first and should be of Text multi line value type and Flight category.
- Business field $mechanicAnswer should be defined first and should be of Text multi line value type and Flight category.
- Business field $resourceId should be defined first and should be of dbObject::Resource value type and Report category.
- Business field $numberMonth should be defined first and should be of integer value type and Report category.
SELECT CONCAT( '[LINK=index.php[QUESTION_MARK]menuAction=flight_record&menuParameter=', flight.id, '&menuParameterBis=flight_resource_logbook&menuParameter3=1]', flight.start_date, '[/LINK]' ) AS _tr(DATE), resource.name AS _tr(RESOURCE), sexa2HoursMinute(flight.duration) AS _tr(DURATION), person.last_name AS Nom, person.first_name AS _tr(FIRST_NAME), departure_location.icao_name AS _tr(DEPARTURE), arrival_location.icao_name AS _tr(ARRIVAL), maintenanceUserComment.content AS _tr(REMARK), mechanicAnswer.content AS _tr(ANSWER) FROM flight LEFT JOIN resource ON resource.id = flight.aircraft_id LEFT JOIN flight_pilot ON flight_pilot.flight_id = flight.id LEFT JOIN person ON person.id = flight_pilot.pilot_id LEFT JOIN location AS departure_location ON departure_location.icao_name = flight.departure_icao_id LEFT JOIN location AS arrival_location ON arrival_location.icao_name = flight.arrival_icao_id LEFT JOIN business_field_content AS maintenanceUserComment ON maintenanceUserComment.category_id = flight.id LEFT JOIN business_field_content AS mechanicAnswer ON mechanicAnswer.category_id = flight.id WHERE flight_pilot.num = 0 AND maintenanceUserComment.business_field_id =( SELECT business_field.id FROM business_field WHERE ( business_field.variable = "maintenanceUserComment" ) ) AND mechanicAnswer.business_field_id =( SELECT business_field.id FROM business_field WHERE ( business_field.variable = "mechanicAnswer" ) ) AND ( maintenanceUserComment.content <> "" OR mechanicAnswer.content <> "" ) AND start_date > DATE_SUB( NOW(), INTERVAL $numberMonth MONTH) AND ( (resource.id = $resourceId) OR($resourceId < '1') ) GROUP BY flight.id ORDER BY resource.name, start_date DESC
Flight with their location code (ICAO)
SELECT flight.* FROM flight
Flight hours total per person
Following variables are needed:
- Variable $endDate of Date and time value type.
- Variable $startDate of Date and time value type.
SELECT CONCAT(person.last_name,' ',person.first_name) AS _tr(LAST_NAME), sexa2HoursMinute( SUM( IFNULL( Solo.sum_duration, 0 ) ) ) AS _tr(ALONE), sexa2HoursMinute( SUM( IFNULL( DC.sum_duration, 0 ) ) ) AS _tr(LEGEND_INSTRUCTION), sexa2HoursMinute( SUM( IFNULL( Solo.sum_duration, 0 ) ) + SUM( IFNULL( DC.sum_duration, 0 ) ) ) AS _tr(TOTAL) FROM person LEFT JOIN ( SELECT pilot_id, IF ( (SELECT COUNT(*) FROM flight_pilot flight_pilot_2 WHERE flight_pilot_2.flight_id=flight_pilot_1.flight_id AND flight_pilot_2.num=1)=0, 'Solo', 'DC' ) AS Solo_DC, SUM(flight.duration) AS sum_duration FROM flight_pilot flight_pilot_1 LEFT JOIN flight ON flight_pilot_1.flight_id=flight.id WHERE flight.airborne=0 AND flight.start_date >= $startDate AND flight.start_date <= $endDate AND flight_pilot_1.num=0 GROUP BY pilot_id, Solo_DC ) AS Solo ON person.id=Solo.pilot_id AND Solo.Solo_DC='Solo' LEFT JOIN ( SELECT pilot_id, IF ( (SELECT COUNT(*) FROM flight_pilot flight_pilot_2 WHERE flight_pilot_2.flight_id=flight_pilot_1.flight_id AND flight_pilot_2.num=1)=0, 'Solo', 'DC' ) AS Solo_DC, SUM(flight.duration) AS sum_duration FROM flight_pilot flight_pilot_1 LEFT JOIN flight ON flight_pilot_1.flight_id=flight.id WHERE flight.airborne=0 AND flight.start_date >= $startDate AND flight.start_date <= $endDate AND flight_pilot_1.num=0 GROUP BY pilot_id, Solo_DC ) AS DC ON person.id=DC.pilot_id AND DC.Solo_DC='DC' WHERE (Solo.pilot_id IS NOT