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();
}
}