Skip to content

Commit

Permalink
Add downloadable attachment option (as mentioned in the changelog per…
Browse files Browse the repository at this point in the history
… 2023-07-27) for the entities:

- estimates
- external sales invoice
- sales invoice
- document: general document
- document: general journal document
- document: purchase invoice
- document: receipt
- document: typeless document
  • Loading branch information
robindirksen1 authored Jul 27, 2023
1 parent edafecc commit daef42f
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/Estimate.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class Estimate extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => EstimateAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'custom_fields' => [
'entity' => SalesInvoiceCustomField::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
16 changes: 16 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/EstimateAttachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class EstimateAttachment.
*/
class EstimateAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'estimates';
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class ExternalSalesInvoice extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => ExternalSalesInvoiceAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'details' => [
'entity' => ExternalSalesInvoiceDetail::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class ExternalSalesInvoiceAttachment.
*/
class ExternalSalesInvoiceAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'external_sales_invoices';
}
10 changes: 10 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/GeneralDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ class GeneralDocument extends Model
* @var string
*/
protected $namespace = 'general_document';

/**
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => GeneralDocumentAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class GeneralDocumentAttachment.
*/
class GeneralDocumentAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/general_documents';
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class GeneralJournalDocument extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => GeneralJournalDocumentAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'general_journal_document_entries' => [
'entity' => GeneralJournalDocumentEntry::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class GeneralJournalDocumentAttachment.
*/
class GeneralJournalDocumentAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/general_journal_documents';
}
46 changes: 46 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/Generic/Attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Picqer\Financials\Moneybird\Entities\Generic;

use Picqer\Financials\Moneybird\Model;

/**
* Class InvoiceDetail.
*/
abstract class Attachment extends Model
{
/**
* @var string
*/
protected $attachmentPath = 'attachments';

/**
* @var array
*/
protected $fillable = [
'id',
'administration_id',
'attachable_id',
'attachable_type',
'filename',
'content_type',
'size',
'rotation',
'created_at',
'updated_at',
];

/**
* Download the file.
*
* @return string file data
*
* @throws \Picqer\Financials\Moneybird\Exceptions\ApiException
*/
public function download()
{
$response = $this->connection()->download($this->getEndpoint() . '/' . urlencode($this->attachable_id) . '/' . $this->attachmentPath . '/' . urlencode($this->id) . '/download');

return $response->getBody()->getContents();
}
}
4 changes: 4 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/PurchaseInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class PurchaseInvoice extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => PurchaseInvoiceAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'details' => [
'entity' => PurchaseInvoiceDetail::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class SalesInvoiceAttachment.
*/
class PurchaseInvoiceAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/purchase_invoices';
}
4 changes: 4 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class Receipt extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => ReceiptAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'details' => [
'entity' => ReceiptDetail::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
16 changes: 16 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/ReceiptAttachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class ReceiptAttachment.
*/
class ReceiptAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/receipts';
}
4 changes: 4 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/SalesInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class SalesInvoice extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => SalesInvoiceAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'custom_fields' => [
'entity' => SalesInvoiceCustomField::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class SalesInvoiceAttachment.
*/
class SalesInvoiceAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'sales_invoices';
}
10 changes: 10 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/TypelessDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ class TypelessDocument extends Model
* @var string
*/
protected $namespace = 'typeless_document';

/**
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => TypelessDocumentAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class TypelessDocumentAttachment.
*/
class TypelessDocumentAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/typeless_documents';
}

0 comments on commit daef42f

Please sign in to comment.