66 lines
1.4 KiB
PHP
66 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 21/12/2017
|
|
* Time: 18:05
|
|
*/
|
|
|
|
|
|
class Offer extends BaseModel {
|
|
|
|
protected $table = "offers";
|
|
|
|
public function payments()
|
|
{
|
|
return $this->hasMany( 'Payment' );
|
|
}
|
|
|
|
public function project()
|
|
{
|
|
return $this->belongsTo( 'Project' );
|
|
}
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo( 'Customer' );
|
|
}
|
|
|
|
public static function getAllOffers( $archive = 'F' )
|
|
{
|
|
$offers = Offer::orderBy( 'startdate' )
|
|
->with( 'customer' )
|
|
->with( 'project' );
|
|
|
|
if ( $archive == 'F' ) $offers = $offers->whereArchive( 'F' );
|
|
|
|
$offers = $offers->get();
|
|
|
|
return $offers;
|
|
}
|
|
|
|
public static function saveOffer( $offerID, $offer )
|
|
{
|
|
$offer = (array) $offer;
|
|
|
|
$offer['startdate'] = date2mysql( $offer['startdate'] );
|
|
$offer['accepteddate'] = date2mysql( $offer['accepteddate'] );
|
|
$offer['rejectdate'] = date2mysql( $offer['rejectdate'] );
|
|
|
|
if ( $offerID == 0 )
|
|
{
|
|
$offer = Offer::create( $offer );
|
|
}
|
|
else
|
|
{
|
|
$offer = Offer::whereId( $offerID )->update( $offer );
|
|
}
|
|
|
|
return $offer['id'];
|
|
}
|
|
|
|
public static function removeOffer( $offerID )
|
|
{
|
|
Offer::whereId( $offerID )->delete();
|
|
}
|
|
} |