Skip to content

Commit c21978a

Browse files
authored
Merge pull request #286 from robindirksen1/patch-downloadable-attachments
Add downloadable attachment option (as mentioned in the changelog per 2023-07-27)
2 parents 465da86 + daef42f commit c21978a

17 files changed

+218
-0
lines changed

src/Picqer/Financials/Moneybird/Entities/Estimate.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class Estimate extends Model
9090
* @var array
9191
*/
9292
protected $multipleNestedEntities = [
93+
'attachments' => [
94+
'entity' => EstimateAttachment::class,
95+
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
96+
],
9397
'custom_fields' => [
9498
'entity' => SalesInvoiceCustomField::class,
9599
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Picqer\Financials\Moneybird\Entities;
4+
5+
use Picqer\Financials\Moneybird\Entities\Generic\Attachment;
6+
7+
/**
8+
* Class EstimateAttachment.
9+
*/
10+
class EstimateAttachment extends Attachment
11+
{
12+
/**
13+
* @var string
14+
*/
15+
protected $endpoint = 'estimates';
16+
}

src/Picqer/Financials/Moneybird/Entities/ExternalSalesInvoice.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class ExternalSalesInvoice extends Model
7777
* @var array
7878
*/
7979
protected $multipleNestedEntities = [
80+
'attachments' => [
81+
'entity' => ExternalSalesInvoiceAttachment::class,
82+
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
83+
],
8084
'details' => [
8185
'entity' => ExternalSalesInvoiceDetail::class,
8286
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Picqer\Financials\Moneybird\Entities;
4+
5+
use Picqer\Financials\Moneybird\Entities\Generic\Attachment;
6+
7+
/**
8+
* Class ExternalSalesInvoiceAttachment.
9+
*/
10+
class ExternalSalesInvoiceAttachment extends Attachment
11+
{
12+
/**
13+
* @var string
14+
*/
15+
protected $endpoint = 'external_sales_invoices';
16+
}

src/Picqer/Financials/Moneybird/Entities/GeneralDocument.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ class GeneralDocument extends Model
4444
* @var string
4545
*/
4646
protected $namespace = 'general_document';
47+
48+
/**
49+
* @var array
50+
*/
51+
protected $multipleNestedEntities = [
52+
'attachments' => [
53+
'entity' => GeneralDocumentAttachment::class,
54+
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
55+
],
56+
];
4757
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Picqer\Financials\Moneybird\Entities;
4+
5+
use Picqer\Financials\Moneybird\Entities\Generic\Attachment;
6+
7+
/**
8+
* Class GeneralDocumentAttachment.
9+
*/
10+
class GeneralDocumentAttachment extends Attachment
11+
{
12+
/**
13+
* @var string
14+
*/
15+
protected $endpoint = 'documents/general_documents';
16+
}

src/Picqer/Financials/Moneybird/Entities/GeneralJournalDocument.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class GeneralJournalDocument extends Model
4444
* @var array
4545
*/
4646
protected $multipleNestedEntities = [
47+
'attachments' => [
48+
'entity' => GeneralJournalDocumentAttachment::class,
49+
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
50+
],
4751
'general_journal_document_entries' => [
4852
'entity' => GeneralJournalDocumentEntry::class,
4953
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Picqer\Financials\Moneybird\Entities;
4+
5+
use Picqer\Financials\Moneybird\Entities\Generic\Attachment;
6+
7+
/**
8+
* Class GeneralJournalDocumentAttachment.
9+
*/
10+
class GeneralJournalDocumentAttachment extends Attachment
11+
{
12+
/**
13+
* @var string
14+
*/
15+
protected $endpoint = 'documents/general_journal_documents';
16+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Picqer\Financials\Moneybird\Entities\Generic;
4+
5+
use Picqer\Financials\Moneybird\Model;
6+
7+
/**
8+
* Class InvoiceDetail.
9+
*/
10+
abstract class Attachment extends Model
11+
{
12+
/**
13+
* @var string
14+
*/
15+
protected $attachmentPath = 'attachments';
16+
17+
/**
18+
* @var array
19+
*/
20+
protected $fillable = [
21+
'id',
22+
'administration_id',
23+
'attachable_id',
24+
'attachable_type',
25+
'filename',
26+
'content_type',
27+
'size',
28+
'rotation',
29+
'created_at',
30+
'updated_at',
31+
];
32+
33+
/**
34+
* Download the file.
35+
*
36+
* @return string file data
37+
*
38+
* @throws \Picqer\Financials\Moneybird\Exceptions\ApiException
39+
*/
40+
public function download()
41+
{
42+
$response = $this->connection()->download($this->getEndpoint() . '/' . urlencode($this->attachable_id) . '/' . $this->attachmentPath . '/' . urlencode($this->id) . '/download');
43+
44+
return $response->getBody()->getContents();
45+
}
46+
}

src/Picqer/Financials/Moneybird/Entities/PurchaseInvoice.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class PurchaseInvoice extends Model
7272
* @var array
7373
*/
7474
protected $multipleNestedEntities = [
75+
'attachments' => [
76+
'entity' => PurchaseInvoiceAttachment::class,
77+
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
78+
],
7579
'details' => [
7680
'entity' => PurchaseInvoiceDetail::class,
7781
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,

0 commit comments

Comments
 (0)