Diversen nav opmerkingen
This commit is contained in:
@@ -15,4 +15,48 @@ class Employeetarget extends BaseModel {
|
||||
return $this->belongsTo( 'User' );
|
||||
}
|
||||
|
||||
public static function saveTarget( $targetID, $target )
|
||||
{
|
||||
$target = (array) $target;
|
||||
|
||||
if ( $targetID == 0 )
|
||||
{
|
||||
$target = self::create( $target );
|
||||
$targetID = $target['id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
self::whereId( $targetID )->update( $target );
|
||||
}
|
||||
|
||||
return $targetID;
|
||||
}
|
||||
|
||||
public static function getTargetHoursPerEmployee( $employeeID, $year, $monthID )
|
||||
{
|
||||
$months = $monthID == 0 ? [1,2,3,4,5,6,7,8,9,10,11,12] : [$monthID];
|
||||
|
||||
$targetHours = 0;
|
||||
|
||||
foreach($months as $month)
|
||||
{
|
||||
$targetHours += self::getCurrentMonthTarget( $employeeID, $year, $month);
|
||||
}
|
||||
|
||||
return $targetHours;
|
||||
}
|
||||
|
||||
public static function getCurrentMonthTarget( $employeeID, $year, $month )
|
||||
{
|
||||
$monthTarget = Self::whereUserId($employeeID)
|
||||
->where('startyear', '<=', $year)
|
||||
->where('startmonth', '<=', $month)
|
||||
->orderBy('startyear', 'DESC')
|
||||
->orderBy('startmonth', 'DESC');
|
||||
|
||||
if( $monthTarget->count() == 0 ) return 0;
|
||||
|
||||
return $monthTarget->first()->target;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,12 +14,12 @@ class QEmployeeHours {
|
||||
SELECT monthID,
|
||||
user_id,
|
||||
CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname,
|
||||
SUM(projecthours) AS projecthours,
|
||||
SUM(profitablehours) AS profitablehours,
|
||||
SUM(nonprofitablehours) AS nonprofitablehours,
|
||||
SUM(revenues) AS revenues,
|
||||
SUM(nonprojecthours) AS nonprojecthours,
|
||||
SUM(projecthours + nonprojecthours) AS totalhours,
|
||||
ROUND(SUM(projecthours), 0) AS projecthours,
|
||||
ROUND(SUM(profitablehours), 0) AS profitablehours,
|
||||
ROUND(SUM(nonprofitablehours), 0) AS nonprofitablehours,
|
||||
ROUND(SUM(revenues), 0) AS revenues,
|
||||
ROUND(SUM(nonprojecthours), 0) AS nonprojecthours,
|
||||
ROUND(SUM(projecthours + nonprojecthours), 0) AS totalhours,
|
||||
targethours
|
||||
FROM (
|
||||
SELECT employee_id AS user_id,
|
||||
|
||||
@@ -10,31 +10,47 @@ class ReservationTotals {
|
||||
|
||||
public static function fire()
|
||||
{
|
||||
$sql = "SELECT projectID, externalID, reservation, payed, (reservation - payed) AS saldo, PRJ.projectnumber, EXT.contactperson
|
||||
// UNION ALL wordt gebruikt voor een full outer join
|
||||
$sql = "SELECT Q5.project_id AS projectID, external_id AS externalID,
|
||||
costs, reservation, payed, (reservation - payed) AS saldo,
|
||||
(costs - payed) AS saldoToPay, PRJ.projectnumber, EXT.contactperson,
|
||||
ROUND(( (other_revenue * (100 + (SELECT vatrate from vats where active='T' LIMIT 1))) / 100 ), 0) other_revenue
|
||||
FROM (
|
||||
SELECT COALESCE(RES.project_id, PRC.project_id) AS projectID,
|
||||
COALESCE(RES.external_id, PRC.external_id) AS externalID,
|
||||
SUM(COALESCE(reservationamount, 0)) AS reservation,
|
||||
SUM(COALESCE(payed, 0)) AS payed
|
||||
FROM reservations RES
|
||||
LEFT JOIN projectcosts PRC
|
||||
ON RES.project_id = PRC.project_id AND RES.external_id = PRC.external_id
|
||||
GROUP BY COALESCE(RES.project_id, PRC.project_id), COALESCE(PRC.external_id, PRC.external_id)
|
||||
SELECT COALESCE(reservation, 0) AS reservation, costs, payed, Q2.external_id, Q2.project_id
|
||||
FROM (
|
||||
SELECT SUM(reservationamount) AS reservation, external_id, project_id
|
||||
FROM reservations
|
||||
GROUP BY external_id, project_id
|
||||
) Q1
|
||||
RIGHT JOIN
|
||||
(
|
||||
SELECT SUM(costs) AS costs, SUM(payed) AS payed, external_id, project_id
|
||||
FROM projectcosts
|
||||
GROUP BY external_id, project_id
|
||||
) Q2
|
||||
ON Q1.external_id = Q2.external_id AND Q1.project_id = Q2.project_id
|
||||
UNION ALL
|
||||
SELECT COALESCE(RES.project_id, PRC.project_id) AS projectID,
|
||||
COALESCE(RES.external_id, PRC.external_id) AS externalID,
|
||||
SUM(COALESCE(reservationamount, 0)) AS reservation,
|
||||
SUM(COALESCE(payed, 0)) AS payed
|
||||
FROM reservations RES
|
||||
RIGHT JOIN projectcosts PRC
|
||||
ON RES.project_id = PRC.project_id AND RES.external_id = PRC.external_id
|
||||
WHERE RES.id IS NULL
|
||||
GROUP BY COALESCE(RES.project_id, PRC.project_id), COALESCE(RES.external_id, PRC.external_id)
|
||||
) Q3
|
||||
SELECT reservation, COALESCE(costs, 0), COALESCE(payed, 0), Q3.external_id, Q3.project_id
|
||||
FROM (
|
||||
SELECT SUM(reservationamount) AS reservation, external_id, project_id
|
||||
FROM reservations
|
||||
GROUP BY external_id, project_id
|
||||
) Q3
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT SUM(costs) AS costs, SUM(payed) AS payed, external_id, project_id, id
|
||||
FROM projectcosts
|
||||
GROUP BY external_id, project_id
|
||||
) Q4
|
||||
ON Q3.external_id = Q4.external_id AND Q3.project_id = Q4.project_id
|
||||
WHERE Q4.id IS NULL
|
||||
) Q5
|
||||
JOIN projects PRJ
|
||||
ON PRJ.id = Q3.projectID
|
||||
ON PRJ.id = Q5.project_id
|
||||
JOIN externals EXT
|
||||
ON EXT.id = Q3.externalID ";
|
||||
ON EXT.id = Q5.external_id
|
||||
JOIN offers OFF
|
||||
ON PRJ.id = OFF.project_id ";
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user