Conditions | 3 |
Paths | 4 |
Total Lines | 105 |
Code Lines | 87 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
169 | private function addInvoiceItem($itemIndex) { |
||
170 | |||
171 | // XML Nodes |
||
172 | $InvoiceLine = new InvoiceLine(); |
||
173 | $PricingReference = new PricingReference(); |
||
174 | $TaxTotal = new TaxTotal(); |
||
175 | $TaxSubTotal = new TaxSubTotal(); |
||
176 | $TaxCategory = new TaxCategory(); |
||
177 | $TaxCategory |
||
178 | ->setElementAttributes('ID', [ |
||
179 | 'schemeID' => 'UN/ECE 5305', |
||
180 | 'schemeName' => 'Tax Category Identifier', |
||
181 | 'schemeAgencyName' => 'United Nations Economic Commission for Europe']) |
||
182 | ->setElementAttributes('TaxExemptionReasonCode', [ |
||
183 | 'listAgencyName' => 'PE:SUNAT', |
||
184 | 'listName' => 'SUNAT:Codigo de Tipo de Afectación del IGV', |
||
185 | 'listURI' => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo07']); |
||
186 | |||
187 | $TaxScheme = new TaxScheme(); |
||
188 | $TaxScheme |
||
189 | ->setElementAttributes('ID', [ |
||
190 | 'schemeID' => 'UN/ECE 5153', |
||
191 | 'schemeName' => 'Tax Scheme Identifier', |
||
192 | 'schemeAgencyName' => 'United Nations Economic Commission for Europe']); |
||
193 | |||
194 | $AlternativeConditionPrice = new AlternativeConditionPrice(); |
||
195 | $Item = new Item(); |
||
196 | $SellersItemIdentification = new SellersItemIdentification(); |
||
197 | $CommodityClassification = new CommodityClassification(); |
||
198 | $Price = new Price(); |
||
199 | // Detail Operation Matrix |
||
200 | $Items = $this->invoiceDocument->getItems(); |
||
201 | // Vars |
||
202 | $productCode = $Items->getProductCode($itemIndex); |
||
203 | $sunatProductCode = $Items->getUNPSC($itemIndex); |
||
204 | $unitCode = $Items->getUnitCode($itemIndex); |
||
205 | $quantity = $Items->getQunatity($itemIndex); |
||
206 | $description = $Items->getDescription($itemIndex); |
||
207 | $currencyID = $Items->getCurrencyCode($itemIndex); |
||
208 | $unitBillableValue = $Items->getUnitBillableValue($itemIndex); |
||
209 | $priceTypeCode = $Items->getPriceTypeCode($itemIndex); |
||
210 | $taxTypeCode = $Items->getTaxTypeCode($itemIndex); |
||
211 | $igvAffectationCode = $Items->getIgvAffectationCode($itemIndex); |
||
212 | |||
213 | $itemValue = $Items->getItemValue($itemIndex); |
||
214 | $allowances = $Items->getAllowances($itemIndex); |
||
215 | $charges = $Items->getCharges($itemIndex); |
||
216 | $itemTaxableAmount = $Items->getTaxableAmount($itemIndex); |
||
217 | $itemTaxAmount = $Items->getIgv($itemIndex); |
||
218 | $unitPrice = $Items->getUnitTaxedValue($itemIndex); |
||
219 | |||
220 | // Catálogo 5 Ipuesto aplicable |
||
221 | $cat5Item = Catalogo::getCatItem(5, $taxTypeCode); |
||
222 | |||
223 | // Descuentos |
||
224 | foreach ($allowances as $item) { |
||
225 | $multFactor = $item['multiplierFactor']; |
||
226 | $amount = $itemValue * $multFactor; |
||
227 | UblHelper::addAllowanceCharge($InvoiceLine, $currencyID, 'false', $item['reasonCode'], $multFactor, $amount, $itemValue); |
||
228 | } |
||
229 | // Cargos |
||
230 | foreach ($charges as $item) { |
||
231 | $multFactor = $item['multiplierFactor']; |
||
232 | $amount = $itemValue * $multFactor; |
||
233 | UblHelper::addAllowanceCharge($InvoiceLine, $currencyID, 'true', $item['reasonCode'], $multFactor, $amount, $itemValue); |
||
234 | } |
||
235 | |||
236 | $InvoiceLine |
||
237 | ->setCurrencyID($currencyID) // Tipo de moneda |
||
238 | ->setID($itemIndex + 1) // Número de orden |
||
239 | ->setUnitCode($unitCode) // Codigo de unidad de medida |
||
240 | ->setInvoicedQuantity($quantity) // Cantidad |
||
241 | ->setLineExtensionAmount($itemTaxableAmount) // Valor de venta del ítem, sin impuestos |
||
242 | ->setPricingReference($PricingReference |
||
243 | ->setAlternativeConditionPrice($AlternativeConditionPrice |
||
244 | ->setCurrencyID($currencyID) // Tipo de moneda |
||
245 | ->setPriceAmount($unitPrice) // Precio de venta unitario |
||
246 | ->setPriceTypeCode($priceTypeCode))) // Price |
||
247 | ->setTaxTotal($TaxTotal |
||
248 | ->setCurrencyID($currencyID) |
||
249 | ->setTaxAmount($itemTaxAmount) |
||
250 | ->addTaxSubTotal($TaxSubTotal |
||
251 | ->setCurrencyID($currencyID) // Tipo de moneda |
||
252 | ->setTaxableAmount($itemTaxableAmount) // Valor de venta del item sin impuestos |
||
253 | ->setTaxAmount($itemTaxAmount) // IGV |
||
254 | ->setTaxCategory($TaxCategory |
||
255 | ->setID($cat5Item['categoria']) // Codigo de categoria de immpuestos @CAT5 |
||
256 | ->setPercent(SunatVars::IGV_PERCENT) // Porcentaje de IGV (18.00) |
||
257 | ->setTaxExemptionReasonCode($igvAffectationCode) // Código de afectación del IGV |
||
258 | ->setTaxScheme($TaxScheme |
||
259 | ->setID($taxTypeCode) // Codigo de categoria de impuesto |
||
260 | ->setName($cat5Item['name']) |
||
261 | ->setTaxTypeCode($cat5Item['UN_ECE_5153']))))) |
||
262 | ->setItem($Item |
||
263 | ->setDescription($description) // Descripción |
||
264 | ->setSellersItemIdentification($SellersItemIdentification |
||
265 | ->setID($productCode)) // Código de producto |
||
266 | ->setCommodityClassification($CommodityClassification |
||
267 | ->setItemClassificationCode($sunatProductCode))) // Código de producto SUNAT |
||
268 | ->setPrice($Price |
||
269 | ->setCurrencyID($currencyID) // Tipo de moneda |
||
270 | ->setPriceAmount($unitBillableValue) // Precio unitario del item |
||
271 | ); |
||
272 | // Añade item |
||
273 | $this->addInvoiceLine($InvoiceLine); |
||
274 | } |
||
363 |