Skip to content

Commit 75f7f6a

Browse files
committed
Better support for import mappings
1 parent f2ddfae commit 75f7f6a

File tree

9 files changed

+46
-8
lines changed

9 files changed

+46
-8
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ $salesInvoices = $moneybird->salesInvoice()->filter([
111111
'state' => 'draft'
112112
]);
113113
var_dump($salesInvoices); // Array with filtered SalesInvoice objects
114+
115+
// Example: Get import mappings for contacts
116+
$mappings = $moneybird->importMapping()->setType('contact')->get();
117+
var_dump($mappings); // Array with ImportMapping objects
114118
```
115119

116120
## Code example

src/Picqer/Financials/Moneybird/Actions/Filterable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function filter(array $filters)
1717
$filterList[] = $key .':' . $value;
1818
}
1919

20-
$result = $this->connection()->get($this->url, ['filter' => implode(',', $filterList)]);
20+
$result = $this->connection()->get($this->getUrl(), ['filter' => implode(',', $filterList)]);
2121

2222
return $this->collectionFromResult($result);
2323
}

src/Picqer/Financials/Moneybird/Actions/FindAll.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait FindAll
1212
*/
1313
public function get()
1414
{
15-
$result = $this->connection()->get($this->url);
15+
$result = $this->connection()->get($this->getUrl());
1616

1717
return $this->collectionFromResult($result);
1818
}

src/Picqer/Financials/Moneybird/Actions/FindOne.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait FindOne {
1212
*/
1313
public function find($id)
1414
{
15-
$result = $this->connection()->get($this->url . '/' . urlencode($id));
15+
$result = $this->connection()->get($this->getUrl() . '/' . urlencode($id));
1616

1717
return $this->makeFromResponse($result);
1818
}

src/Picqer/Financials/Moneybird/Actions/Removable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait Removable {
1111
*/
1212
public function delete()
1313
{
14-
return $this->connection()->delete($this->url . '/' . urlencode($this->id));
14+
return $this->connection()->delete($this->getUrl() . '/' . urlencode($this->id));
1515
}
1616

1717
}

src/Picqer/Financials/Moneybird/Actions/Storable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function save()
2525
*/
2626
public function insert()
2727
{
28-
$result = $this->connection()->post($this->url, $this->jsonWithNamespace());
28+
$result = $this->connection()->post($this->getUrl(), $this->jsonWithNamespace());
2929

3030
return $this->selfFromResponse($result);
3131
}
@@ -35,7 +35,7 @@ public function insert()
3535
*/
3636
public function update()
3737
{
38-
$result = $this->connection()->patch($this->url . '/' . urlencode($this->id), $this->jsonWithNamespace());
38+
$result = $this->connection()->patch($this->getUrl() . '/' . urlencode($this->id), $this->jsonWithNamespace());
3939

4040
return $this->selfFromResponse($result);
4141
}

src/Picqer/Financials/Moneybird/Actions/Synchronizable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait Synchronizable
1212
*/
1313
public function listVersions()
1414
{
15-
$result = $this->connection()->get($this->url . '/synchronization');
15+
$result = $this->connection()->get($this->getUrl() . '/synchronization');
1616

1717
return $this->collectionFromResult($result);
1818
}
@@ -23,7 +23,7 @@ public function listVersions()
2323
*/
2424
public function getVersions(array $ids)
2525
{
26-
$result = $this->connection()->post($this->url .'/synchronization', json_encode([
26+
$result = $this->connection()->post($this->getUrl() .'/synchronization', json_encode([
2727
'ids' => $ids
2828
]));
2929

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class ImportMapping extends Model {
1212

1313
use FindAll, FindOne;
1414

15+
protected $type = null;
16+
1517
/**
1618
* @var array
1719
*/
@@ -26,4 +28,28 @@ class ImportMapping extends Model {
2628
* @var string
2729
*/
2830
protected $url = 'import_mappings';
31+
32+
/**
33+
* @param string $type The type of import mapping to request
34+
*
35+
* Type should be any of: financial_account bank_mutation contact document_attachment general_journal identity
36+
* incoming_invoice attachment payment history invoice_attachment transaction ledger_account tax_rate product
37+
* print_invoice recurring_template invoice workflow document_style
38+
* @return $this
39+
*/
40+
public function setType($type)
41+
{
42+
$this->type = $type;
43+
44+
return $this;
45+
}
46+
47+
public function getUrl()
48+
{
49+
if (is_null($this->type)) {
50+
return $this->url;
51+
}
52+
53+
return $this->url . '/' . $this->type;
54+
}
2955
}

src/Picqer/Financials/Moneybird/Model.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,12 @@ public function __debugInfo()
329329
return $result;
330330
}
331331

332+
/**
333+
* @return string
334+
*/
335+
public function getUrl()
336+
{
337+
return $this->url;
338+
}
339+
332340
}

0 commit comments

Comments
 (0)