Skip to content

Commit

Permalink
Changed SupplierInvoice book method
Browse files Browse the repository at this point in the history
  • Loading branch information
kg-bot committed Jun 19, 2020
1 parent 033a927 commit b916bbb
Showing 1 changed file with 28 additions and 50 deletions.
78 changes: 28 additions & 50 deletions src/Models/SupplierInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,34 @@
class SupplierInvoice extends Model
{

protected $entity = 'supplier-invoices';
protected $primaryKey = 'number';

/**
* Book supplier invoice
*
* @param bool|array $send_email [optional] <p>
* This parameter indicates should the mail be sent to supplier,
* if you send it as array it must be in format like this:
* [
* "send" => false,
* "body" => "Something",
* "subject" => "YOUR SUBJECT",
* "receivers" => [
* "to" => [ "email@here.com"],
* "cc" => ["cc-email@here.com"],
* "bcc" => ["bcc1-email@here.com", "bcc2@here.com"]
* ]
* ]
* If you set send to false or use ->book(true) email body won't be included
* </p>
* @return mixed
* @throws \Rackbeat\Exceptions\RackbeatClientException
* @throws \Rackbeat\Exceptions\RackbeatRequestException
*/
public function book($send_email = false)
{
return $this->request->handleWithExceptions(function () use ($send_email) {

$query = '';
$body = [];

if (is_bool($send_email)) {

$query = ($send_email === true) ? '?send_mail=true' : '';
} else if (is_array($send_email)) {

$body = [

'mail' => $send_email,
];
}

$response = $this->request->client->post("{$this->entity}/{$this->url_friendly_id}/book" . $query, [
'json' => $body,
]);


return json_decode((string)$response->getBody());
});
protected $entity = 'supplier-invoices';
protected $primaryKey = 'number';

/**
* Book supplier invoice
*
* @param bool $mark_as_received
* @param bool $use_invoice_date
*
* @return mixed
* @throws \Rackbeat\Exceptions\RackbeatClientException
* @throws \Rackbeat\Exceptions\RackbeatRequestException
*/
public function book( $mark_as_received = false, $use_invoice_date = false ) {
return $this->request->handleWithExceptions( function () use ( $mark_as_received, $use_invoice_date ) {

$data = [
'mark_received' => $mark_as_received,
'use_invoice_date' => $use_invoice_date
];

$response = $this->request->client->post( "{$this->entity}/{$this->url_friendly_id}/book", [
'json' => $data,
] );


return json_decode( (string) $response->getBody() );
});
}

public function getPDF()
Expand Down

0 comments on commit b916bbb

Please sign in to comment.