jxcodes /
f72x
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * MÓDULO DE EMISIÓN ELECTRÓNICA F72X |
||||
| 5 | * UBL 2.1 |
||||
| 6 | * Version 1.0 |
||||
| 7 | * |
||||
| 8 | * Copyright 2019, Jaime Cruz |
||||
| 9 | */ |
||||
| 10 | |||||
| 11 | namespace F72X\Sunat\Document; |
||||
| 12 | |||||
| 13 | use F72X\Sunat\Operations; |
||||
| 14 | use F72X\Sunat\Catalogo; |
||||
| 15 | |||||
| 16 | /** |
||||
| 17 | * AbstractSummary |
||||
| 18 | * |
||||
| 19 | * Base class for Resumen Diario y Comunicación de baja. |
||||
| 20 | */ |
||||
| 21 | abstract class AbstractPerRet extends AbstractDocument { |
||||
| 22 | |||||
| 23 | protected $isPercepcion = false; |
||||
| 24 | protected $isRetencion = false; |
||||
| 25 | |||||
| 26 | /** |
||||
| 27 | * The catalog number of Retencion or Retencion Regime |
||||
| 28 | * |
||||
| 29 | * Use: |
||||
| 30 | * 22: Percepción |
||||
| 31 | * 23: Retención |
||||
| 32 | * |
||||
| 33 | * @var string |
||||
| 34 | */ |
||||
| 35 | protected $regimeCatNumber; |
||||
| 36 | |||||
| 37 | protected function parseInput(array $in) { |
||||
| 38 | $out = $in; |
||||
| 39 | $lines = $this->parseInputLines($in['lines']); |
||||
| 40 | $out['percent'] = Catalogo::getCatItemFieldValue($this->regimeCatNumber, $in['systemCode'], 'tasa'); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 41 | $out['lines'] = $lines; |
||||
| 42 | // Calculate totals |
||||
| 43 | $totalInvoiceAmount = 0; |
||||
| 44 | $totalCashed = 0; |
||||
| 45 | foreach ($lines as $line) { |
||||
| 46 | $totalInvoiceAmount += $line['operationAmount']; |
||||
| 47 | $totalCashed += $line['netTotal']; |
||||
| 48 | } |
||||
| 49 | $out['totalInvoiceAmount'] = $totalInvoiceAmount; |
||||
| 50 | $out['total'] = $totalCashed; |
||||
| 51 | return $out; |
||||
| 52 | } |
||||
| 53 | public function parseInputLine(array $in) { |
||||
| 54 | $bodyInput = $this->getRawData(); |
||||
| 55 | $percent = Catalogo::getCatItemFieldValue($this->regimeCatNumber, $bodyInput['systemCode'], 'tasa'); |
||||
|
0 ignored issues
–
show
$this->regimeCatNumber of type string is incompatible with the type integer expected by parameter $catNumber of F72X\Sunat\Catalogo::getCatItemFieldValue().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 56 | $out = $in; |
||||
| 57 | // Set amount and netTotalCashed |
||||
| 58 | $exchangeCalculationRate = ($out['currencyCode'] == self::LOCAL_CURRENCY_CODE) ? 1 : $out['exchangeRate']; |
||||
| 59 | $paymentBase = $out['payment']['paidAmount'] * $exchangeCalculationRate; |
||||
| 60 | $opAmount = ($paymentBase * $percent)/100; |
||||
| 61 | // Percepcion base + amount |
||||
| 62 | // Retencion base - amount |
||||
| 63 | $operator = $this->isPercepcion ? 1 : -1; |
||||
| 64 | $out['operationAmount'] = $opAmount; |
||||
| 65 | $out['netTotal'] = $paymentBase + ($operator * $opAmount); |
||||
| 66 | return $out; |
||||
| 67 | } |
||||
| 68 | public function setBodyFields() { |
||||
| 69 | $data = $this->getParsedData(); |
||||
| 70 | // Lines |
||||
| 71 | $this->lines = $data['lines']; |
||||
| 72 | } |
||||
| 73 | |||||
| 74 | public function getDataForXml() { |
||||
| 75 | $in = $this->getParsedData(); |
||||
| 76 | // Get base fields |
||||
| 77 | $baseFields = $this->getBaseFieldsForXml(); |
||||
| 78 | $fields = [ |
||||
| 79 | // Regimén |
||||
| 80 | 'systemCode' => $in['systemCode'], |
||||
| 81 | 'percent' => Operations::formatAmount($in['percent']), |
||||
| 82 | 'totalInvoiceAmount' => Operations::formatAmount($in['totalInvoiceAmount']), |
||||
| 83 | 'total' => Operations::formatAmount($in['total']), |
||||
| 84 | 'note' => $in['note'], |
||||
| 85 | 'customer' => $in['customer'] |
||||
| 86 | ]; |
||||
| 87 | return array_merge($baseFields, $fields); |
||||
| 88 | } |
||||
| 89 | |||||
| 90 | protected function getLineForXml(array $in) { |
||||
| 91 | $out = $in; |
||||
| 92 | // Parse payment |
||||
| 93 | $payment = $out['payment']; |
||||
| 94 | $out['payment']['paidAmount'] = Operations::formatAmount($payment['paidAmount']); |
||||
| 95 | $out['totalInvoiceAmount'] = Operations::formatAmount($in['totalInvoiceAmount']); |
||||
| 96 | $out['netTotal'] = Operations::formatAmount($in['netTotal']); |
||||
| 97 | // Per Ret information |
||||
| 98 | |||||
| 99 | return $out; |
||||
| 100 | } |
||||
| 101 | } |
||||
| 102 |