|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MÓDULO DE EMISIÓN ELECTRÓNICA F72X |
|
5
|
|
|
* UBL 2.1 |
|
6
|
|
|
* Version 1.1 |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright 2018, Jaime Cruz |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace F72X\Sunat; |
|
12
|
|
|
|
|
13
|
|
|
class Operations { |
|
14
|
|
|
|
|
15
|
|
|
public static function formatAmount($amount, $decimals = 2) { |
|
16
|
|
|
return number_format($amount, $decimals, '.', ''); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* |
|
21
|
|
|
* @param float $amount |
|
22
|
|
|
* @param array $items |
|
23
|
|
|
* @return float |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function applyAllowancesAndCharges($amount, array $items = []) { |
|
26
|
|
|
if (!$amount) { |
|
27
|
|
|
return 0; |
|
28
|
|
|
} |
|
29
|
|
|
$totalAllowances = 0; |
|
30
|
|
|
$totalCharges = 0; |
|
31
|
|
|
foreach ($items as $item) { |
|
32
|
|
|
$isCharge = $item['isCharge']; |
|
33
|
|
|
$k = $item['multiplierFactor']; |
|
34
|
|
|
$r = $amount * $k; |
|
35
|
|
|
if($isCharge){ |
|
36
|
|
|
$totalCharges += $r; |
|
37
|
|
|
}else{ |
|
38
|
|
|
$totalAllowances += $r; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
return $amount - $totalAllowances + $totalCharges; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public static function getTotalAllowanceCharge($amount, array $items, $isCharge) { |
|
46
|
|
|
$total = 0; |
|
47
|
|
|
foreach ($items as $item) { |
|
48
|
|
|
$k = $item['multiplierFactor']; |
|
49
|
|
|
if ($item['isCharge'] == $isCharge) { |
|
50
|
|
|
$total += $amount * $k; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
return $total; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public static function getTotalCharges($amount, array $items) { |
|
57
|
|
|
return self::getTotalAllowanceCharge($amount, $items, true); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public static function getTotalAllowances($amount, array $items) { |
|
61
|
|
|
return self::getTotalAllowanceCharge($amount, $items, false); |
|
62
|
|
|
} |
|
63
|
|
|
/** |
|
64
|
|
|
* Calcular IGV |
|
65
|
|
|
* @param float $baseAmount |
|
66
|
|
|
* @return float |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function calcIGV($baseAmount) { |
|
69
|
|
|
return $baseAmount * SunatVars::IGV; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Calcular ISC |
|
74
|
|
|
* @IMP |
|
75
|
|
|
* @return float |
|
76
|
|
|
*/ |
|
77
|
|
|
public static function calcISC() { |
|
78
|
|
|
return 0; |
|
79
|
|
|
} |
|
80
|
|
|
/** |
|
81
|
|
|
* Calcular IVAP |
|
82
|
|
|
* @IMP |
|
83
|
|
|
* @return float |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function calcIVAP() { |
|
86
|
|
|
return 0; |
|
87
|
|
|
} |
|
88
|
|
|
/** |
|
89
|
|
|
* Aplica IGV? |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $igvAffectCode @CAT7 |
|
92
|
|
|
* @return boolean |
|
93
|
|
|
*/ |
|
94
|
|
|
public static function isIGVAffected($igvAffectCode) { |
|
95
|
|
|
return ($igvAffectCode === Catalogo::CAT7_GRA_IGV); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|