Diversen opmerkingen Peter (23-08-2019)

This commit is contained in:
2019-09-12 20:16:57 +02:00
parent f5b815d34d
commit b49fb957a3
17 changed files with 1194 additions and 1094 deletions
+69 -55
View File
@@ -9,76 +9,90 @@
class Offer extends BaseModel {
protected $table = "offers";
protected $table = "offers";
public function payments()
{
return $this->hasMany( 'Payment' );
}
public function payments()
{
return $this->hasMany( 'Payment' );
}
public function project()
{
return $this->belongsTo( 'Project' );
}
public function project()
{
return $this->belongsTo( 'Project' );
}
public function customer()
{
return $this->belongsTo( 'Customer' );
}
public function customer()
{
return $this->belongsTo( 'Customer' );
}
public static function getAllOffers( $projectID, $archive = 'F', $search, $order, $direction )
{
$offers = Offer::selectRAW('offers.*')
->join('customers AS CUS', 'CUS.id', '=', 'offers.customer_id')
->with( 'customer' )
->with( 'project' )
->where('offernumber', 'LIKE', "%{$search}%")
->orderBy($order, $direction);
public static function getAllOffers( $projectID, $archive = 'F', $search, $order, $direction )
{
$offers = Offer::selectRAW( 'offers.*' )
->join( 'customers AS CUS', 'CUS.id', '=', 'offers.customer_id' )
->with( 'customer' )
->with( 'project' )
->where( 'offernumber', 'LIKE', "%{$search}%" )
->orderBy( $order, $direction );
if ( $projectID ) $offers = $offers->whereProjectId( $projectID );
if ( $projectID ) $offers = $offers->whereProjectId( $projectID );
if ( $archive == 'F' ) $offers = $offers->where( 'offers.archive', '=', 'F' );
if ( $archive == 'F' ) $offers = $offers->where( 'offers.archive', '=', 'F' );
$offers = $offers->get();
$offers = $offers->get();
return $offers;
}
return $offers;
}
public static function getOffersWithoutProject( )
{
$offersWithoutProject = Offer::orderBy('startdate')
public static function getOffersWithoutProject()
{
$offersWithoutProject = Offer::orderBy( 'startdate' )
// ->whereNull('rejectdate')
// ->whereNull('project_id')
->whereArchive('F')
->get();
->whereArchive( 'F' )
->get();
return $offersWithoutProject;
}
return $offersWithoutProject;
}
public static function saveOffer( $offerID, $offer )
{
$offer = (array) $offer;
public static function saveOffer( $offerID, $offer )
{
$offer = (array) $offer;
$offer['startdate'] = date2mysql( $offer['startdate'] );
$offer['accepteddate'] = date2mysql( $offer['accepteddate'] );
$offer['rejectdate'] = date2mysql( $offer['rejectdate'] );
$offer['startdate'] = date2mysql( $offer['startdate'] );
$offer['accepteddate'] = date2mysql( $offer['accepteddate'] );
$offer['rejectdate'] = date2mysql( $offer['rejectdate'] );
if ( $offerID == 0 )
{
$offer = Offer::create( $offer );
if ( $offerID == 0 )
{
$offer = Offer::create( $offer );
$offerID = $offer['id'];
}
else
{
Offer::whereId( $offerID )->update( $offer );
}
$offerID = $offer['id'];
}
else
{
Offer::whereId( $offerID )->update( $offer );
return $offerID;
}
$offer = self::find( $offerID );
public static function removeOffer( $offerID )
{
Offer::whereId( $offerID )->delete();
}
}
if ( ! is_null( $offer->project_id ) ) Project::syncOffername( $offer );
}
return $offerID;
}
public static function syncProjectname( $projectID )
{
$project = Project::find( $projectID );
$offer = self::find( $projectID );
$offer->offername = $project->projectname;
$offer->save();
}
public static function removeOffer( $offerID )
{
Offer::whereId( $offerID )->delete();
}
}
+133 -128
View File
@@ -9,169 +9,174 @@
class Project extends BaseModel {
protected $table = "projects";
protected $table = "projects";
public function offers()
{
return $this->hasMany( 'Offer' );
}
public function offers()
{
return $this->hasMany( 'Offer' );
}
public function offer()
{
return $this->hasOne( 'Offer' );
}
public function offer()
{
return $this->hasOne( 'Offer' );
}
public function projectemployees()
{
return $this->hasMany( 'Projectemployee' );
}
public function projectemployees()
{
return $this->hasMany( 'Projectemployee' );
}
public function projectcosts()
{
return $this->hasMany( 'Projectcost' );
}
public function projectcosts()
{
return $this->hasMany( 'Projectcost' );
}
public function invoices()
{
return $this->hasMany( 'Invoice' );
}
public function invoices()
{
return $this->hasMany( 'Invoice' );
}
public function forecasts()
{
return $this->hasMany( 'Forecast' );
}
public function forecasts()
{
return $this->hasMany( 'Forecast' );
}
public function reservations()
{
return $this->hasMany( 'Reservation' );
}
public function reservations()
{
return $this->hasMany( 'Reservation' );
}
public function vat()
{
return $this->belongsTo( 'Vat' );
}
public function vat()
{
return $this->belongsTo( 'Vat' );
}
public function projectleader()
{
return $this->belongsTo( 'User', 'projectleader_id' );
}
public function projectleader()
{
return $this->belongsTo( 'User', 'projectleader_id' );
}
public function customer()
{
return $this->belongsTo( 'Customer' );
}
public function customer()
{
return $this->belongsTo( 'Customer' );
}
public static function getAllProjects( $archive, $search, $order, $direction )
{
$projects = Project::getBaseProject();
public static function getAllProjects( $archive, $search, $order, $direction )
{
$projects = Project::getBaseProject();
$projects = $projects->selectRaw( 'projects.*' )
->join( 'customers AS CUS', 'CUS.id', '=', 'projects.customer_id' )
->join( 'users AS USR', 'USR.id', '=', 'projects.projectleader_id' )
->where( 'projects.projectnumber', 'LIKE', "%{$search}%" )
->orderBy( $order, $direction );
$projects = $projects->selectRaw( 'projects.*' )
->join( 'customers AS CUS', 'CUS.id', '=', 'projects.customer_id' )
->join( 'users AS USR', 'USR.id', '=', 'projects.projectleader_id' )
->where( 'projects.projectnumber', 'LIKE', "%{$search}%" )
->orderBy( $order, $direction );
if ( $archive == 'F' ) $projects = $projects->where( 'projects.archive', '=', 'F' );
if ( $archive == 'F' ) $projects = $projects->where( 'projects.archive', '=', 'F' );
$projects = $projects->get();
$projects = $projects->get();
return $projects;
}
return $projects;
}
public static function getProject( $projectID )
{
$project = Project::getBaseProject();
public static function getProject( $projectID )
{
$project = Project::getBaseProject();
$project = $project->whereArchive( 'F' )
->whereId( $projectID )
->first();
$project = $project->whereArchive( 'F' )
->whereId( $projectID )
->first();
return $project;
}
return $project;
}
public static function removeProject( $projectID )
{
Offer::whereProjectId( $projectID )->update( ['project_id' => NULL] );
public static function removeProject( $projectID )
{
Offer::whereProjectId( $projectID )->update( ['project_id' => NULL] );
Project::whereId( $projectID )->delete();
}
Project::whereId( $projectID )->delete();
}
public static function getActiveProjects($archive = 'T')
{
$projects = Project::selectRaw( "projects.id, YEAR(projects.startdate) AS instroom, YEAR(projects.enddate) AS uitstroom, projectnumber, current_financial_year,
public static function getActiveProjects( $archive = 'T' )
{
$projects = Project::selectRaw( "projects.id, YEAR(projects.startdate) AS instroom, YEAR(projects.enddate) AS uitstroom, projectnumber, current_financial_year,
projectname, CUS.name, OFF.own_revenue, OFF.other_revenue" )
->join( 'customers AS CUS', 'CUS.id', '=', 'projects.customer_id' )
->join( 'offers AS OFF', 'OFF.project_id', '=', 'projects.id' )
->groupBy( 'projects.id' )
->groupBy( 'OFF.own_revenue' )
->groupBy( 'OFF.other_revenue' );
->join( 'customers AS CUS', 'CUS.id', '=', 'projects.customer_id' )
->join( 'offers AS OFF', 'OFF.project_id', '=', 'projects.id' )
->groupBy( 'projects.id' )
->groupBy( 'OFF.own_revenue' )
->groupBy( 'OFF.other_revenue' );
if( $archive == 'F') $projects = $projects->where('projects.archive', '=', 'F');
if ( $archive == 'F' ) $projects = $projects->where( 'projects.archive', '=', 'F' );
$projects = $projects->get();
$projects = $projects->get();
return $projects;
}
return $projects;
}
public static function getProjectsForReport( $orderType, $orderDirection, $archive = 'F' )
{
$projects = self::getBaseProject();
public static function getProjectsForReport( $orderType, $orderDirection, $archive = 'F' )
{
$projects = self::getBaseProject();
if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' );
if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' );
$projects = $projects->orderBy( $orderType, $orderDirection )->get();
$projects = $projects->orderBy( $orderType, $orderDirection )->get();
return $projects;
}
return $projects;
}
public static function getBaseProject()
{
$project = Project::with( [
'projectleader' => function ( $q ) {
$q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
}] )
->with( 'offer' )
->with( [
'projectemployees.user' => function ( $q ) {
$q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
}] )
->with( 'vat' )
->with( ['forecasts'] )
->with( ['reservations'] )
->with( 'projectemployees.projecthours' )
->with( 'projectcosts.external' )
->with( 'invoices.payments' )
->with( 'invoices.vat' )
->with( 'vat' )
->with( 'customer' );
public static function getBaseProject()
{
$project = Project::with( [
'projectleader' => function ( $q ) {
$q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
}] )
->with( 'offer' )
->with( [
'projectemployees.user' => function ( $q ) {
$q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
}] )
->with( 'vat' )
->with( ['forecasts'] )
->with( ['reservations'] )
->with( 'projectemployees.projecthours' )
->with( 'projectcosts.external' )
->with( 'invoices.payments' )
->with( 'invoices.vat' )
->with( 'vat' )
->with( 'customer' );
return $project;
}
return $project;
}
public static function createProject()
{
$data = ['startdate' => date( 'Y-m-d' )];
public static function createProject()
{
$data = ['startdate' => date( 'Y-m-d' )];
$project = Project::create( $data );
$project = Project::create( $data );
return $project->id;
}
return $project->id;
}
public static function saveProject( $projectID, $project )
{
$project = (array) $project;
public static function saveProject( $projectID, $project )
{
$project = (array) $project;
if ( $projectID == 0 )
{
$project = Project::create( $project );
$projectID = $project['id'];;
}
else
{
Project::whereId( $projectID )->update( $project );
}
if ( $projectID == 0 )
{
$project = Project::create( $project );
$projectID = $project['id'];;
}
else
{
Project::whereId( $projectID )->update( $project );
}
return $projectID;
return $projectID;
}
}
}
public static function syncOffername( $offer )
{
self::whereId( $offer->project_id )
->update( ['projectname' => $offer->offername] );
}
}
+98 -85
View File
@@ -9,117 +9,130 @@
class User extends BaseModel {
protected $table = "users";
protected $table = "users";
public function projectemployees()
{
return $this->hasMany( 'Projectemployee' );
}
public function projectemployees()
{
return $this->hasMany( 'Projectemployee' );
}
public function employeetargets()
{
return $this->hasMany( 'Employeetarget' );
}
public function employeetargets()
{
return $this->hasMany( 'Employeetarget' );
}
public function projectemployee()
{
return $this->hasOne( 'Projectemployee' );
}
public function projectemployee()
{
return $this->hasOne( 'Projectemployee' );
}
public function role()
{
return $this->belongsTo( 'Role', 'level', 'rolelevel' );
}
public function role()
{
return $this->belongsTo( 'Role', 'level', 'rolelevel' );
}
public static function getAllUsers( $archive )
{
$users = User::selectRaw( "*, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" )
->orderBy( 'lastname' );
public static function getAllUsers( $archive )
{
$users = User::selectRaw( "*, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" )
->orderBy( 'lastname' );
if ( $archive == 'F' ) $users = $users->whereArchive( 'F' );
if ( $archive == 'F' ) $users = $users->whereArchive( 'F' );
$users = $users->get();
$users = $users->get();
return $users;
}
return $users;
}
public static function getUserRoleHierarchy()
{
$userrole = User::find( USERID )->role;
public static function getUserRoleHierarchy()
{
$userrole = User::find( USERID )->role;
return $userrole;
}
return $userrole;
}
public static function getUserWithprojects()
{
$usersWithProjects =
User::selectRaw( "users.id, CONCAT(users.firstname, ' ', users.middlename, ' ', users.lastname) AS fullname" )
->with( [
'projectemployees.project' => function ( $q ) {
$q->whereArchive( 'F' );
}] )
->get();
public static function getUserWithprojects()
{
$usersWithProjects =
User::selectRaw( "users.id, CONCAT(users.firstname, ' ', users.middlename, ' ', users.lastname) AS fullname" )
->with( [
'projectemployees.project' => function ( $q ) {
$q->whereArchive( 'F' );
}] )
->get();
return $usersWithProjects;
}
return $usersWithProjects;
}
public static function checkUsername( $username )
{
$username = strtoupper( $username );
public static function getUserActiveProjects( $userID )
{
$usersActiveProjects =
User::selectRaw( "PRJ.id AS projectID, projectname, projectnumber, CONCAT(projectnumber, '-', projectname) AS projectFull" )
->join( 'projectemployees AS PRE', 'PRE.user_id', '=', 'users.id' )
->join( 'projects AS PRJ', 'PRJ.id', '=', 'PRE.project_id' )
->where( 'PRJ.archive', '=', 'F' )
->where( 'users.id', '=', $userID )
->get();
$user = User::whereRaw( "UCASE(username) = {$username}" );
return $usersActiveProjects;
}
if ( $user->count() == 0 ) return FALSE;
public static function checkUsername( $username )
{
$username = strtoupper( $username );
return TRUE;
}
$user = User::whereRaw( "UCASE(username) = {$username}" );
public static function saveUser( $userID, $user )
{
$user = (array) $user;
if ( $user->count() == 0 ) return FALSE;
if ( $userID == 0 )
{
$user = User::create( $user );
$userID = $user['id'];
}
else
{
User::whereId( $userID )->update( $user );
}
return TRUE;
}
return $userID;
}
public static function saveUser( $userID, $user )
{
$user = (array) $user;
public static function removeUser( $userID )
{
User::whereId( $userID )->delete();
}
if ( $userID == 0 )
{
$user = User::create( $user );
$userID = $user['id'];
}
else
{
User::whereId( $userID )->update( $user );
}
public static function getUniqueProjectUsers()
{
//TODO: date range
$projectusers = User::selectRaw( "
return $userID;
}
public static function removeUser( $userID )
{
User::whereId( $userID )->delete();
}
public static function getUniqueProjectUsers()
{
//TODO: date range
$projectusers = User::selectRaw( "
users.id,
CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname,
SUBSTR(MD5(users.id), 1, 6) AS slug" )
->join( 'projectemployees AS PEM', 'PEM.user_id', '=', 'users.id' )
->with( [
'projectemployee.project' => function ( $q ) {
$q->selectRaw( "id, YEAR(startdate) AS instroom, COALESCE(YEAR(enddate), '') AS uitstroom" );
}] )
->distinct()
->get();
->join( 'projectemployees AS PEM', 'PEM.user_id', '=', 'users.id' )
->with( [
'projectemployee.project' => function ( $q ) {
$q->selectRaw( "id, YEAR(startdate) AS instroom, COALESCE(YEAR(enddate), '') AS uitstroom" );
}] )
->distinct()
->get();
return $projectusers;
}
return $projectusers;
}
public static function getSaltedPassword( $password, $salt )
{
$saltedpassword = sha1( sha1( $password ) . $salt );
public static function getSaltedPassword( $password, $salt )
{
$saltedpassword = sha1( sha1( $password ) . $salt );
return $saltedpassword;
}
return $saltedpassword;
}
}
}
@@ -16,10 +16,10 @@ class ReservationTotals {
Q5.costs, reservation, payed, (reservation - fromreservation) AS saldo,
(Q5.costs - payed) AS saldoToPay, PRJ.projectnumber, EXT.contactperson,
ROUND(( (OFF.costs * (100 + (SELECT vatrate
FROM vats VTS
JOIN projects P
ON VTS.id = P.vat_id
WHERE P.id = PRJ.id LIMIT 1))) / 100 ), 0) other_revenue
FROM vats VTS
JOIN projects P
ON VTS.id = P.vat_id
WHERE P.id = PRJ.id LIMIT 1))) / 100 ), 0) other_revenue
FROM (
SELECT COALESCE(reservation, 0) AS reservation, costs, payed, Q2.external_id, Q2.project_id,
IF(from_reservation = 'T', payed, 0) fromreservation