1- <?php
1+ <?php declare (strict_types= 1 );
22
3- namespace REWEParser ;
3+ namespace K118 \ Receipt \ REWE ;
44
5- use REWEParser \Exception \ReceiptParseException ;
5+ use K118 \Receipt \Format \Exception \ReceiptParseException ;
6+ use K118 \Receipt \Format \Models \Receipt ;
67
7- class Position {
8+ class Position implements \ K118 \ Receipt \ Format \ Models \Position {
89
9- private $ name ;
10- private $ priceTotal ;
11- private $ priceSingle ;
12- private $ taxCode ;
10+ private Receipt $ receipt ;
1311
14- private $ weight ;
15- private $ amount ;
12+ private string $ name ;
13+ private ?float $ priceTotal ;
14+ private ?float $ priceSingle ;
15+ private ?string $ taxCode ;
16+ private ?float $ quantity ;
1617
17- /**
18- * The name of the product.
19- *
20- * @return string|NULL
21- */
22- public function getName (): ?string {
18+ public function __construct (Receipt $ receipt , string $ name = null , float $ priceTotal = null , float $ priceSingle = null , string $ taxCode = null , float $ quantity = null ) {
19+ $ this ->receipt = $ receipt ;
20+ $ this ->name = $ name ;
21+ $ this ->priceTotal = $ priceTotal ;
22+ $ this ->priceSingle = $ priceSingle ;
23+ $ this ->taxCode = $ taxCode ;
24+ $ this ->quantity = $ quantity ;
25+ }
26+
27+ public function getName (): string {
2328 return $ this ->name ;
2429 }
2530
2631 /**
27- * The total sum of the position
28- *
29- * @return float
30- * @throws ReceiptParseException
32+ * The Tax Code of the position (e.g. "A" or "B")
33+ * @return string|NULL
34+ * @todo support tax amount
3135 */
32- public function getPriceTotal (): float {
33- if ($ this ->priceTotal !== null ) {
34- return $ this ->priceTotal ;
35- }
36- if ($ this ->priceSingle !== null && $ this ->amount !== null ) {
37- return $ this ->priceSingle * $ this ->amount ;
38- }
39- if ($ this ->priceSingle !== null && $ this ->weight !== null ) {
40- return $ this ->priceSingle * $ this ->weight ;
41- }
42- throw new ReceiptParseException ();
36+ public function getTaxCode (): ?string {
37+ return $ this ->taxCode ;
38+ }
39+
40+ public function getReceipt (): Receipt {
41+ return $ this ->receipt ;
4342 }
4443
4544 /**
46- * The single value for one unit of the product
47- *
48- * @return float
4945 * @throws ReceiptParseException
5046 */
51- public function getPriceSingle (): float {
47+ public function getSinglePrice (): float {
5248 if ($ this ->priceSingle !== null ) {
5349 return $ this ->priceSingle ;
5450 }
55- if ($ this ->priceTotal !== null && $ this ->amount !== null ) {
56- return $ this ->priceTotal / $ this ->amount ;
57- }
58- if ($ this ->priceTotal !== null && $ this ->weight !== null ) {
59- return $ this ->priceTotal / $ this ->weight ;
51+ if ($ this ->priceTotal !== null && $ this ->quantity !== null ) {
52+ return $ this ->priceTotal / $ this ->quantity ;
6053 }
6154 if ($ this ->priceTotal !== null ) {
6255 return $ this ->priceTotal ;
6356 }
6457 throw new ReceiptParseException ();
6558 }
6659
67- /**
68- * The Tax Code of the position (e.g. "A" or "B")
69- *
70- * @return string|NULL
71- */
72- public function getTaxCode (): ?string {
73- return $ this ->taxCode ;
60+ public function getQuantity (): float {
61+ return $ this ->quantity ?? 1.0 ;
7462 }
7563
7664 /**
77- * The weight of the position (if the product is weightable)
78- *
79- * @return float|NULL
65+ * @throws ReceiptParseException
8066 */
81- public function getWeight (): ?float {
82- return $ this ->weight ;
67+ public function getTotalPrice (): float {
68+ if ($ this ->priceTotal !== null ) {
69+ return $ this ->priceTotal ;
70+ }
71+ if ($ this ->priceSingle !== null && $ this ->quantity !== null ) {
72+ return $ this ->priceSingle * $ this ->quantity ;
73+ }
74+ throw new ReceiptParseException ();
8375 }
8476
85- /**
86- * The amount of the position (if the product is countable)
87- *
88- * @return int|NULL
89- */
90- public function getAmount (): ?int {
91- if ($ this ->amount === null && $ this ->weight === null ) {
92- return 1 ;
93- }
94- return $ this ->amount ;
77+ public function getTax (): float {
78+ // TODO: Implement getTax() method.
79+ return -1 ;
9580 }
9681
9782 public function setName (string $ name ): void {
@@ -110,12 +95,7 @@ public function setTaxCode(string $taxCode): void {
11095 $ this ->taxCode = $ taxCode ;
11196 }
11297
113- public function setWeight (float $ weight ): void {
114- $ this ->weight = $ weight ;
115- }
116-
117- public function setAmount (int $ amount ): void {
118- $ this ->amount = $ amount ;
98+ public function setQuantity (float $ quantity ): void {
99+ $ this ->quantity = $ quantity ;
119100 }
120-
121101}
0 commit comments