Reservations
This commit is contained in:
@@ -11,6 +11,11 @@ class External extends BaseModel {
|
||||
|
||||
protected $table = "externals";
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->hasMany( 'Reservation' );
|
||||
}
|
||||
|
||||
public static function getAllExternals( $archive )
|
||||
{
|
||||
$externals = External::orderBy( 'name' );
|
||||
@@ -24,24 +29,24 @@ class External extends BaseModel {
|
||||
|
||||
public static function saveExternal( $externalID, $external )
|
||||
{
|
||||
$external = (array)$external;
|
||||
$external = (array) $external;
|
||||
|
||||
if( $externalID == 0)
|
||||
if ( $externalID == 0 )
|
||||
{
|
||||
$external = External::create($external);
|
||||
$external = External::create( $external );
|
||||
$externalID = $external['id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
External::whereId($externalID)->update($external);
|
||||
External::whereId( $externalID )->update( $external );
|
||||
}
|
||||
|
||||
return $externalID;
|
||||
}
|
||||
|
||||
public static function removeExternal($externalID)
|
||||
public static function removeExternal( $externalID )
|
||||
{
|
||||
External::whereId($externalID)->delete();
|
||||
External::whereId( $externalID )->delete();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ class Reservation extends BaseModel {
|
||||
return $this->belongsTo( 'Project' );
|
||||
}
|
||||
|
||||
public function external()
|
||||
{
|
||||
return $this->belongsTo( 'External' );
|
||||
}
|
||||
|
||||
public static function saveReservation( $reservationID, $reservation )
|
||||
{
|
||||
$reservation = (array) $reservation;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 13/04/2018
|
||||
* Time: 14:27
|
||||
*/
|
||||
|
||||
class ReservationTotals {
|
||||
|
||||
public static function fire()
|
||||
{
|
||||
$sql = "SELECT projectID, externalID, reservation, payed, (reservation - payed) AS saldo, PRJ.projectnumber, EXT.contactperson
|
||||
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)
|
||||
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
|
||||
JOIN projects PRJ
|
||||
ON PRJ.id = Q3.projectID
|
||||
JOIN externals EXT
|
||||
ON EXT.id = Q3.externalID ";
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user