Passed
Branch develop (5fc816)
by JAIME ELMER
01:58
created

Operations::calcIGV()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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