Skip to content

Commit

Permalink
✨ Add Rate Category namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
tgeorgel committed Feb 13, 2023
1 parent 9b03877 commit a31a430
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 1 deletion.
124 changes: 124 additions & 0 deletions src/Api/RateCategoriesApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Bluerock\Sellsy\Api;

use Bluerock\Sellsy\Entities\RateCategory;
use Bluerock\Sellsy\Collections\RateCategoryCollection;
use Bluerock\Sellsy\Core\Response;

/**
* The API client for the `rate-categories` namespace.
*
* @package bluerock/sellsy-client
* @author Thomas <[email protected]>
* @version 1.1
* @access public
* @see https://api.sellsy.com/doc/v2/#tag/Rate-Categories
*/
class RateCategoriesApi extends AbstractApi
{
/**
* @inheritdoc
*/
public function __construct()
{
parent::__construct();

$this->entity = RateCategory::class;
$this->collection = RateCategoryCollection::class;
}

/**
* List all rate categories.
*
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/get-rate-categories
*/
public function index(array $query = []): Response
{
$response = $this->connection
->request('rate-categories')
->get($query);

return $this->prepareResponse($response);
}

/**
* Show a single rate category by id.
*
* @param string $id The rate category id to retrieve.
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/get-rate-category
*/
public function show(string $id, array $query = []): Response
{
$response = $this->connection
->request("rate-categories/{$id}")
->get($query);

return $this->prepareResponse($response);
}

/**
* Store (create) a rate category.
*
* @param RateCategory $rateCategory The rate category entity to store.
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/create-rate-category
*/
public function store(RateCategory $rateCategory, array $query = []): Response
{
$body = $rateCategory->except('id')
->toArray();

$response = $this->connection
->request('rate-categories')
->post(array_filter($body) + $query);

return $this->prepareResponse($response);
}

/**
* Update an existing rate category.
*
* @param RateCategory $rateCategory The rate category entity to store.
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/update-rate-category
*/
public function update(RateCategory $rateCategory, array $query = []): Response
{
$body = $rateCategory->except('id')
->toArray();

$response = $this->connection
->request("rate-categories/{$rateCategory->id}")
->put(array_filter($body) + $query);

return $this->prepareResponse($response);
}

/**
* Delete an existing rate category.
*
* @param int $id The rate category id to be deleted.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/delete-rate-category
*/
public function destroy(int $id): Response
{
$response = $this->connection
->request("rate-categories/{$id}")
->delete();

return $this->prepareResponse($response);
}
}
25 changes: 25 additions & 0 deletions src/Collections/RateCategoryCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Bluerock\Sellsy\Collections;

use Bluerock\Sellsy\Entities\RateCategory;
use Bluerock\Sellsy\Contracts\EntityCollectionContract;
use Spatie\DataTransferObject\DataTransferObjectCollection;

/**
* The RateCategory Entity collection.
*
* @package bluerock/sellsy-client
* @author Thomas <[email protected]>
* @version 1.1
* @access public
*
* @method \Bluerock\Sellsy\Entities\RateCategory current
*/
class RateCategoryCollection extends DataTransferObjectCollection implements EntityCollectionContract
{
public static function create(array $data): RateCategoryCollection
{
return new static(RateCategory::arrayOf($data));
}
}
26 changes: 26 additions & 0 deletions src/Entities/Accounting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Bluerock\Sellsy\Entities;

use Bluerock\Sellsy\Entities\Entity;

/**
* The Accounting Entity.
*
* @package bluerock/sellsy-client
* @author Thomas <[email protected]>
* @version 1.1
* @access public
*/
class Accounting extends Entity
{
/**
* Accounting code ID.
*/
public ?int $accounting_code_id;

/**
* Discount accounting code ID.
*/
public ?int $discount_accounting_code_id;
}
2 changes: 1 addition & 1 deletion src/Entities/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* The Item Entity.
*
* @package cedricWebsenso/sellsy-client
* @package bluerock/sellsy-client
* @author Cédric <[email protected]>
* @version 1.0
* @access public
Expand Down
59 changes: 59 additions & 0 deletions src/Entities/RateCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Bluerock\Sellsy\Entities;

use Bluerock\Sellsy\Entities\Tax;
use Bluerock\Sellsy\Entities\Unit;
use Bluerock\Sellsy\Entities\Entity;
use Bluerock\Sellsy\Entities\Accounting;

/**
* The Rate Category Entity.
*
* @package bluerock/sellsy-client
* @author Thomas <[email protected]>
* @version 1.0
* @access public
*/
class RateCategory extends Entity
{
/**
* <READONLY> Rate category ID from Sellsy.
*/
public ?int $id;

/**
* Rate category related tax ID from Sellsy.
*/
public ?int $tax_id;

/**
* Rate category label.
*/
public ?string $label;

/**
* Rate category currency.
*/
public string $currency = 'EUR';

/**
* Does the Rate category includes taxes.
*/
public ?bool $includes_taxes;

/**
* Does the Rate category is the default for this account.
*/
public ?bool $is_default;

/**
* Rate category accounting.
*/
public ?Accounting $accounting;

/**
* Rate category default layouts.
*/
public ?array $default_layouts;
}

0 comments on commit a31a430

Please sign in to comment.