Skip to content

Commit db3421f

Browse files
committed
Added tax rates and products
1 parent c42a66c commit db3421f

File tree

142 files changed

+13405
-7875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+13405
-7875
lines changed

ApiConnector.php

+2
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ protected function getType(Domainmodel_Abstract $model) {
560560
'IncomingInvoice',
561561
'RecurringTemplate',
562562
'CurrentSession',
563+
'TaxRate',
564+
'Product',
563565
);
564566
foreach ($types as $type) {
565567
if ($model instanceof $type) {

Detail/Abstract.php

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ abstract class Detail_Abstract
2525
protected $price;
2626
protected $rowOrder;
2727
protected $tax;
28+
protected $taxRateId;
2829
protected $totalPriceExclTax;
2930
protected $totalPriceInclTax;
3031
protected $updatedAt;

InvoiceProfile.php

-8
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,4 @@ class InvoiceProfile extends Domainmodel_Abstract implements Mapper_Mapable {
1818
'id',
1919
'name',
2020
);
21-
22-
public function save(ApiConnector $service) {
23-
throw new Exception('Cannot save InvoiceProfile');
24-
}
25-
26-
public function delete(ApiConnector $service) {
27-
throw new Exception('Cannot delete InvoiceProfile');
28-
}
2921
}

Product.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* Product class file
5+
*/
6+
7+
namespace Moneybird;
8+
9+
/**
10+
* Product
11+
*/
12+
class Product extends Domainmodel_Abstract implements Mapper_Mapable {
13+
14+
protected $createdAt;
15+
protected $description;
16+
protected $id;
17+
protected $ledgerAccountId;
18+
protected $price;
19+
protected $tax;
20+
protected $taxRateId;
21+
protected $updatedAt;
22+
23+
protected $_readonlyAttr = array(
24+
'createdAt',
25+
'description',
26+
'id',
27+
'ledgerAccountId',
28+
'price',
29+
'tax',
30+
'taxRateId',
31+
'updatedAt',
32+
);
33+
}

Product/Array.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/*
4+
* Product array file
5+
*/
6+
7+
namespace Moneybird;
8+
9+
/**
10+
* Product array
11+
*/
12+
class Product_Array extends ArrayObject {
13+
}

Product/Service.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* Product service class
5+
*/
6+
7+
namespace Moneybird;
8+
9+
/**
10+
* Product service
11+
*/
12+
class Product_Service implements Service {
13+
14+
/**
15+
* ApiConnector object
16+
* @var ApiConnector
17+
*/
18+
protected $connector;
19+
20+
public function __construct(ApiConnector $connector) {
21+
$this->connector = $connector;
22+
}
23+
24+
public function getAll() {
25+
return $this->connector->getAll('Product');
26+
}
27+
}

TaxRate.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* TaxRate class file
5+
*/
6+
7+
namespace Moneybird;
8+
9+
/**
10+
* TaxRate
11+
*/
12+
class TaxRate extends Domainmodel_Abstract implements Mapper_Mapable {
13+
14+
/**
15+
* Rate type
16+
* @const RATE_TYPE_SALES Rates for sales
17+
*/
18+
const RATE_TYPE_SALES = 1;
19+
20+
/**
21+
* Rate type
22+
* @const RATE_TYPE_PURCHASE Rates for purchases
23+
*/
24+
const RATE_TYPE_PURCHASE = 2;
25+
26+
protected $active;
27+
protected $createdAt;
28+
protected $id;
29+
protected $name;
30+
protected $percentage;
31+
protected $showTax;
32+
protected $taxRateType;
33+
protected $taxedItemType;
34+
protected $updatedAt;
35+
36+
protected $_readonlyAttr = array(
37+
'active',
38+
'createdAt',
39+
'id',
40+
'name',
41+
'percentage',
42+
'showTax',
43+
'taxRateType',
44+
'taxedItemType',
45+
'updatedAt',
46+
);
47+
}

TaxRate/Array.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/*
4+
* TaxRate array file
5+
*/
6+
7+
namespace Moneybird;
8+
9+
/**
10+
* TaxRate array
11+
*/
12+
class TaxRate_Array extends ArrayObject {
13+
}

TaxRate/Service.php

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* TaxRate service class
5+
*/
6+
7+
namespace Moneybird;
8+
9+
/**
10+
* TaxRate service
11+
*/
12+
class TaxRate_Service implements Service {
13+
14+
/**
15+
* ApiConnector object
16+
* @var ApiConnector
17+
*/
18+
protected $connector;
19+
20+
public function __construct(ApiConnector $connector) {
21+
$this->connector = $connector;
22+
}
23+
24+
/**
25+
* Get all tax rates
26+
*
27+
* @param string $filter Filter name (all, sales, purchase, inactive)
28+
* @return TaxRate_Array
29+
* @throws InvalidFilterException
30+
*/
31+
public function getAll($filter = null) {
32+
$filters = array('all', 'sales', 'purchase', 'inactive');
33+
if (!in_array($filter, $filters)) {
34+
$message = 'Unknown filter "' . $filter . '" for TaxRates';
35+
$message .= '; available filters: ' . implode(', ', $filters);
36+
throw new InvalidFilterException($message);
37+
}
38+
39+
$rates = new TaxRate_Array;
40+
foreach ($this->connector->getAll('TaxRate') as $rate) {
41+
if (($filter == 'inactive' && $rate->active) || ($filter != 'inactive' && !$rate->active)) {
42+
continue;
43+
}
44+
if ($filter == 'sales' && $rate->taxRateType != TaxRate::RATE_TYPE_SALES) {
45+
continue;
46+
} elseif ($filter == 'purchase' && $rate->taxRateType != TaxRate::RATE_TYPE_PURCHASE) {
47+
continue;
48+
}
49+
$rates->append($rate);
50+
}
51+
return $rates;
52+
}
53+
}

XmlMapper.php

+6
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,17 @@ public function __construct() {
5656
'invoice-profiles' => __NAMESPACE__.'\\InvoiceProfile_Array',
5757
'invoice-profile' => __NAMESPACE__.'\\InvoiceProfile',
5858

59+
'products' => __NAMESPACE__.'\\Product_Array',
60+
'product' => __NAMESPACE__.'\\Product',
61+
5962
'recurring-templates' => __NAMESPACE__.'\\RecurringTemplate_Array',
6063
'recurring-template' => __NAMESPACE__.'\\RecurringTemplate',
6164
'recurring-template/details' => __NAMESPACE__.'\\RecurringTemplate_Detail_Array',
6265
'recurring-template/details/detail' => __NAMESPACE__.'\\RecurringTemplate_Detail',
6366

67+
'tax-rates' => __NAMESPACE__.'\\TaxRate_Array',
68+
'tax-rate' => __NAMESPACE__.'\\TaxRate',
69+
6470
'errors' => __NAMESPACE__.'\\Error_Array',
6571
'error' => __NAMESPACE__.'\\Error',
6672
);

0 commit comments

Comments
 (0)