Skip to content

Commit

Permalink
Merge pull request #66 from yohancreemers/master
Browse files Browse the repository at this point in the history
Added method Model::userHasRights, added Address entity, expanded Contact entity
  • Loading branch information
stephangroen authored Jul 25, 2016
2 parents e68f102 + 9137332 commit 08c51b5
Show file tree
Hide file tree
Showing 3 changed files with 310 additions and 3 deletions.
128 changes: 128 additions & 0 deletions Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php namespace Picqer\Financials\Exact;

/**
* Class Address
*
* @package Picqer\Financials\Exact
* @see https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=crmAddresses
*
* @property Guid $ID Primary key
* @property Guid $Account Account linked to the address
* @property Boolean $AccountIsSupplier Indicates if the account is a supplier
* @property String $AccountName Name of the account
* @property String $AddressLine1 First address line
* @property String $AddressLine2 Second address line
* @property String $AddressLine3 Third address line
* @property String $City City
* @property Guid $Contact Contact linked to Address
* @property String $ContactName Contact name
* @property String $Country Country code
* @property String $CountryName Country name
* @property DateTime $Created Creation date
* @property Guid $Creator User ID of creator
* @property String $CreatorFullName Name of creator
* @property Int32 $Division Division code
* @property String $Fax Fax number
* @property Boolean $FreeBoolField_01 Free boolean field 1
* @property Boolean $FreeBoolField_02 Free boolean field 2
* @property Boolean $FreeBoolField_03 Free boolean field 3
* @property Boolean $FreeBoolField_04 Free boolean field 4
* @property Boolean $FreeBoolField_05 Free boolean field 5
* @property DateTime $FreeDateField_01 Free date field 1
* @property DateTime $FreeDateField_02 Free date field 2
* @property DateTime $FreeDateField_03 Free date field 3
* @property DateTime $FreeDateField_04 Free date field 4
* @property DateTime $FreeDateField_05 Free date field 5
* @property Double $FreeNumberField_01 Free number field 1
* @property Double $FreeNumberField_02 Free number field 2
* @property Double $FreeNumberField_03 Free number field 3
* @property Double $FreeNumberField_04 Free number field 4
* @property Double $FreeNumberField_05 Free number field 5
* @property String $FreeTextField_01 Free text field 1
* @property String $FreeTextField_02 Free text field 2
* @property String $FreeTextField_03 Free text field 3
* @property String $FreeTextField_04 Free text field 4
* @property String $FreeTextField_05 Free text field 5
* @property String $Mailbox Mailbox
* @property Boolean $Main Indicates if the address is the main address for this type
* @property DateTime $Modified Last modified date
* @property Guid $Modifier User ID of modifier
* @property String $ModifierFullName Name of modifier
* @property String $NicNumber Last 5 digits of SIRET number which is an intern sequential number of 4 digits representing the identification of the localization of the office
* @property String $Notes Notes for an address
* @property String $Phone Phone number
* @property String $PhoneExtension Phone extension
* @property String $Postcode Postcode
* @property String $State State
* @property String $StateDescription Name of the State
* @property Int16 $Type The type of address. Visit=1, Postal=2, Invoice=3, Delivery=4
* @property Guid $Warehouse The warehouse linked to the address, if a warehouse is linked the account will be empty. Can only be filled for type=Delivery
* @property String $WarehouseCode Code of the warehoude
* @property String $WarehouseDescription Description of the warehouse
*/
class Address extends Model
{

use Query\Findable;
use Persistance\Storable;

protected $fillable = [
'ID',
'Account',
'AccountIsSupplier',
'AccountName',
'AddressLine1',
'AddressLine2',
'AddressLine3',
'City',
'Contact',
'ContactName',
'Country',
'CountryName',
'Created',
'Creator',
'CreatorFullName',
'Division',
'Fax',
'FreeBoolField_01',
'FreeBoolField_02',
'FreeBoolField_03',
'FreeBoolField_04',
'FreeBoolField_05',
'FreeDateField_01',
'FreeDateField_02',
'FreeDateField_03',
'FreeDateField_04',
'FreeDateField_05',
'FreeNumberField_01',
'FreeNumberField_02',
'FreeNumberField_03',
'FreeNumberField_04',
'FreeNumberField_05',
'FreeTextField_01',
'FreeTextField_02',
'FreeTextField_03',
'FreeTextField_04',
'FreeTextField_05',
'Mailbox',
'Main',
'Modified',
'Modifier',
'ModifierFullName',
'NicNumber',
'Notes',
'Phone',
'PhoneExtension',
'Postcode',
'State',
'StateDescription',
'Type',
'Warehouse',
'WarehouseCode',
'WarehouseDescription'
];

protected $url = 'crm/Addresses';

}
148 changes: 148 additions & 0 deletions Contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php namespace Picqer\Financials\Exact;

/**
* Class Contact
*
* @package Picqer\Financials\Exact
* @see https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=crmContacts
*
* @property Guid $ID Primary key
* @property Guid $Account The account to which the contact belongs
* @property Boolean $AccountIsCustomer Indicates if account is a customer
* @property Boolean $AccountIsSupplier Indicates if account is a supplier
* @property Guid $AccountMainContact Reference to the main contact of the account
* @property String $AccountName Name of the account
* @property String $AddressLine2 Second address line
* @property String $AddressStreet Street name of the address
* @property String $AddressStreetNumber Street number of the address
* @property String $AddressStreetNumberSuffix Street number suffix of the address
* @property Int32 $AllowMailing Obsolete
* @property DateTime $BirthDate Birth date
* @property String $BirthName Last birth name
* @property String $BirthNamePrefix Middle birth name
* @property String $BirthPlace Birth place
* @property String $BusinessEmail Email address of the contact
* @property String $BusinessFax Fax of the contact
* @property String $BusinessMobile Mobile of the contact
* @property String $BusinessPhone Phone of the contact
* @property String $BusinessPhoneExtension Phone extension of the contact
* @property String $City City
* @property String $Code Code of the account
* @property String $Country Country code
* @property DateTime $Created Creation date
* @property Guid $Creator User ID of the creator
* @property String $CreatorFullName Name of the creator
* @property Int32 $Division Division code
* @property String $Email Email address of the contact
* @property DateTime $EndDate End date
* @property String $FirstName First name. Provide at least first name or last name to create a new contact
* @property String $FullName Full name (First name Middle name Last name)
* @property String $Gender Gender
* @property Int32 $HID Contact ID
* @property DateTime $IdentificationDate Identification date
* @property Guid $IdentificationDocument Reference to the identification document of the contact
* @property Guid $IdentificationUser Reference to the user responsible for identification
* @property String $Initials Initials
* @property Boolean $IsMailingExcluded Indicates whether contacts are excluded from the marketing list
* @property Boolean $IsMainContact Indicates if this is the main contact of the linked account
* @property String $JobTitleDescription Jobtitle of the contact
* @property String $Language Language code
* @property String $LastName Last name. Provide at least first name or last name to create a new contact
* @property String $MarketingNotes The user should be able to do a full text search on these notes to gather contacts for a marketing campaign
* @property String $MiddleName Middle name
* @property String $Mobile Business phone of the contact
* @property DateTime $Modified Last modified date
* @property Guid $Modifier User ID of modifier
* @property String $ModifierFullName Name of the last modifier
* @property String $Nationality Nationality
* @property String $Notes Extra remarks
* @property String $PartnerName Last name of partner
* @property String $PartnerNamePrefix Middlename of partner
* @property Guid $Person Reference to the personal information of this contact such as name, gender, address etc.
* @property String $Phone Phone of the contact
* @property String $PhoneExtension Phone extension of the contact
* @property Binary $Picture This field is write-only. The picture can be downloaded through PictureUrl and PictureThumbnailUrl.
* @property String $PictureName Filename of the picture
* @property String $PictureThumbnailUrl Url to retrieve the picture thumbnail
* @property String $PictureUrl Url to retrieve the picture
* @property String $Postcode Postcode
* @property String $SocialSecurityNumber Social security number
* @property DateTime $StartDate Start date
* @property String $State State
* @property String $Title Title
*/
class Contact extends Model
{

use Query\Findable;
use Persistance\Storable;

protected $fillable = [
'ID',
'Account',
'AccountIsCustomer',
'AccountIsSupplier',
'AccountMainContact',
'AccountName',
'AddressLine2',
'AddressStreet',
'AddressStreetNumber',
'AddressStreetNumberSuffix',
'AllowMailing',
'BirthDate',
'BirthName',
'BirthNamePrefix',
'BirthPlace',
'BusinessEmail',
'BusinessFax',
'BusinessMobile',
'BusinessPhone',
'BusinessPhoneExtension',
'City',
'Code',
'Country',
'Created',
'Creator',
'CreatorFullName',
'Division',
'Email',
'EndDate',
'FirstName',
'FullName',
'Gender',
'HID',
'IdentificationDate',
'IdentificationDocument',
'IdentificationUser',
'Initials',
'IsMailingExcluded',
'IsMainContact',
'JobTitleDescription',
'Language',
'LastName',
'MarketingNotes',
'MiddleName',
'Mobile',
'Modified',
'Modifier',
'ModifierFullName',
'Nationality',
'Notes',
'PartnerName',
'PartnerNamePrefix',
'Person',
'Phone',
'PhoneExtension',
'Picture',
'PictureName',
'PictureThumbnailUrl',
'PictureUrl',
'Postcode',
'SocialSecurityNumber',
'StartDate',
'State',
'Title'
];

protected $url = 'crm/Contacts';
}
37 changes: 34 additions & 3 deletions src/Picqer/Financials/Exact/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public function __set($key, $value)
}


/**
* Checks if primaryKey holds a value
*
* @return boolean
*/
public function exists()
{
if ( ! array_key_exists($this->primaryKey, $this->attributes)) {
Expand All @@ -135,19 +140,45 @@ public function exists()
}


public function json()
/**
* Return the JSON representation of the data
*
* @param int $options http://php.net/manual/en/json.constants.php
*
* @return string
*/
public function json($options = 0)
{
return json_encode($this->attributes);
return json_encode($this->attributes, $options);
}


/**
* Return serializable data
*
*
* @return array
*/
public function jsonSerialize()
{
return $this->attributes;
}


/**
* Check whether the current user has rights for an action on this endpoint
* https://start.exactonline.nl/docs/HlpRestAPIResources.aspx?SourceAction=10
*
* @param string $action
*
* @return boolean
*/
public function userHasRights($action='GET')
{
$action = preg_match('/^GET|POST|PUT|DELETE$/i', $action) ? strtoupper($action) : 'GET';
$result = $this->connection()->get('users/UserHasRights', [
'endpoint' => "'{$this->url}'",
'action' => "'{$action}'"
]);
return isset($result['UserHasRights']) ? $result['UserHasRights'] : null;
}
}

0 comments on commit 08c51b5

Please sign in to comment.