|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * Ejemplos de Impuestos Locales por Referencias |
| 6 | + * |
| 7 | + * Este archivo contiene ejemplos de cómo crear facturas de ingreso con complemento |
| 8 | + * de impuestos locales, usando referencias (IDs de personas e items existentes). |
| 9 | + * Incluye 3 variantes: CEDULAR + ISH, solo CEDULAR, solo ISH. |
| 10 | + */ |
| 11 | + |
| 12 | +use Fiscalapi\Http\FiscalApiHttpResponseInterface; |
| 13 | +use Fiscalapi\Http\FiscalApiSettings; |
| 14 | +use Fiscalapi\Services\FiscalApiClient; |
| 15 | + |
| 16 | +require_once __DIR__ . '/../vendor/autoload.php'; |
| 17 | + |
| 18 | + |
| 19 | +// Crea las configuraciones del cliente http fiscalapi. |
| 20 | +$settings = new FiscalApiSettings( |
| 21 | + 'https://test.fiscalapi.com', |
| 22 | + '<apiKey>', |
| 23 | + '<tenant>', |
| 24 | + false, |
| 25 | + false, |
| 26 | +); |
| 27 | + |
| 28 | +// IDs de personas previamente registradas en FiscalAPI |
| 29 | +$escuelaKemperUrgateId = "0e82a655-5f0c-4e07-abab-8f322e4123ef"; |
| 30 | +$karlaFuenteNolascoId = "da71df0c-f328-45ee-9bd9-3096ed02c164"; |
| 31 | + |
| 32 | +// Definir la fecha actual |
| 33 | +$currentDate = getCurrentDate(); |
| 34 | + |
| 35 | +// Crear cliente HTTP |
| 36 | +$client = new FiscalApiClient($settings); |
| 37 | + |
| 38 | + |
| 39 | +try { |
| 40 | + |
| 41 | + // ================================================================== |
| 42 | + // FACTURA DE INGRESO CON IMPUESTOS LOCALES (CEDULAR + ISH) POR REFERENCIAS |
| 43 | + // ================================================================== |
| 44 | + |
| 45 | + // ------------------------------------------------------------------ |
| 46 | + // Crear factura de ingreso con impuesto CEDULAR + ISH por referencias |
| 47 | + // ------------------------------------------------------------------ |
| 48 | + // $invoiceWithLocalTaxes = [ |
| 49 | + // 'versionCode' => "4.0", |
| 50 | + // 'series' => "F", |
| 51 | + // 'date' => $currentDate, |
| 52 | + // 'paymentFormCode' => "01", |
| 53 | + // 'paymentConditions' => "Contado", |
| 54 | + // 'currencyCode' => "MXN", |
| 55 | + // 'typeCode' => "I", |
| 56 | + // 'expeditionZipCode' => "42501", |
| 57 | + // 'paymentMethodCode' => "PUE", |
| 58 | + // 'exchangeRate' => 1.0, |
| 59 | + // 'exportCode' => "01", |
| 60 | + // 'issuer' => [ |
| 61 | + // 'id' => $karlaFuenteNolascoId |
| 62 | + // ], |
| 63 | + // 'recipient' => [ |
| 64 | + // 'id' => $escuelaKemperUrgateId |
| 65 | + // ], |
| 66 | + // 'items' => [ |
| 67 | + // ['id' => "2f3c65f3-ed02-452f-944c-97a47010df5c"], |
| 68 | + // ['id' => "037b5705-a9a2-4422-b842-97c0f9347498"], |
| 69 | + // ['id' => "40389443-2aa1-4121-b86a-e8c45fac6b17"] |
| 70 | + // ], |
| 71 | + // // Complemento de impuestos locales |
| 72 | + // 'complement' => [ |
| 73 | + // 'localTaxes' => [ |
| 74 | + // 'taxes' => [ |
| 75 | + // [ |
| 76 | + // 'taxName' => "CEDULAR", |
| 77 | + // 'taxRate' => 3.00, |
| 78 | + // 'taxAmount' => 6.00, |
| 79 | + // 'taxFlagCode' => "R" |
| 80 | + // ], |
| 81 | + // [ |
| 82 | + // 'taxName' => "ISH", |
| 83 | + // 'taxRate' => 8.00, |
| 84 | + // 'taxAmount' => 16.00, |
| 85 | + // 'taxFlagCode' => "R" |
| 86 | + // ] |
| 87 | + // ] |
| 88 | + // ] |
| 89 | + // ] |
| 90 | + // ]; |
| 91 | + // $apiResponse = $client->getInvoiceService()->create($invoiceWithLocalTaxes); |
| 92 | + // consoleLog($apiResponse); |
| 93 | + |
| 94 | + |
| 95 | + // ================================================================== |
| 96 | + // FACTURA DE INGRESO CON IMPUESTO CEDULAR (SOLO) POR REFERENCIAS |
| 97 | + // ================================================================== |
| 98 | + |
| 99 | + // ------------------------------------------------------------------ |
| 100 | + // Crear factura de ingreso con impuesto CEDULAR por referencias |
| 101 | + // ------------------------------------------------------------------ |
| 102 | + // $invoiceWithCedular = [ |
| 103 | + // 'versionCode' => "4.0", |
| 104 | + // 'series' => "F", |
| 105 | + // 'date' => $currentDate, |
| 106 | + // 'paymentFormCode' => "01", |
| 107 | + // 'paymentConditions' => "Contado", |
| 108 | + // 'currencyCode' => "MXN", |
| 109 | + // 'typeCode' => "I", |
| 110 | + // 'expeditionZipCode' => "42501", |
| 111 | + // 'paymentMethodCode' => "PUE", |
| 112 | + // 'exchangeRate' => 1.0, |
| 113 | + // 'exportCode' => "01", |
| 114 | + // 'issuer' => [ |
| 115 | + // 'id' => $karlaFuenteNolascoId |
| 116 | + // ], |
| 117 | + // 'recipient' => [ |
| 118 | + // 'id' => $escuelaKemperUrgateId |
| 119 | + // ], |
| 120 | + // 'items' => [ |
| 121 | + // ['id' => "2f3c65f3-ed02-452f-944c-97a47010df5c"], |
| 122 | + // ['id' => "037b5705-a9a2-4422-b842-97c0f9347498"], |
| 123 | + // ['id' => "40389443-2aa1-4121-b86a-e8c45fac6b17"] |
| 124 | + // ], |
| 125 | + // // Complemento de impuestos locales (solo CEDULAR) |
| 126 | + // 'complement' => [ |
| 127 | + // 'localTaxes' => [ |
| 128 | + // 'taxes' => [ |
| 129 | + // [ |
| 130 | + // 'taxName' => "CEDULAR", |
| 131 | + // 'taxRate' => 3.00, |
| 132 | + // 'taxAmount' => 6.00, |
| 133 | + // 'taxFlagCode' => "R" |
| 134 | + // ] |
| 135 | + // ] |
| 136 | + // ] |
| 137 | + // ] |
| 138 | + // ]; |
| 139 | + // $apiResponse = $client->getInvoiceService()->create($invoiceWithCedular); |
| 140 | + // consoleLog($apiResponse); |
| 141 | + |
| 142 | + |
| 143 | + // ================================================================== |
| 144 | + // FACTURA DE INGRESO CON IMPUESTO ISH (SOLO) POR REFERENCIAS |
| 145 | + // ================================================================== |
| 146 | + |
| 147 | + // ------------------------------------------------------------------ |
| 148 | + // Crear factura de ingreso con impuesto ISH por referencias |
| 149 | + // ------------------------------------------------------------------ |
| 150 | + // $invoiceWithIsh = [ |
| 151 | + // 'versionCode' => "4.0", |
| 152 | + // 'series' => "F", |
| 153 | + // 'date' => $currentDate, |
| 154 | + // 'paymentFormCode' => "01", |
| 155 | + // 'paymentConditions' => "Contado", |
| 156 | + // 'currencyCode' => "MXN", |
| 157 | + // 'typeCode' => "I", |
| 158 | + // 'expeditionZipCode' => "42501", |
| 159 | + // 'paymentMethodCode' => "PUE", |
| 160 | + // 'exchangeRate' => 1.0, |
| 161 | + // 'exportCode' => "01", |
| 162 | + // 'issuer' => [ |
| 163 | + // 'id' => $karlaFuenteNolascoId |
| 164 | + // ], |
| 165 | + // 'recipient' => [ |
| 166 | + // 'id' => $escuelaKemperUrgateId |
| 167 | + // ], |
| 168 | + // 'items' => [ |
| 169 | + // ['id' => "2f3c65f3-ed02-452f-944c-97a47010df5c"], |
| 170 | + // ['id' => "037b5705-a9a2-4422-b842-97c0f9347498"], |
| 171 | + // ['id' => "40389443-2aa1-4121-b86a-e8c45fac6b17"] |
| 172 | + // ], |
| 173 | + // // Complemento de impuestos locales (solo ISH) |
| 174 | + // 'complement' => [ |
| 175 | + // 'localTaxes' => [ |
| 176 | + // 'taxes' => [ |
| 177 | + // [ |
| 178 | + // 'taxName' => "ISH", |
| 179 | + // 'taxRate' => 8.00, |
| 180 | + // 'taxAmount' => 16.00, |
| 181 | + // 'taxFlagCode' => "R" |
| 182 | + // ] |
| 183 | + // ] |
| 184 | + // ] |
| 185 | + // ] |
| 186 | + // ]; |
| 187 | + // $apiResponse = $client->getInvoiceService()->create($invoiceWithIsh); |
| 188 | + // consoleLog($apiResponse); |
| 189 | + |
| 190 | + |
| 191 | +} catch (\Exception $e) { |
| 192 | + consoleError($e); |
| 193 | +} |
| 194 | + |
| 195 | +function consoleLog(FiscalApiHttpResponseInterface $apiResponse) { |
| 196 | + echo "apiResponse:\n" . json_encode($apiResponse->getJson(), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n"; |
| 197 | +} |
| 198 | + |
| 199 | +function consoleError(\Exception $e) { |
| 200 | + echo "Error en la ejecución: " . $e->getMessage() . "\n"; |
| 201 | + echo "Traza: " . $e->getTraceAsString() . "\n"; |
| 202 | +} |
| 203 | + |
| 204 | +/** |
| 205 | + * Obtiene la fecha y hora actual en la zona horaria de México Central |
| 206 | + */ |
| 207 | +function getCurrentDate(): string { |
| 208 | + date_default_timezone_set('Etc/GMT+6'); |
| 209 | + return date('Y-m-d\TH:i:s'); |
| 210 | +} |
0 commit comments