File tree Expand file tree Collapse file tree 4 files changed +97
-3
lines changed Expand file tree Collapse file tree 4 files changed +97
-3
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace TantHammar \LaravelRules \Helpers ;
4
+
5
+ use TantHammar \LaravelRules \Rules \OrgNummer ;
6
+ use TantHammar \LaravelRules \Rules \PersonNummer ;
7
+
8
+ /** returns 'business', 'individual' or 'undefined' */
9
+ class BusinessTypeFromNr
10
+ {
11
+ /** returns 'business', 'individual' or 'undefined' */
12
+ public static function make (string |int $ nr ): string
13
+ {
14
+ if (filled ($ nr )) {
15
+ if ((new PersonNummer ())->passes (null , $ nr )) {
16
+ return 'individual ' ;
17
+ }
18
+ if ((new OrgNummer ())->passes (null , $ nr )) {
19
+ return 'business ' ;
20
+ }
21
+ }
22
+ return 'undefined ' ;
23
+ }
24
+ }
Original file line number Diff line number Diff line change 8
8
9
9
class RuleHelpers
10
10
{
11
+ /**
12
+ * @param string $vatID
13
+ * @return string
14
+ * @deprecated use BusinessNameFromVatID::lookup(string $vatID)
15
+ */
11
16
public static function getBusinessNameFromVatID (string $ vatID ): string
12
17
{
13
18
try {
@@ -17,8 +22,10 @@ public static function getBusinessNameFromVatID(string $vatID): string
17
22
}
18
23
}
19
24
20
- /** src https://github.com/driesvints/vat-calculator#get-eu-vat-number-details<br>
21
- * uk format: https://github.com/driesvints/vat-calculator#uk-vat-numbers
25
+ /**
26
+ * @param string $vatID
27
+ * @return object
28
+ * @deprecated use VatDetailsFromVatID::lookup(string $vatID)
22
29
*/
23
30
public static function getVATDetailsFromVatID (string $ vatID ): object
24
31
{
@@ -37,7 +44,11 @@ public static function getVATDetailsFromVatID(string $vatID): object
37
44
}
38
45
}
39
46
40
- /** returns 'business', 'individual' or 'undefined' */
47
+ /**
48
+ * @param string|int $nr
49
+ * @return string
50
+ * @deprecated use BusinessTypeFromNr::make(string|int $nr)
51
+ */
41
52
public static function check_business_type (string |int $ nr ): string
42
53
{
43
54
if (filled ($ nr )) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace TantHammar \LaravelRules \Services ;
4
+
5
+ use Mpociot \VatCalculator \Facades \VatCalculator ;
6
+
7
+ class BusinessNameFromVatID
8
+ {
9
+ public static function lookup (string $ vatID ): string
10
+ {
11
+ $ unknown = trans ('laravel-rules::msg.vat-name-unknown ' );
12
+
13
+ if (!$ vatID ) {
14
+ return $ unknown ;
15
+ }
16
+
17
+ try {
18
+ return VatCalculator::getVATDetails ($ vatID )?->name ?? $ unknown ;
19
+ } catch (\Exception ) {
20
+ return $ unknown ;
21
+ }
22
+
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace TantHammar \LaravelRules \Services ;
4
+
5
+ use Mpociot \VatCalculator \Facades \VatCalculator ;
6
+
7
+ /**
8
+ * eu format or uk format:<br>
9
+ * @see https://github.com/driesvints/vat-calculator#get-eu-vat-number-details
10
+ * @see https://github.com/driesvints/vat-calculator#uk-vat-numbers
11
+ */
12
+ class VatDetailsFromVatID
13
+ {
14
+ public static function lookup (string $ vatID ): object
15
+ {
16
+ $ empty = new \stdClass ([
17
+ 'countryCode ' => '' ,
18
+ 'vatNumber ' => '' ,
19
+ 'requestDate ' => '' ,
20
+ 'valid ' => false ,
21
+ 'name ' => '' ,
22
+ 'address ' => '' ,
23
+ ]);
24
+
25
+ if (!$ vatID ) {
26
+ return $ empty ;
27
+ }
28
+
29
+ try {
30
+ return VatCalculator::getVATDetails ($ vatID ) ?? $ empty ;
31
+ } catch (\Exception ) {
32
+ return $ empty ;
33
+ }
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments