| Conditions | 7 |
| Paths | 30 |
| Total Lines | 99 |
| Code Lines | 84 |
| 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 |
||
| 31 | private static function generateFSTextInput(InvoiceDocument $Invoice, $companyRUC) {
|
||
| 32 | $issueDate = $Invoice->getIssueDate(); |
||
| 33 | $Items = $Invoice->getItems(); |
||
| 34 | $json = [ |
||
| 35 | 'cabecera' => [ |
||
| 36 | 'tipOperacion' => $Invoice->getOperationType(), |
||
| 37 | 'fecEmision' => $issueDate->format('Y-m-d'),
|
||
| 38 | 'horEmision' => $issueDate->format('H:i:s'),
|
||
| 39 | 'fecVencimiento' => '-', |
||
| 40 | 'codLocalEmisor' => Company::getRegAddressCode(), |
||
| 41 | 'tipDocUsuario' => $Invoice->getCustomerDocType(), |
||
| 42 | 'numDocUsuario' => $Invoice->getCustomerDocNumber(), |
||
| 43 | 'rznSocialUsuario' => $Invoice->getCustomerRegName(), |
||
| 44 | 'tipMoneda' => $Invoice->getCurrencyType(), |
||
| 45 | |||
| 46 | 'sumTotTributos' => Operations::formatAmount($Invoice->getTotalTaxes()), |
||
| 47 | 'sumTotValVenta' => Operations::formatAmount($Invoice->getBillableValue()), |
||
| 48 | 'sumPrecioVenta' => Operations::formatAmount($Invoice->getPayableAmount()), |
||
| 49 | 'sumDescTotal' => Operations::formatAmount($Invoice->getTotalAllowances()), |
||
| 50 | 'sumOtrosCargos' => 0.00, |
||
| 51 | 'sumTotalAnticipos' => 0.00, |
||
| 52 | 'sumImpVenta' => Operations::formatAmount($Invoice->getPayableAmount()), |
||
| 53 | |||
| 54 | 'ublVersionId' => '2.1', |
||
| 55 | 'customizationId' => '2.0' |
||
| 56 | ], |
||
| 57 | 'detalle' => [], |
||
| 58 | 'variablesGlobales' => self::getVariablesGlobales($Invoice) |
||
| 59 | ]; |
||
| 60 | $ln = $Items->getCount(); |
||
| 61 | for ($rowIndex = 0; $rowIndex < $ln; $rowIndex++) {
|
||
| 62 | $cat5Item = Catalogo::getCatItem(5, $Items->getTaxTypeCode($rowIndex)); |
||
| 63 | // IGV percent |
||
| 64 | if($cat5Item['id'] === Catalogo::CAT5_IGV){
|
||
| 65 | $porIgvItem = Operations::formatAmount(SunatVars::IGV_PERCENT); |
||
| 66 | }else{
|
||
| 67 | $porIgvItem = '0.00'; |
||
| 68 | } |
||
| 69 | if ($Items->getPriceTypeCode($rowIndex) === Catalogo::CAT16_REF_VALUE) {
|
||
| 70 | $mtoPrecioVentaUnitario = '0.00'; |
||
| 71 | $mtoValorReferencialUnitario = Operations::formatAmount($Items->getUnitValue($rowIndex)); |
||
| 72 | } else {
|
||
| 73 | $mtoPrecioVentaUnitario = Operations::formatAmount($Items->getUnitTaxedValue($rowIndex)); |
||
| 74 | $mtoValorReferencialUnitario = '0.00'; |
||
| 75 | } |
||
| 76 | $item = [ |
||
| 77 | 'codUnidadMedida' => $Items->getUnitCode($rowIndex), |
||
| 78 | 'ctdUnidadItem' => $Items->getQunatity($rowIndex), |
||
| 79 | 'codProducto' => $Items->getProductCode($rowIndex), |
||
| 80 | 'codProductoSUNAT' => $Items->getUNPSC($rowIndex), |
||
| 81 | 'desItem' => $Items->getDescription($rowIndex), |
||
| 82 | 'mtoValorUnitario' => Operations::formatAmount($Items->getUnitBillableValue($rowIndex)), |
||
| 83 | 'sumTotTributosItem' => Operations::formatAmount($Items->getIgv($rowIndex)), |
||
| 84 | 'codTriIGV' => $Items->getTaxTypeCode($rowIndex), |
||
| 85 | 'mtoIgvItem' => Operations::formatAmount($Items->getIgv($rowIndex)), |
||
| 86 | 'mtoBaseIgvItem' => Operations::formatAmount($Items->getTaxableAmount($rowIndex)), |
||
| 87 | 'nomTributoIgvItem' => $cat5Item['name'], |
||
| 88 | 'codTipTributoIgvItem' => $cat5Item['UN_ECE_5153'], |
||
| 89 | 'tipAfeIGV' => $Items->getIgvAffectationCode($rowIndex), |
||
| 90 | 'porIgvItem' => $porIgvItem, |
||
| 91 | 'codTriISC' => '-', |
||
| 92 | 'mtoIscItem' => '0.00', |
||
| 93 | 'mtoBaseIscItem' => '0.00', |
||
| 94 | 'nomTributoIscItem' => '0.00', |
||
| 95 | 'codTipTributoIscItem' => '0.00', |
||
| 96 | 'tipSisISC' => '0.00', |
||
| 97 | 'porIscItem' => '0.00', |
||
| 98 | 'codTriOtroItem' => '-', |
||
| 99 | 'mtoTriOtroItem' => '0.00', |
||
| 100 | 'mtoBaseTriOtroItem' => '0.00', |
||
| 101 | 'nomTributoIOtroItem' => '0.00', |
||
| 102 | 'codTipTributoIOtroItem' => '0.00', |
||
| 103 | 'porTriOtroItem' => '0.00', |
||
| 104 | 'mtoPrecioVentaUnitario' => $mtoPrecioVentaUnitario, |
||
| 105 | 'mtoValorVentaItem' => Operations::formatAmount($Items->getItemBillableValue($rowIndex)), |
||
| 106 | 'mtoValorReferencialUnitario' => $mtoValorReferencialUnitario, |
||
| 107 | ]; |
||
| 108 | $json['detalle'][] = $item; |
||
| 109 | } |
||
| 110 | // Line jump |
||
| 111 | $ENTER = chr(13) . chr(10); |
||
| 112 | $cabContent = implode('|', $json['cabecera']);
|
||
| 113 | |||
| 114 | $detContent = ''; |
||
| 115 | for ($rowIndex = 0; $rowIndex < $ln; $rowIndex++) {
|
||
| 116 | $detContent .= implode('|', $json['detalle'][$rowIndex]) . $ENTER;
|
||
| 117 | } |
||
| 118 | $voucherId = $Invoice->getVoucherId(); |
||
| 119 | $invoiceType = $Invoice->getInvoiceType(); |
||
| 120 | self::writeFSFile("$companyRUC-$invoiceType-$voucherId.CAB", $cabContent);
|
||
| 121 | self::writeFSFile("$companyRUC-$invoiceType-$voucherId.DET", $detContent);
|
||
| 122 | //CABECERA VARIABLE |
||
| 123 | if(!empty($json['variablesGlobales'])){
|
||
| 124 | $glovalVars = $json['variablesGlobales']; |
||
| 125 | $varGlobalContent = ''; |
||
| 126 | foreach ($glovalVars as $row) {
|
||
| 127 | $varGlobalContent .= implode('|', $row) . $ENTER;
|
||
| 128 | } |
||
| 129 | self::writeFSFile("$companyRUC-$invoiceType-$voucherId.ACV", $varGlobalContent);
|
||
| 130 | } |
||
| 177 |