@@ -80,16 +80,16 @@ |
||
| 80 | 80 | |
| 81 | 81 | private static function saveStatusResponse($response, $documentName) {
|
| 82 | 82 | $xml = simplexml_load_string($response); |
| 83 | - $status = (array)$xml->xpath("//status")[0];
|
|
| 83 | + $status = (array) $xml->xpath("//status")[0];
|
|
| 84 | 84 | |
| 85 | 85 | // Status code only 0 and 99 |
| 86 | - if($status['statusCode'] == '0' || $status['statusCode'] == '99') {
|
|
| 86 | + if ($status['statusCode'] == '0' || $status['statusCode'] == '99') {
|
|
| 87 | 87 | $statusContent = $status['content']; |
| 88 | 88 | $cdr = base64_decode($statusContent); |
| 89 | 89 | Repository::saveCdr($documentName, $cdr); |
| 90 | 90 | $status['cdr'] = Repository::getCdrInfo($documentName); |
| 91 | 91 | $status['message'] = null; |
| 92 | - }else{
|
|
| 92 | + } else {
|
|
| 93 | 93 | $status['cdr'] = null; |
| 94 | 94 | $status['message'] = $status['content']; |
| 95 | 95 | } |
@@ -89,7 +89,7 @@ |
||
| 89 | 89 | Repository::saveCdr($documentName, $cdr); |
| 90 | 90 | $status['cdr'] = Repository::getCdrInfo($documentName); |
| 91 | 91 | $status['message'] = null; |
| 92 | - }else{
|
|
| 92 | + } else{
|
|
| 93 | 93 | $status['cdr'] = null; |
| 94 | 94 | $status['message'] = $status['content']; |
| 95 | 95 | } |
@@ -76,43 +76,43 @@ |
||
| 76 | 76 | $grossUnitValue = $item['unitPrice']; |
| 77 | 77 | $igvIncluded = $item['igvIncluded']; |
| 78 | 78 | |
| 79 | - $unitValue = $this->calcUnitValue($igvAffectCode, $grossUnitValue, $igvIncluded); // Valor unitario |
|
| 79 | + $unitValue = $this->calcUnitValue($igvAffectCode, $grossUnitValue, $igvIncluded); // Valor unitario |
|
| 80 | 80 | $unitTaxedValue = $this->calcUnitTaxedValue($igvAffectCode, $grossUnitValue, $igvIncluded); // Valor unitario incluyendo impuestos si son aplicables |
| 81 | - $unitBillableValue = $this->calcUnitBillableValue($unitValue, $priceType); // Valor unitario facturable |
|
| 81 | + $unitBillableValue = $this->calcUnitBillableValue($unitValue, $priceType); // Valor unitario facturable |
|
| 82 | 82 | $quantity = $item['quantity']; // Cantidad |
| 83 | 83 | |
| 84 | - $itemValue = $unitValue * $quantity; // Valor de item |
|
| 84 | + $itemValue = $unitValue * $quantity; // Valor de item |
|
| 85 | 85 | $itemBillableValue = $unitBillableValue * $quantity; // Valor de item |
| 86 | 86 | $itemAllowancesAmount = Operations::getTotalAllowances($itemBillableValue, $ac); // Descuentos de item |
| 87 | - $itemChargesAmount = Operations::getTotalCharges($itemValue, $ac); // Cargos de item |
|
| 88 | - $itemBillableAmount = $this->calcItemBillableAmount($itemValue, $priceType, $ac); // Valor de venta del ítem = (Valor del item - Descuentos + Cargos), 0 si el valor del item es referencial! |
|
| 89 | - $itemTaxableAmount = $this->calcItemTaxableAmount($itemValue, $priceType, $ac); // Valor de venta del ítem = (Valor del item - Descuentos + Cargos), 0 si el valor del item es referencial! |
|
| 87 | + $itemChargesAmount = Operations::getTotalCharges($itemValue, $ac); // Cargos de item |
|
| 88 | + $itemBillableAmount = $this->calcItemBillableAmount($itemValue, $priceType, $ac); // Valor de venta del ítem = (Valor del item - Descuentos + Cargos), 0 si el valor del item es referencial! |
|
| 89 | + $itemTaxableAmount = $this->calcItemTaxableAmount($itemValue, $priceType, $ac); // Valor de venta del ítem = (Valor del item - Descuentos + Cargos), 0 si el valor del item es referencial! |
|
| 90 | 90 | $igvAmount = $this->calcIgvAmount($igvAffectCode, $itemTaxableAmount); // Afectación al IGV por item |
| 91 | 91 | |
| 92 | 92 | $itemPayableAmount = $itemBillableValue + $igvAmount; |
| 93 | 93 | |
| 94 | - $this->set(self::COL_PRODUCT_CODE, $idx, $item['productCode']); |
|
| 95 | - $this->set(self::COL_UNPSC, $idx, $item['unspsc']); |
|
| 96 | - $this->set(self::COL_UNIT_CODE, $idx, $item['unitCode']); |
|
| 97 | - $this->set(self::COL_QUANTITY, $idx, $quantity); |
|
| 98 | - $this->set(self::COL_DESCRIPTION, $idx, trim($item['description'])); |
|
| 99 | - $this->set(self::COL_CURRENCY_CODE, $idx, $currencyCode); |
|
| 94 | + $this->set(self::COL_PRODUCT_CODE, $idx, $item['productCode']); |
|
| 95 | + $this->set(self::COL_UNPSC, $idx, $item['unspsc']); |
|
| 96 | + $this->set(self::COL_UNIT_CODE, $idx, $item['unitCode']); |
|
| 97 | + $this->set(self::COL_QUANTITY, $idx, $quantity); |
|
| 98 | + $this->set(self::COL_DESCRIPTION, $idx, trim($item['description'])); |
|
| 99 | + $this->set(self::COL_CURRENCY_CODE, $idx, $currencyCode); |
|
| 100 | 100 | // Códigos de catálogos predefinidos |
| 101 | - $this->set(self::COL_PRICE_TYPE, $idx, $priceType); |
|
| 102 | - $this->set(self::COL_TAX_TYPE, $idx, $item['taxType']); |
|
| 103 | - $this->set(self::COL_IGV_AFFECTATION, $idx, $item['igvAffectationType']); |
|
| 101 | + $this->set(self::COL_PRICE_TYPE, $idx, $priceType); |
|
| 102 | + $this->set(self::COL_TAX_TYPE, $idx, $item['taxType']); |
|
| 103 | + $this->set(self::COL_IGV_AFFECTATION, $idx, $item['igvAffectationType']); |
|
| 104 | 104 | |
| 105 | - $this->set(self::COL_UNIT_VALUE, $idx, $unitValue); |
|
| 105 | + $this->set(self::COL_UNIT_VALUE, $idx, $unitValue); |
|
| 106 | 106 | $this->set(self::COL_UNIT_BILLABLE_VALUE, $idx, $unitBillableValue); |
| 107 | - $this->set(self::COL_UNIT_TAXED_VALUE, $idx, $unitTaxedValue); |
|
| 108 | - $this->set(self::COL_ITEM_VALUE, $idx, $itemValue); |
|
| 107 | + $this->set(self::COL_UNIT_TAXED_VALUE, $idx, $unitTaxedValue); |
|
| 108 | + $this->set(self::COL_ITEM_VALUE, $idx, $itemValue); |
|
| 109 | 109 | $this->set(self::COL_ITEM_BILLABLE_VALUE, $idx, $itemBillableValue); |
| 110 | - $this->set(self::COL_ALLOWANCES_CHARGES, $idx, $ac); |
|
| 111 | - $this->set(self::COL_ALLOWANCES_AMOUNT, $idx, $itemAllowancesAmount); |
|
| 112 | - $this->set(self::COL_CHARGES_AMOUNT, $idx, $itemChargesAmount); |
|
| 113 | - $this->set(self::COL_ITEM_BILLABLE_AMOUNT,$idx, $itemBillableAmount); |
|
| 110 | + $this->set(self::COL_ALLOWANCES_CHARGES, $idx, $ac); |
|
| 111 | + $this->set(self::COL_ALLOWANCES_AMOUNT, $idx, $itemAllowancesAmount); |
|
| 112 | + $this->set(self::COL_CHARGES_AMOUNT, $idx, $itemChargesAmount); |
|
| 113 | + $this->set(self::COL_ITEM_BILLABLE_AMOUNT, $idx, $itemBillableAmount); |
|
| 114 | 114 | $this->set(self::COL_ITEM_TAXABLE_AMOUNT, $idx, $itemTaxableAmount); |
| 115 | - $this->set(self::COL_IGV, $idx, $igvAmount); |
|
| 115 | + $this->set(self::COL_IGV, $idx, $igvAmount); |
|
| 116 | 116 | $this->set(self::COL_ITEM_PAYABLE_AMOUNT, $idx, $itemPayableAmount); |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | $this->documentNumber = str_pad($rawData['documentNumber'], 5, '0', STR_PAD_LEFT); |
| 38 | 38 | $this->issueDate = new DateTime($parsedData['issueDate']); |
| 39 | 39 | $this->referenceDate = new DateTime($parsedData['referenceDate']); |
| 40 | - $this->documentId = $this->documentType.'-' . $this->issueDate->format('Ymd') . '-' . $this->documentNumber; |
|
| 40 | + $this->documentId = $this->documentType . '-' . $this->issueDate->format('Ymd') . '-' . $this->documentNumber; |
|
| 41 | 41 | $this->documentFileName = Company::getRUC() . '-' . $this->documentId; |
| 42 | 42 | $this->rawData = $rawData; |
| 43 | 43 | $this->parsedData = $parsedData; |
@@ -111,21 +111,21 @@ discard block |
||
| 111 | 111 | $name = str_replace('\\', '/', $name);
|
| 112 | 112 | $hexdtime = pack('V', $this->unix2DosTime($time));
|
| 113 | 113 | $fr = "\x50\x4b\x03\x04"; |
| 114 | - $fr .= "\x14\x00"; // ver needed to extract |
|
| 115 | - $fr .= "\x00\x00"; // gen purpose bit flag |
|
| 116 | - $fr .= "\x08\x00"; // compression method |
|
| 117 | - $fr .= $hexdtime; // last mod time and date |
|
| 114 | + $fr .= "\x14\x00"; // ver needed to extract |
|
| 115 | + $fr .= "\x00\x00"; // gen purpose bit flag |
|
| 116 | + $fr .= "\x08\x00"; // compression method |
|
| 117 | + $fr .= $hexdtime; // last mod time and date |
|
| 118 | 118 | // "local file header" segment |
| 119 | 119 | $unc_len = strlen($data); |
| 120 | 120 | $crc = crc32($data); |
| 121 | 121 | $zdata = gzcompress($data); |
| 122 | 122 | $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug |
| 123 | 123 | $c_len = strlen($zdata); |
| 124 | - $fr .= pack('V', $crc); // crc32
|
|
| 125 | - $fr .= pack('V', $c_len); // compressed filesize
|
|
| 126 | - $fr .= pack('V', $unc_len); // uncompressed filesize
|
|
| 127 | - $fr .= pack('v', strlen($name)); // length of filename
|
|
| 128 | - $fr .= pack('v', 0); // extra field length
|
|
| 124 | + $fr .= pack('V', $crc); // crc32
|
|
| 125 | + $fr .= pack('V', $c_len); // compressed filesize
|
|
| 126 | + $fr .= pack('V', $unc_len); // uncompressed filesize
|
|
| 127 | + $fr .= pack('v', strlen($name)); // length of filename
|
|
| 128 | + $fr .= pack('v', 0); // extra field length
|
|
| 129 | 129 | $fr .= $name; |
| 130 | 130 | // "file data" segment |
| 131 | 131 | $fr .= $zdata; |
@@ -137,20 +137,20 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | // now add to central directory record |
| 139 | 139 | $cdrec = "\x50\x4b\x01\x02"; |
| 140 | - $cdrec .= "\x00\x00"; // version made by |
|
| 141 | - $cdrec .= "\x14\x00"; // version needed to extract |
|
| 142 | - $cdrec .= "\x00\x00"; // gen purpose bit flag |
|
| 143 | - $cdrec .= "\x08\x00"; // compression method |
|
| 144 | - $cdrec .= $hexdtime; // last mod time & date |
|
| 145 | - $cdrec .= pack('V', $crc); // crc32
|
|
| 146 | - $cdrec .= pack('V', $c_len); // compressed filesize
|
|
| 147 | - $cdrec .= pack('V', $unc_len); // uncompressed filesize
|
|
| 140 | + $cdrec .= "\x00\x00"; // version made by |
|
| 141 | + $cdrec .= "\x14\x00"; // version needed to extract |
|
| 142 | + $cdrec .= "\x00\x00"; // gen purpose bit flag |
|
| 143 | + $cdrec .= "\x08\x00"; // compression method |
|
| 144 | + $cdrec .= $hexdtime; // last mod time & date |
|
| 145 | + $cdrec .= pack('V', $crc); // crc32
|
|
| 146 | + $cdrec .= pack('V', $c_len); // compressed filesize
|
|
| 147 | + $cdrec .= pack('V', $unc_len); // uncompressed filesize
|
|
| 148 | 148 | $cdrec .= pack('v', strlen($name)); // length of filename
|
| 149 | - $cdrec .= pack('v', 0); // extra field length
|
|
| 150 | - $cdrec .= pack('v', 0); // file comment length
|
|
| 151 | - $cdrec .= pack('v', 0); // disk number start
|
|
| 152 | - $cdrec .= pack('v', 0); // internal file attributes
|
|
| 153 | - $cdrec .= pack('V', 32); // external file attributes
|
|
| 149 | + $cdrec .= pack('v', 0); // extra field length
|
|
| 150 | + $cdrec .= pack('v', 0); // file comment length
|
|
| 151 | + $cdrec .= pack('v', 0); // disk number start
|
|
| 152 | + $cdrec .= pack('v', 0); // internal file attributes
|
|
| 153 | + $cdrec .= pack('V', 32); // external file attributes
|
|
| 154 | 154 | // - 'archive' bit set |
| 155 | 155 | $cdrec .= pack('V', $this->old_offset); // relative offset of local header
|
| 156 | 156 | $this->old_offset += strlen($fr); |
@@ -176,10 +176,10 @@ discard block |
||
| 176 | 176 | pack('v', sizeof($this->ctrl_dir)) . //total #of entries overall
|
| 177 | 177 | pack('V', strlen($ctrldir)) . //size of central dir
|
| 178 | 178 | pack('V', $this->old_offset) . //offset to start of central dir
|
| 179 | - "\x00\x00"; //.zip file comment length |
|
| 179 | + "\x00\x00"; //.zip file comment length |
|
| 180 | 180 | if ($this->doWrite) { // Send central directory & end ctrl dir to STDOUT
|
| 181 | 181 | echo $header; |
| 182 | - return ""; // Return empty string |
|
| 182 | + return ""; // Return empty string |
|
| 183 | 183 | } else { // Return entire ZIP archive as string
|
| 184 | 184 | $data = implode('', $this->datasec);
|
| 185 | 185 | return $data . $header; |
@@ -104,14 +104,14 @@ discard block |
||
| 104 | 104 | 'igvPercent' => SunatVars::IGV_PERCENT, |
| 105 | 105 | 'logo' => LogoMgr::getLogoString(), |
| 106 | 106 | 'qr' => QrGenerator::getQrString($inv), // QR Code |
| 107 | - 'taxableOperations' => $inv->getTotalTaxableOperations(), // Total operaciones gravadas |
|
| 108 | - 'freeOperations' => $inv->getTotalFreeOperations(), // Total operaciones gratuitas |
|
| 107 | + 'taxableOperations' => $inv->getTotalTaxableOperations(), // Total operaciones gravadas |
|
| 108 | + 'freeOperations' => $inv->getTotalFreeOperations(), // Total operaciones gratuitas |
|
| 109 | 109 | 'unaffectedOperations' => $inv->getTotalUnaffectedOperations(), // Total operaciones inafectas |
| 110 | - 'exemptedOperations' => $inv->getTotalExemptedOperations(), // Total operaciones exoneradas |
|
| 111 | - 'totalAllowances' => $inv->getTotalAllowances(), // Total operaciones exoneradas |
|
| 112 | - 'igvAmount' => $inv->getIGV(), // Total a pagar |
|
| 113 | - 'payableAmount' => $payableAmount, // Total a pagar |
|
| 114 | - 'payableInWords' => $payableInWords, // Monto en palabras |
|
| 110 | + 'exemptedOperations' => $inv->getTotalExemptedOperations(), // Total operaciones exoneradas |
|
| 111 | + 'totalAllowances' => $inv->getTotalAllowances(), // Total operaciones exoneradas |
|
| 112 | + 'igvAmount' => $inv->getIGV(), // Total a pagar |
|
| 113 | + 'payableAmount' => $payableAmount, // Total a pagar |
|
| 114 | + 'payableInWords' => $payableInWords, // Monto en palabras |
|
| 115 | 115 | 'items' => self::getDocumentDataItems($inv) // Items |
| 116 | 116 | ]; |
| 117 | 117 | // For credit and debit notes |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $ln = $Items->getCount(); |
| 135 | 135 | $items2 = []; |
| 136 | 136 | for ($i = 0; $i < $ln; $i++) { |
| 137 | - $items2[]= [ |
|
| 137 | + $items2[] = [ |
|
| 138 | 138 | 'productCode' => $Items->getProductCode($i), |
| 139 | 139 | 'quantity' => $Items->getQunatity($i), |
| 140 | 140 | 'unitName' => Catalogo::getUnitName($Items->getUnitCode($i)), |