From e0e1a449e0cea48421eba859450c0a4964aabe8b Mon Sep 17 00:00:00 2001 From: Paul G Date: Tue, 24 Aug 2021 09:34:44 +0100 Subject: [PATCH] provide setter for adding bill items --- CHANGELOG.md | 2 +- src/Entities/Bills/Create.php | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96bbeda..c16a44f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog All notable changes to this project will be documented in this file. -## [0.3.0] - 2021-08-22 +## [0.3.1] - 2021-08-22 ### Added - Add support for new Bill Items update to the API. diff --git a/src/Entities/Bills/Create.php b/src/Entities/Bills/Create.php index 7fa042c..7096e6b 100644 --- a/src/Entities/Bills/Create.php +++ b/src/Entities/Bills/Create.php @@ -2,6 +2,7 @@ namespace FernleafSystems\ApiWrappers\Freeagent\Entities\Bills; +use FernleafSystems\ApiWrappers\Freeagent\Entities\Bills\Items\BillItemVO; use FernleafSystems\ApiWrappers\Freeagent\Entities\Categories\CategoryVO; use FernleafSystems\ApiWrappers\Freeagent\Entities\Contacts\ContactVO; @@ -14,29 +15,42 @@ class Create extends Base { const REQUEST_METHOD = 'post'; /** - * @param array $aData + * @param array $data * @return BillVO|null */ - public function create( $aData = [] ) { - return $this->setRequestData( $aData, true ) + public function create( array $data = [] ) { + return $this->setRequestData( $data, true ) ->sendRequestWithVoResponse(); } /** - * @param CategoryVO $oCategory + * @param BillItemVO $item * @return $this */ - public function setCategory( $oCategory ) { - return $this->setRequestDataItem( 'category', $oCategory->getUri() ); + public function addBillItem( BillItemVO $item, $merge = true ) { + $items = $this->getRequestDataItem( 'bill_items' ); + if ( !$merge || !is_array( $items ) ) { + $items = []; + } + $items[] = $item->getRawDataAsArray(); + return $this->setRequestDataItem( 'bill_items', $items ); + } + + /** + * @param CategoryVO $category + * @return $this + */ + public function setCategory( CategoryVO $category ) { + return $this->setRequestDataItem( 'category', $category->getUri() ); } /** * Will attempt to construct the URI for this category from the Base ID - * @param int $nId + * @param int $id * @return $this */ - public function setCategoryId( $nId ) { - return $this->setRequestDataItem( 'category', $this->getCategoryUrl( $nId ) ); + public function setCategoryId( $id ) { + return $this->setRequestDataItem( 'category', $this->getCategoryUrl( $id ) ); } /**