How to use std class

Best Atoum code snippet using std

Make.php

Source:Make.php Github

copy

Full Screen

...17use NFePHP\Common\Keys;18use NFePHP\Common\DOMImproved as Dom;19use NFePHP\Common\Strings;20use NFePHP\NFe\Common\Gtin;21use stdClass;22use RuntimeException;23use InvalidArgumentException;24use DOMElement;25use DateTime;26class Make27{28 /**29 * @var array30 */31 public $errors = [];32 /**33 * @var string34 */35 public $chNFe;36 /**37 * @var string38 */39 public $xml;40 /**41 * @var string42 */43 protected $version;44 /**45 * @var integer46 */47 protected $mod = 55;48 /**49 * @var \NFePHP\Common\DOMImproved50 */51 public $dom;52 /**53 * @var integer54 */55 protected $tpAmb = 2;56 /**57 * @var DOMElement58 */59 protected $NFe;60 /**61 * @var DOMElement62 */63 protected $infNFe;64 /**65 * @var DOMElement66 */67 protected $ide;68 /**69 * @var DOMElement70 */71 protected $emit;72 /**73 * @var DOMElement74 */75 protected $enderEmit;76 /**77 * @var DOMElement78 */79 protected $dest;80 /**81 * @var DOMElement82 */83 protected $enderDest;84 /**85 * @var DOMElement86 */87 protected $retirada;88 /**89 * @var DOMElement90 */91 protected $entrega;92 /**93 * @var DOMElement94 */95 protected $total;96 /**97 * @var DOMElement98 */99 protected $cobr;100 /**101 * @var DOMElement102 */103 protected $transp;104 /**105 * @var DOMElement106 */107 protected $infAdic;108 /**109 * @var DOMElement110 */111 protected $exporta;112 /**113 * @var DOMElement114 */115 protected $compra;116 /**117 * @var DOMElement118 */119 protected $cana;120 /**121 * @var DOMElement122 */123 protected $infNFeSupl;124 /**125 * @var array of DOMElements126 */127 protected $aNFref = [];128 /**129 * @var array of DOMElements130 */131 protected $aDup = [];132 /**133 * @var DOMElement134 */135 protected $pag;136 /**137 * @var array of DOMElements138 */139 protected $aDetPag = [];140 /**141 * @var array of DOMElements142 */143 protected $aReboque = [];144 /**145 * @var array of DOMElements146 */147 protected $aVol = [];148 /**149 * @var array of DOMElements150 */151 protected $aAutXML = [];152 /**153 * @var array of DOMElements154 */155 protected $aDet = [];156 /**157 * @var array of DOMElements158 */159 protected $aProd = [];160 /**161 * @var array of DOMElements162 */163 protected $aRastro = [];164 /**165 * @var array of DOMElements166 */167 protected $aNVE = [];168 /**169 * @var array of DOMElements170 */171 protected $aCest = [];172 /**173 * @var array of DOMElements174 */175 protected $aRECOPI = [];176 /**177 * @var array of DOMElements178 */179 protected $aDetExport = [];180 /**181 * @var array of DOMElements182 */183 protected $aDI = [];184 /**185 * @var array of DOMElements186 */187 protected $aAdi = [];188 /**189 * @var array of DOMElements190 */191 protected $aVeicProd = [];192 /**193 * @var array of DOMElements194 */195 protected $aMed = [];196 /**197 * @var array of DOMElements198 */199 protected $aArma = [];200 /**201 * @var array of DOMElements202 */203 protected $aComb = [];204 /**205 * @var array of DOMElements206 */207 protected $aEncerrante = [];208 /**209 * @var array of DOMElements210 */211 protected $aImposto = [];212 /**213 * @var array of DOMElements214 */215 protected $aICMS = [];216 /**217 * @var array of DOMElements218 */219 protected $aICMSUFDest = [];220 /**221 * @var array of DOMElements222 */223 protected $aIPI = [];224 /**225 * @var array of DOMElements226 */227 protected $aII = [];228 /**229 * @var array of DOMElements230 */231 protected $aISSQN = [];232 /**233 * @var array234 */235 protected $aPIS = [];236 /**237 * @var array of DOMElements238 */239 protected $aPISST = [];240 /**241 * @var array of DOMElements242 */243 protected $aCOFINS = [];244 /**245 * @var array of DOMElements246 */247 protected $aCOFINSST = [];248 /**249 * @var array of DOMElements250 */251 protected $aImpostoDevol = [];252 /**253 * @var array of DOMElements254 */255 protected $aInfAdProd = [];256 /**257 * @var array of DOMElements258 */259 protected $aObsCont = [];260 /**261 * @var array of DOMElements262 */263 protected $aObsFisco = [];264 /**265 * @var array of DOMElements266 */267 protected $aProcRef = [];268 /**269 * @var stdClass270 */271 protected $stdTot;272 /**273 * @var DOMElement274 */275 protected $infRespTec;276 /**277 * @var string278 */279 protected $csrt;280 /**281 * @var boolean282 */283 protected $replaceAccentedChars = false;284 /**285 * Função construtora cria um objeto DOMDocument286 * que será carregado com o documento fiscal287 */288 public function __construct()289 {290 $this->dom = new Dom('1.0', 'UTF-8');291 $this->dom->preserveWhiteSpace = false;292 $this->dom->formatOutput = false;293 //elemento totalizador294 $this->stdTot = new \stdClass();295 $this->stdTot->vBC = 0;296 $this->stdTot->vICMS = 0;297 $this->stdTot->vICMSDeson = 0;298 $this->stdTot->vFCP = 0;299 $this->stdTot->vFCPUFDest = 0;300 $this->stdTot->vICMSUFDest = 0;301 $this->stdTot->vICMSUFRemet = 0;302 $this->stdTot->vBCST = 0;303 $this->stdTot->vST = 0;304 $this->stdTot->vFCPST = 0;305 $this->stdTot->vFCPSTRet = 0;306 $this->stdTot->vProd = 0;307 $this->stdTot->vFrete = 0;308 $this->stdTot->vSeg = 0;309 $this->stdTot->vDesc = 0;310 $this->stdTot->vII = 0;311 $this->stdTot->vIPI = 0;312 $this->stdTot->vIPIDevol = 0;313 $this->stdTot->vPIS = 0;314 $this->stdTot->vCOFINS = 0;315 $this->stdTot->vOutro = 0;316 $this->stdTot->vNF = 0;317 $this->stdTot->vTotTrib = 0;318 }319 /**320 * Set character convertion to ASCII only ou not321 * @param bool $option322 */323 public function setOnlyAscii($option = false)324 {325 $this->replaceAccentedChars = $option;326 }327 /**328 * Returns xml string and assembly it is necessary329 * @return string330 */331 public function getXML()332 {333 if (empty($this->xml)) {334 $this->montaNFe();335 }336 return $this->xml;337 }338 /**339 * Retorns the key number of NFe (44 digits)340 * @return string341 */342 public function getChave()343 {344 return $this->chNFe;345 }346 /**347 * Returns the model of NFe 55 or 65348 * @return int349 */350 public function getModelo()351 {352 return $this->mod;353 }354 /**355 * Call method of xml assembly. For compatibility only.356 * @return string357 */358 public function montaNFe()359 {360 return $this->monta();361 }362 /**363 * NFe xml mount method364 * this function returns TRUE on success or FALSE on error365  * The xml of the NFe must be retrieved by the getXML() function or366 * directly by the public property $xml367 *368 * @return string369 * @throws RuntimeException370 */371 public function monta()372 {373 if (!empty($this->errors)) {374 $this->errors = array_merge($this->errors, $this->dom->errors);375 } else {376 $this->errors = $this->dom->errors;377 }378 //cria a tag raiz da Nfe379 $this->buildNFe();380 //processa nfeRef e coloca as tags na tag ide381 foreach ($this->aNFref as $nfeRef) {382 $this->dom->appChild($this->ide, $nfeRef, 'Falta tag "ide"');383 }384 //monta as tags det e coloca no array $this->aDet com os detalhes dos produtos385 $this->buildDet();386 //[2] tag ide (5 B01)387 $this->dom->appChild($this->infNFe, $this->ide, 'Falta tag "infNFe"');388 //[8] tag emit (30 C01)389 $this->dom->appChild($this->infNFe, $this->emit, 'Falta tag "infNFe"');390 //[10] tag dest (62 E01)391 $this->dom->appChild($this->infNFe, $this->dest, 'Falta tag "infNFe"');392 //[12] tag retirada (80 F01)393 $this->dom->appChild($this->infNFe, $this->retirada, 'Falta tag "infNFe"');394 //[13] tag entrega (89 G01)395 $this->dom->appChild($this->infNFe, $this->entrega, 'Falta tag "infNFe"');396 //[14] tag autXML (97a.1 G50)397 foreach ($this->aAutXML as $aut) {398 $this->dom->appChild($this->infNFe, $aut, 'Falta tag "infNFe"');399 }400 //[14a] tag det (98 H01)401 foreach ($this->aDet as $det) {402 $this->dom->appChild($this->infNFe, $det, 'Falta tag "infNFe"');403 }404 //[28a] tag total (326 W01)405 $this->dom->appChild($this->infNFe, $this->total, 'Falta tag "infNFe"');406 //mota a tag vol407 $this->buildVol();408 //[32] tag transp (356 X01)409 $this->dom->appChild($this->infNFe, $this->transp, 'Falta tag "infNFe"');410 //[39a] tag cobr (389 Y01)411 $this->dom->appChild($this->infNFe, $this->cobr, 'Falta tag "infNFe"');412 //[42] tag pag (398a YA01)413 //processa Pag e coloca as tags na tag pag414 $this->buildTagPag();415 //[44] tag infAdic (399 Z01)416 $this->dom->appChild($this->infNFe, $this->infAdic, 'Falta tag "infNFe"');417 //[48] tag exporta (402 ZA01)418 $this->dom->appChild($this->infNFe, $this->exporta, 'Falta tag "infNFe"');419 //[49] tag compra (405 ZB01)420 $this->dom->appChild($this->infNFe, $this->compra, 'Falta tag "infNFe"');421 //[50] tag cana (409 ZC01)422 $this->dom->appChild($this->infNFe, $this->cana, 'Falta tag "infNFe"');423 //Responsável Técnico424 $this->dom->appChild($this->infNFe, $this->infRespTec, 'Falta tag "infNFe"');425 //[1] tag infNFe (1 A01)426 $this->dom->appChild($this->NFe, $this->infNFe, 'Falta tag "NFe"');427 //[0] tag NFe428 $this->dom->appendChild($this->NFe);429 // testa da chave430 $this->checkNFeKey($this->dom);431 $this->xml = $this->dom->saveXML();432 if (count($this->errors) > 0) {433 throw new RuntimeException('Existem erros nas tags. Obtenha os erros com getErrors().');434 }435 return $this->xml;436 }437 /**438 * Informações da NF-e A01 pai NFe439 * tag NFe/infNFe440 * @param stdClass $std441 * @return DOMElement442 */443 public function taginfNFe(stdClass $std)444 {445 $possible = ['Id', 'versao', 'pk_nItem'];446 $std = $this->equilizeParameters($std, $possible);447 $chave = preg_replace('/[^0-9]/', '', $std->Id);448 $this->infNFe = $this->dom->createElement("infNFe");449 $this->infNFe->setAttribute("Id", 'NFe' . $chave);450 $this->infNFe->setAttribute(451 "versao",452 $std->versao453 );454 $this->version = $std->versao;455 if (!empty($std->pk_nItem)) {456 $this->infNFe->setAttribute("pk_nItem", $std->pk_nItem);457 }458 $this->chNFe = $chave;459 return $this->infNFe;460 }461 /**462 * Informações de identificação da NF-e B01 pai A01463 * NOTA: Ajustado para NT2016_002_v1.30464 * tag NFe/infNFe/ide465 * @param stdClass $std466 * @return DOMElement467 */468 public function tagide(stdClass $std)469 {470 $possible = [471 'cUF',472 'cNF',473 'natOp',474 'indPag',475 'mod',476 'serie',477 'nNF',478 'dhEmi',479 'dhSaiEnt',480 'tpNF',481 'idDest',482 'cMunFG',483 'tpImp',484 'tpEmis',485 'cDV',486 'tpAmb',487 'finNFe',488 'indFinal',489 'indPres',490 'procEmi',491 'verProc',492 'dhCont',493 'xJust'494 ];495 $std = $this->equilizeParameters($std, $possible);496 if (empty($std->cNF)) {497 $std->cNF = Keys::random($std->nNF);498 }499 if (empty($std->cDV)) {500 $std->cDV = 0;501 }502 //validação conforme NT 2019.001503 $std->cNF = str_pad($std->cNF, 8, '0', STR_PAD_LEFT);504 if (intval($std->cNF) == intval($std->nNF)) {505 throw new InvalidArgumentException("O valor [{$std->cNF}] não é "506 . "aceitável para cNF, não pode ser igual ao de nNF, vide NT2019.001");507 }508 if (method_exists(Keys::class, 'cNFIsValid')) {509 if (!Keys::cNFIsValid($std->cNF)) {510 throw new InvalidArgumentException("O valor [{$std->cNF}] para cNF "511 . "é invalido, deve respeitar a NT2019.001");512 }513 }514 $this->tpAmb = $std->tpAmb;515 $this->mod = $std->mod;516 $identificador = 'B01 <ide> - ';517 $ide = $this->dom->createElement("ide");518 $this->dom->addChild(519 $ide,520 "cUF",521 $std->cUF,522 true,523 $identificador . "Código da UF do emitente do Documento Fiscal"524 );525 $this->dom->addChild(526 $ide,527 "cNF",528 $std->cNF,529 true,530 $identificador . "Código Numérico que compõe a Chave de Acesso"531 );532 $this->dom->addChild(533 $ide,534 "natOp",535 substr(trim($std->natOp), 0, 60),536 true,537 $identificador . "Descrição da Natureza da Operação"538 );539 $this->dom->addChild(540 $ide,541 "mod",542 $std->mod,543 true,544 $identificador . "Código do Modelo do Documento Fiscal"545 );546 $this->dom->addChild(547 $ide,548 "serie",549 $std->serie,550 true,551 $identificador . "Série do Documento Fiscal"552 );553 $this->dom->addChild(554 $ide,555 "nNF",556 $std->nNF,557 true,558 $identificador . "Número do Documento Fiscal"559 );560 $this->dom->addChild(561 $ide,562 "dhEmi",563 $std->dhEmi,564 true,565 $identificador . "Data e hora de emissão do Documento Fiscal"566 );567 if ($std->mod == '55' && !empty($std->dhSaiEnt)) {568 $this->dom->addChild(569 $ide,570 "dhSaiEnt",571 $std->dhSaiEnt,572 false,573 $identificador . "Data e hora de Saída ou da Entrada da Mercadoria/Produto"574 );575 }576 $this->dom->addChild(577 $ide,578 "tpNF",579 $std->tpNF,580 true,581 $identificador . "Tipo de Operação"582 );583 $this->dom->addChild(584 $ide,585 "idDest",586 $std->idDest,587 true,588 $identificador . "Identificador de local de destino da operação"589 );590 $this->dom->addChild(591 $ide,592 "cMunFG",593 $std->cMunFG,594 true,595 $identificador . "Código do Município de Ocorrência do Fato Gerador"596 );597 $this->dom->addChild(598 $ide,599 "tpImp",600 $std->tpImp,601 true,602 $identificador . "Formato de Impressão do DANFE"603 );604 $this->dom->addChild(605 $ide,606 "tpEmis",607 $std->tpEmis,608 true,609 $identificador . "Tipo de Emissão da NF-e"610 );611 $this->dom->addChild(612 $ide,613 "cDV",614 !empty($std->cDV) ? $std->cDV : '0',615 true,616 $identificador . "Dígito Verificador da Chave de Acesso da NF-e"617 );618 $this->dom->addChild(619 $ide,620 "tpAmb",621 $std->tpAmb,622 true,623 $identificador . "Identificação do Ambiente"624 );625 $this->dom->addChild(626 $ide,627 "finNFe",628 $std->finNFe,629 true,630 $identificador . "Finalidade de emissão da NF-e"631 );632 $this->dom->addChild(633 $ide,634 "indFinal",635 $std->indFinal,636 true,637 $identificador . "Indica operação com Consumidor final"638 );639 $this->dom->addChild(640 $ide,641 "indPres",642 $std->indPres,643 true,644 $identificador . "Indicador de presença do comprador no estabelecimento comercial no momento da operação"645 );646 $this->dom->addChild(647 $ide,648 "procEmi",649 $std->procEmi,650 true,651 $identificador . "Processo de emissão da NF-e"652 );653 $this->dom->addChild(654 $ide,655 "verProc",656 $std->verProc,657 true,658 $identificador . "Versão do Processo de emissão da NF-e"659 );660 if (!empty($std->dhCont) && !empty($std->xJust)) {661 $this->dom->addChild(662 $ide,663 "dhCont",664 $std->dhCont,665 true,666 $identificador . "Data e Hora da entrada em contingência"667 );668 $this->dom->addChild(669 $ide,670 "xJust",671 substr(trim($std->xJust), 0, 256),672 true,673 $identificador . "Justificativa da entrada em contingência"674 );675 }676 $this->ide = $ide;677 return $ide;678 }679 /**680 * Chave de acesso da NF-e referenciada BA02 pai BA01681 * tag NFe/infNFe/ide/NFref/refNFe682 * @param stdClass $std683 * @return DOMElement684 */685 public function tagrefNFe(stdClass $std)686 {687 $possible = ['refNFe'];688 $std = $this->equilizeParameters($std, $possible);689 $num = $this->buildNFref();690 $refNFe = $this->dom->createElement("refNFe", $std->refNFe);691 $this->dom->appChild($this->aNFref[$num - 1], $refNFe);692 return $refNFe;693 }694 /**695 * Informação da NF modelo 1/1A referenciada BA03 pai BA01696 * tag NFe/infNFe/ide/NFref/NF DOMNode697 * @param stdClass $std698 * @return DOMElement699 */700 public function tagrefNF(stdClass $std)701 {702 $possible = ['cUF', 'AAMM', 'CNPJ', 'mod', 'serie', 'nNF'];703 $std = $this->equilizeParameters($std, $possible);704 $identificador = 'BA03 <refNF> - ';705 $num = $this->buildNFref();706 $refNF = $this->dom->createElement("refNF");707 $this->dom->addChild(708 $refNF,709 "cUF",710 $std->cUF,711 true,712 $identificador . "Código da UF do emitente"713 );714 $this->dom->addChild(715 $refNF,716 "AAMM",717 $std->AAMM,718 true,719 $identificador . "Ano e Mês de emissão da NF-e"720 );721 $this->dom->addChild(722 $refNF,723 "CNPJ",724 $std->CNPJ,725 true,726 $identificador . "CNPJ do emitente"727 );728 $this->dom->addChild(729 $refNF,730 "mod",731 $std->mod,732 true,733 $identificador . "Modelo do Documento Fiscal"734 );735 $this->dom->addChild(736 $refNF,737 "serie",738 $std->serie,739 true,740 $identificador . "Série do Documento Fiscal"741 );742 $this->dom->addChild(743 $refNF,744 "nNF",745 $std->nNF,746 true,747 $identificador . "Número do Documento Fiscal"748 );749 $this->dom->appChild($this->aNFref[$num - 1], $refNF);750 return $refNF;751 }752 /**753 * Informações da NF de produtor rural referenciada BA10 pai BA01754 * tag NFe/infNFe/ide/NFref/refNFP755 * @param stdClass $std756 * @return DOMElement757 */758 public function tagrefNFP(stdClass $std)759 {760 $possible = [761 'cUF',762 'AAMM',763 'CNPJ',764 'CPF',765 'IE',766 'mod',767 'serie',768 'nNF'769 ];770 $std = $this->equilizeParameters($std, $possible);771 $identificador = 'BA10 <refNFP> - ';772 $num = $this->buildNFref();773 $refNFP = $this->dom->createElement("refNFP");774 $this->dom->addChild(775 $refNFP,776 "cUF",777 $std->cUF,778 true,779 $identificador . "Código da UF do emitente"780 );781 $this->dom->addChild(782 $refNFP,783 "AAMM",784 $std->AAMM,785 true,786 $identificador . "AAMM da emissão da NF de produtor"787 );788 $this->dom->addChild(789 $refNFP,790 "CNPJ",791 $std->CNPJ,792 false,793 $identificador . "Informar o CNPJ do emitente da NF de produtor"794 );795 $this->dom->addChild(796 $refNFP,797 "CPF",798 $std->CPF,799 false,800 $identificador . "Informar o CPF do emitente da NF de produtor"801 );802 $this->dom->addChild(803 $refNFP,804 "IE",805 $std->IE,806 true,807 $identificador . "Informar a IE do emitente da NF de Produtor ou o literal 'ISENTO'"808 );809 $this->dom->addChild(810 $refNFP,811 "mod",812 str_pad($std->mod, 2, '0', STR_PAD_LEFT),813 true,814 $identificador . "Modelo do Documento Fiscal"815 );816 $this->dom->addChild(817 $refNFP,818 "serie",819 $std->serie,820 true,821 $identificador . "Série do Documento Fiscal"822 );823 $this->dom->addChild(824 $refNFP,825 "nNF",826 $std->nNF,827 true,828 $identificador . "Número do Documento Fiscal"829 );830 $this->dom->appChild($this->aNFref[$num - 1], $refNFP);831 return $refNFP;832 }833 /**834 * Chave de acesso do CT-e referenciada BA19 pai BA01835 * tag NFe/infNFe/ide/NFref/refCTe836 * @param stdClass $std837 * @return DOMElement838 */839 public function tagrefCTe(stdClass $std)840 {841 $possible = ['refCTe'];842 $std = $this->equilizeParameters($std, $possible);843 $num = $this->buildNFref();844 $refCTe = $this->dom->createElement("refCTe", $std->refCTe);845 $this->dom->appChild($this->aNFref[$num - 1], $refCTe);846 return $refCTe;847 }848 /**849 * Informações do Cupom Fiscal referenciado BA20 pai BA01850 * tag NFe/infNFe/ide/NFref/refECF851 * @param stdClass $std852 * @return DOMElement853 */854 public function tagrefECF(stdClass $std)855 {856 $possible = ['mod', 'nECF', 'nCOO'];857 $std = $this->equilizeParameters($std, $possible);858 $identificador = 'BA20 <refECF> - ';859 $num = $this->buildNFref();860 $refECF = $this->dom->createElement("refECF");861 $this->dom->addChild(862 $refECF,863 "mod",864 $std->mod,865 true,866 $identificador . "Modelo do Documento Fiscal"867 );868 $this->dom->addChild(869 $refECF,870 "nECF",871 str_pad($std->nECF, 3, '0', STR_PAD_LEFT),872 true,873 $identificador . "Número de ordem sequencial do ECF"874 );875 $this->dom->addChild(876 $refECF,877 "nCOO",878 str_pad($std->nCOO, 6, '0', STR_PAD_LEFT),879 true,880 $identificador . "Número do Contador de Ordem de Operação - COO"881 );882 $this->dom->appChild($this->aNFref[$num - 1], $refECF);883 return $refECF;884 }885 /**886 * Identificação do emitente da NF-e C01 pai A01887 * tag NFe/infNFe/emit888 * @param stdClass $std889 * @return DOMElement890 */891 public function tagemit(stdClass $std)892 {893 $possible = [894 'xNome',895 'xFant',896 'IE',897 'IEST',898 'IM',899 'CNAE',900 'CRT',901 'CNPJ',902 'CPF'903 ];904 $std = $this->equilizeParameters($std, $possible);905 $identificador = 'C01 <emit> - ';906 $this->emit = $this->dom->createElement("emit");907 if (!empty($std->CNPJ)) {908 $this->dom->addChild(909 $this->emit,910 "CNPJ",911 Strings::onlyNumbers($std->CNPJ),912 false,913 $identificador . "CNPJ do emitente"914 );915 } elseif (!empty($std->CPF)) {916 $this->dom->addChild(917 $this->emit,918 "CPF",919 Strings::onlyNumbers($std->CPF),920 false,921 $identificador . "CPF do remetente"922 );923 }924 $this->dom->addChild(925 $this->emit,926 "xNome",927 substr(trim($std->xNome), 0, 60),928 true,929 $identificador . "Razão Social ou Nome do emitente"930 );931 $this->dom->addChild(932 $this->emit,933 "xFant",934 substr(trim($std->xFant), 0, 60),935 false,936 $identificador . "Nome fantasia do emitente"937 );938 if ($std->IE != 'ISENTO') {939 $std->IE = Strings::onlyNumbers($std->IE);940 }941 $this->dom->addChild(942 $this->emit,943 "IE",944 $std->IE,945 true,946 $identificador . "Inscrição Estadual do emitente"947 );948 $this->dom->addChild(949 $this->emit,950 "IEST",951 Strings::onlyNumbers($std->IEST),952 false,953 $identificador . "IE do Substituto Tributário do emitente"954 );955 $this->dom->addChild(956 $this->emit,957 "IM",958 Strings::onlyNumbers($std->IM),959 false,960 $identificador . "Inscrição Municipal do Prestador de Serviço do emitente"961 );962 if (!empty($std->IM) && !empty($std->CNAE)) {963 $this->dom->addChild(964 $this->emit,965 "CNAE",966 Strings::onlyNumbers($std->CNAE),967 false,968 $identificador . "CNAE fiscal do emitente"969 );970 }971 $this->dom->addChild(972 $this->emit,973 "CRT",974 $std->CRT,975 true,976 $identificador . "Código de Regime Tributário do emitente"977 );978 return $this->emit;979 }980 /**981 * Endereço do emitente C05 pai C01982 * tag NFe/infNFe/emit/endEmit983 * @param stdClass $std984 * @return DOMElement985 */986 public function tagenderEmit(stdClass $std)987 {988 $possible = [989 'xLgr',990 'nro',991 'xCpl',992 'xBairro',993 'cMun',994 'xMun',995 'UF',996 'CEP',997 'cPais',998 'xPais',999 'fone'1000 ];1001 $std = $this->equilizeParameters($std, $possible);1002 $identificador = 'C05 <enderEmit> - ';1003 $this->enderEmit = $this->dom->createElement("enderEmit");1004 $this->dom->addChild(1005 $this->enderEmit,1006 "xLgr",1007 substr(trim($std->xLgr), 0, 60),1008 true,1009 $identificador . "Logradouro do Endereço do emitente"1010 );1011 $this->dom->addChild(1012 $this->enderEmit,1013 "nro",1014 substr(trim($std->nro), 0, 60),1015 true,1016 $identificador . "Número do Endereço do emitente"1017 );1018 $this->dom->addChild(1019 $this->enderEmit,1020 "xCpl",1021 substr(trim($std->xCpl), 0, 60),1022 false,1023 $identificador . "Complemento do Endereço do emitente"1024 );1025 $this->dom->addChild(1026 $this->enderEmit,1027 "xBairro",1028 substr(trim($std->xBairro), 0, 60),1029 true,1030 $identificador . "Bairro do Endereço do emitente"1031 );1032 $this->dom->addChild(1033 $this->enderEmit,1034 "cMun",1035 Strings::onlyNumbers($std->cMun),1036 true,1037 $identificador . "Código do município do Endereço do emitente"1038 );1039 $this->dom->addChild(1040 $this->enderEmit,1041 "xMun",1042 substr(trim($std->xMun), 0, 60),1043 true,1044 $identificador . "Nome do município do Endereço do emitente"1045 );1046 $this->dom->addChild(1047 $this->enderEmit,1048 "UF",1049 strtoupper(trim($std->UF)),1050 true,1051 $identificador . "Sigla da UF do Endereço do emitente"1052 );1053 $this->dom->addChild(1054 $this->enderEmit,1055 "CEP",1056 Strings::onlyNumbers($std->CEP),1057 true,1058 $identificador . "Código do CEP do Endereço do emitente"1059 );1060 $this->dom->addChild(1061 $this->enderEmit,1062 "cPais",1063 Strings::onlyNumbers($std->cPais),1064 false,1065 $identificador . "Código do País do Endereço do emitente"1066 );1067 $this->dom->addChild(1068 $this->enderEmit,1069 "xPais",1070 substr(trim($std->xPais), 0, 60),1071 false,1072 $identificador . "Nome do País do Endereço do emitente"1073 );1074 $this->dom->addChild(1075 $this->enderEmit,1076 "fone",1077 trim($std->fone),1078 false,1079 $identificador . "Telefone do Endereço do emitente"1080 );1081 $node = $this->emit->getElementsByTagName("IE")->item(0);1082 $this->emit->insertBefore($this->enderEmit, $node);1083 return $this->enderEmit;1084 }1085 /**1086 * Identificação do Destinatário da NF-e E01 pai A011087 * tag NFe/infNFe/dest (opcional para modelo 65)1088 * @param stdClass $std1089 * @return DOMElement1090 */1091 public function tagdest(stdClass $std)1092 {1093 $possible = [1094 'xNome',1095 'indIEDest',1096 'IE',1097 'ISUF',1098 'IM',1099 'email',1100 'CNPJ',1101 'CPF',1102 'idEstrangeiro'1103 ];1104 $std = $this->equilizeParameters($std, $possible);1105 $identificador = 'E01 <dest> - ';1106 $flagNome = true; //marca se xNome é ou não obrigatório1107 $temIE = $std->IE != '' && $std->IE != 'ISENTO'; // Tem inscrição municipal1108 $this->dest = $this->dom->createElement("dest");1109 if (!$temIE && $std->indIEDest == 1) {1110 $std->indIEDest = 2;1111 }1112 if ($this->mod == '65') {1113 $std->indIEDest = 9;1114 if ($std->xNome == '') {1115 $flagNome = false; //marca se xNome é ou não obrigatório1116 }1117 }1118 $xNome = $std->xNome;1119 if ($this->tpAmb == '2') {1120 $xNome = 'NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';1121 //a exigência do CNPJ 99999999000191 não existe mais1122 }1123 if (!empty($std->CNPJ)) {1124 $this->dom->addChild(1125 $this->dest,1126 "CNPJ",1127 Strings::onlyNumbers($std->CNPJ),1128 true,1129 $identificador . "CNPJ do destinatário"1130 );1131 } elseif (!empty($std->CPF)) {1132 $this->dom->addChild(1133 $this->dest,1134 "CPF",1135 Strings::onlyNumbers($std->CPF),1136 true,1137 $identificador . "CPF do destinatário"1138 );1139 } elseif ($std->idEstrangeiro !== null) {1140 $this->dom->addChild(1141 $this->dest,1142 "idEstrangeiro",1143 $std->idEstrangeiro,1144 true,1145 $identificador . "Identificação do destinatário no caso de comprador estrangeiro",1146 true1147 );1148 $std->indIEDest = '9';1149 }1150 $this->dom->addChild(1151 $this->dest,1152 "xNome",1153 substr(trim($xNome), 0, 60),1154 $flagNome, //se mod 55 true ou mod 65 false1155 $identificador . "Razão Social ou nome do destinatário"1156 );1157 $this->dom->addChild(1158 $this->dest,1159 "indIEDest",1160 Strings::onlyNumbers($std->indIEDest),1161 true,1162 $identificador . "Indicador da IE do Destinatário"1163 );1164 if ($temIE) {1165 $this->dom->addChild(1166 $this->dest,1167 "IE",1168 $std->IE,1169 true,1170 $identificador . "Inscrição Estadual do Destinatário"1171 );1172 }1173 $this->dom->addChild(1174 $this->dest,1175 "ISUF",1176 Strings::onlyNumbers($std->ISUF),1177 false,1178 $identificador . "Inscrição na SUFRAMA do destinatário"1179 );1180 $this->dom->addChild(1181 $this->dest,1182 "IM",1183 Strings::onlyNumbers($std->IM),1184 false,1185 $identificador . "Inscrição Municipal do Tomador do Serviço do destinatário"1186 );1187 $this->dom->addChild(1188 $this->dest,1189 "email",1190 substr(trim($std->email), 0, 60),1191 false,1192 $identificador . "Email do destinatário"1193 );1194 return $this->dest;1195 }1196 /**1197 * Endereço do Destinatário da NF-e E05 pai E011198 * tag NFe/infNFe/dest/enderDest (opcional para modelo 65)1199 * Os dados do destinatário devem ser inseridos antes deste método1200 * @param stdClass $std1201 * @return DOMElement1202 */1203 public function tagenderDest(stdClass $std)1204 {1205 $possible = [1206 'xLgr',1207 'nro',1208 'xCpl',1209 'xBairro',1210 'cMun',1211 'xMun',1212 'UF',1213 'CEP',1214 'cPais',1215 'xPais',1216 'fone'1217 ];1218 $std = $this->equilizeParameters($std, $possible);1219 $identificador = 'E05 <enderDest> - ';1220 if (empty($this->dest)) {1221 throw new RuntimeException('A TAG dest deve ser criada antes do endereço do mesmo.');1222 }1223 $this->enderDest = $this->dom->createElement("enderDest");1224 $this->dom->addChild(1225 $this->enderDest,1226 "xLgr",1227 $std->xLgr,1228 true,1229 $identificador . "Logradouro do Endereço do Destinatário"1230 );1231 $this->dom->addChild(1232 $this->enderDest,1233 "nro",1234 $std->nro,1235 true,1236 $identificador . "Número do Endereço do Destinatário"1237 );1238 $this->dom->addChild(1239 $this->enderDest,1240 "xCpl",1241 $std->xCpl,1242 false,1243 $identificador . "Complemento do Endereço do Destinatário"1244 );1245 $this->dom->addChild(1246 $this->enderDest,1247 "xBairro",1248 $std->xBairro,1249 true,1250 $identificador . "Bairro do Endereço do Destinatário"1251 );1252 $this->dom->addChild(1253 $this->enderDest,1254 "cMun",1255 $std->cMun,1256 true,1257 $identificador . "Código do município do Endereço do Destinatário"1258 );1259 $this->dom->addChild(1260 $this->enderDest,1261 "xMun",1262 $std->xMun,1263 true,1264 $identificador . "Nome do município do Endereço do Destinatário"1265 );1266 $this->dom->addChild(1267 $this->enderDest,1268 "UF",1269 $std->UF,1270 true,1271 $identificador . "Sigla da UF do Endereço do Destinatário"1272 );1273 $this->dom->addChild(1274 $this->enderDest,1275 "CEP",1276 $std->CEP,1277 false,1278 $identificador . "Código do CEP do Endereço do Destinatário"1279 );1280 $this->dom->addChild(1281 $this->enderDest,1282 "cPais",1283 $std->cPais,1284 false,1285 $identificador . "Código do País do Endereço do Destinatário"1286 );1287 $this->dom->addChild(1288 $this->enderDest,1289 "xPais",1290 $std->xPais,1291 false,1292 $identificador . "Nome do País do Endereço do Destinatário"1293 );1294 $this->dom->addChild(1295 $this->enderDest,1296 "fone",1297 $std->fone,1298 false,1299 $identificador . "Telefone do Endereço do Destinatário"1300 );1301 $node = $this->dest->getElementsByTagName("indIEDest")->item(0);1302 if (!isset($node)) {1303 $node = $this->dest->getElementsByTagName("IE")->item(0);1304 }1305 $this->dest->insertBefore($this->enderDest, $node);1306 return $this->enderDest;1307 }1308 /**1309 * Identificação do Local de retirada F01 pai A011310 * tag NFe/infNFe/retirada (opcional)1311 * NOTA: ajustado para NT 2018.0051312 * @param stdClass $std1313 * @return DOMElement1314 */1315 public function tagretirada(stdClass $std)1316 {1317 $possible = [1318 'xLgr',1319 'nro',1320 'xCpl',1321 'xBairro',1322 'cMun',1323 'xMun',1324 'UF',1325 'CNPJ',1326 'CPF',1327 'xNome',1328 'CEP',1329 'cPais',1330 'xPais',1331 'fone',1332 'email',1333 'IE'1334 ];1335 $std = $this->equilizeParameters($std, $possible);1336 $identificador = 'F01 <retirada> - ';1337 $this->retirada = $this->dom->createElement("retirada");1338 $this->dom->addChild(1339 $this->retirada,1340 "CNPJ",1341 $std->CNPJ,1342 false,1343 $identificador . "CNPJ do Cliente da Retirada"1344 );1345 $this->dom->addChild(1346 $this->retirada,1347 "CPF",1348 $std->CPF,1349 false,1350 $identificador . "CPF do Cliente da Retirada"1351 );1352 $this->dom->addChild(1353 $this->retirada,1354 "xNome",1355 $std->xNome,1356 false,1357 $identificador . "Nome do Cliente da Retirada"1358 );1359 $this->dom->addChild(1360 $this->retirada,1361 "xLgr",1362 $std->xLgr,1363 true,1364 $identificador . "Logradouro do Endereco do Cliente da Retirada"1365 );1366 $this->dom->addChild(1367 $this->retirada,1368 "nro",1369 $std->nro,1370 true,1371 $identificador . "Número do Endereco do Cliente da Retirada"1372 );1373 $this->dom->addChild(1374 $this->retirada,1375 "xCpl",1376 $std->xCpl,1377 false,1378 $identificador . "Complemento do Endereco do Cliente da Retirada"1379 );1380 $this->dom->addChild(1381 $this->retirada,1382 "xBairro",1383 $std->xBairro,1384 true,1385 $identificador . "Bairro do Endereco do Cliente da Retirada"1386 );1387 $this->dom->addChild(1388 $this->retirada,1389 "cMun",1390 $std->cMun,1391 true,1392 $identificador . "Código do município do Endereco do Cliente da Retirada"1393 );1394 $this->dom->addChild(1395 $this->retirada,1396 "xMun",1397 $std->xMun,1398 true,1399 $identificador . "Nome do município do Endereco do Cliente da Retirada"1400 );1401 $this->dom->addChild(1402 $this->retirada,1403 "UF",1404 $std->UF,1405 true,1406 $identificador . "Sigla da UF do Endereco do Cliente da Retirada"1407 );1408 $this->dom->addChild(1409 $this->retirada,1410 "CEP",1411 $std->CEP,1412 false,1413 $identificador . "CEP do Endereco do Cliente da Retirada"1414 );1415 $this->dom->addChild(1416 $this->retirada,1417 "cPais",1418 $std->cPais,1419 false,1420 $identificador . "Codigo do Pais do Endereco do Cliente da Retirada"1421 );1422 $this->dom->addChild(1423 $this->retirada,1424 "xPais",1425 $std->xPais,1426 false,1427 $identificador . "Pais do Endereco do Cliente da Retirada"1428 );1429 $this->dom->addChild(1430 $this->retirada,1431 "fone",1432 $std->fone,1433 false,1434 $identificador . "Fone do Endereco do Cliente da Retirada"1435 );1436 $this->dom->addChild(1437 $this->retirada,1438 "email",1439 $std->email,1440 false,1441 $identificador . "Email do Endereco do Cliente da Retirada"1442 );1443 $this->dom->addChild(1444 $this->retirada,1445 "IE",1446 $std->IE,1447 false,1448 $identificador . "IE do Cliente da Retirada"1449 );1450 return $this->retirada;1451 }1452 /**1453 * Identificação do Local de entrega G01 pai A011454 * tag NFe/infNFe/entrega (opcional)1455 * NOTA: ajustado para NT 2018.0051456 * @param stdClass $std1457 * @return DOMElement1458 */1459 public function tagentrega(stdClass $std)1460 {1461 $possible = [1462 'xLgr',1463 'nro',1464 'xCpl',1465 'xBairro',1466 'cMun',1467 'xMun',1468 'UF',1469 'CNPJ',1470 'CPF',1471 'xNome',1472 'CEP',1473 'cPais',1474 'xPais',1475 'fone',1476 'email',1477 'IE'1478 ];1479 $std = $this->equilizeParameters($std, $possible);1480 $identificador = 'G01 <entrega> - ';1481 $this->entrega = $this->dom->createElement("entrega");1482 $this->dom->addChild(1483 $this->entrega,1484 "CNPJ",1485 $std->CNPJ,1486 false,1487 $identificador . "CNPJ do Cliente da Entrega"1488 );1489 $this->dom->addChild(1490 $this->entrega,1491 "CPF",1492 $std->CPF,1493 false,1494 $identificador . "CPF do Cliente da Entrega"1495 );1496 $this->dom->addChild(1497 $this->entrega,1498 "xNome",1499 $std->xNome,1500 false,1501 $identificador . "Nome do Cliente da Entrega"1502 );1503 $this->dom->addChild(1504 $this->entrega,1505 "xLgr",1506 $std->xLgr,1507 true,1508 $identificador . "Logradouro do Endereco do Cliente da Entrega"1509 );1510 $this->dom->addChild(1511 $this->entrega,1512 "nro",1513 $std->nro,1514 true,1515 $identificador . "Número do Endereco do Cliente da Entrega"1516 );1517 $this->dom->addChild(1518 $this->entrega,1519 "xCpl",1520 $std->xCpl,1521 false,1522 $identificador . "Complemento do Endereco do Cliente da Entrega"1523 );1524 $this->dom->addChild(1525 $this->entrega,1526 "xBairro",1527 $std->xBairro,1528 true,1529 $identificador . "Bairro do Endereco do Cliente da Entrega"1530 );1531 $this->dom->addChild(1532 $this->entrega,1533 "cMun",1534 $std->cMun,1535 true,1536 $identificador . "Código do município do Endereco do Cliente da Entrega"1537 );1538 $this->dom->addChild(1539 $this->entrega,1540 "xMun",1541 $std->xMun,1542 true,1543 $identificador . "Nome do município do Endereco do Cliente da Entrega"1544 );1545 $this->dom->addChild(1546 $this->entrega,1547 "UF",1548 $std->UF,1549 true,1550 $identificador . "Sigla da UF do Endereco do Cliente da Entrega"1551 );1552 $this->dom->addChild(1553 $this->entrega,1554 "CEP",1555 $std->CEP,1556 false,1557 $identificador . "CEP do Endereco do Cliente da Entrega"1558 );1559 $this->dom->addChild(1560 $this->entrega,1561 "cPais",1562 $std->cPais,1563 false,1564 $identificador . "Codigo do Pais do Endereco do Cliente da Entrega"1565 );1566 $this->dom->addChild(1567 $this->entrega,1568 "xPais",1569 $std->xPais,1570 false,1571 $identificador . "Pais do Endereco do Cliente da Entrega"1572 );1573 $this->dom->addChild(1574 $this->entrega,1575 "fone",1576 $std->fone,1577 false,1578 $identificador . "Fone do Endereco do Cliente da Entrega"1579 );1580 $this->dom->addChild(1581 $this->entrega,1582 "email",1583 $std->email,1584 false,1585 $identificador . "Email do Endereco do Cliente da Entrega"1586 );1587 $this->dom->addChild(1588 $this->entrega,1589 "IE",1590 $std->IE,1591 false,1592 $identificador . "IE do Cliente da Entrega"1593 );1594 return $this->entrega;1595 }1596 /**1597 * Pessoas autorizadas para o download do XML da NF-e G50 pai A011598 * tag NFe/infNFe/autXML1599 * @param stdClass $std1600 * @return DOMElement1601 */1602 public function tagautXML(stdClass $std)1603 {1604 $possible = ['CNPJ', 'CPF'];1605 $std = $this->equilizeParameters($std, $possible);1606 $identificador = 'G50 <autXML> - ';1607 $std->CNPJ = !empty($std->CNPJ) ? $std->CNPJ : null;1608 $std->CPF = !empty($std->CPF) ? $std->CPF : null;1609 $autXML = $this->dom->createElement("autXML");1610 $this->dom->addChild(1611 $autXML,1612 "CNPJ",1613 $std->CNPJ,1614 false,1615 $identificador . "CNPJ do Cliente Autorizado"1616 );1617 $this->dom->addChild(1618 $autXML,1619 "CPF",1620 $std->CPF,1621 false,1622 $identificador . "CPF do Cliente Autorizado"1623 );1624 $this->aAutXML[] = $autXML;1625 return $autXML;1626 }1627 /**1628 * Informações adicionais do produto V01 pai H011629 * tag NFe/infNFe/det[]/infAdProd1630 * @param stdClass $std1631 * @return DOMElement1632 */1633 public function taginfAdProd(stdClass $std)1634 {1635 $possible = ['item', 'infAdProd'];1636 $std = $this->equilizeParameters($std, $possible);1637 $infAdProd = $this->dom->createElement(1638 "infAdProd",1639 substr(trim($std->infAdProd), 0, 500)1640 );1641 $this->aInfAdProd[$std->item] = $infAdProd;1642 return $infAdProd;1643 }1644 /**1645 * Detalhamento de Produtos e Serviços I01 pai H011646 * tag NFe/infNFe/det[]/prod1647 * NOTA: Ajustado para NT2016_002_v1.301648 * @param stdClass $std1649 * @return DOMElement1650 */1651 public function tagprod(stdClass $std)1652 {1653 $possible = [1654 'item',1655 'cProd',1656 'cEAN',1657 'xProd',1658 'NCM',1659 'cBenef',1660 'EXTIPI',1661 'CFOP',1662 'uCom',1663 'qCom',1664 'vUnCom',1665 'vProd',1666 'cEANTrib',1667 'uTrib',1668 'qTrib',1669 'vUnTrib',1670 'vFrete',1671 'vSeg',1672 'vDesc',1673 'vOutro',1674 'indTot',1675 'xPed',1676 'nItemPed',1677 'nFCI'1678 ];1679 $std = $this->equilizeParameters($std, $possible);1680 //totalizador1681 if ($std->indTot == 1) {1682 $this->stdTot->vProd += (float) $std->vProd;1683 }1684 $this->stdTot->vFrete += (float) $std->vFrete;1685 $this->stdTot->vSeg += (float) $std->vSeg;1686 $this->stdTot->vDesc += (float) $std->vDesc;1687 $this->stdTot->vOutro += (float) $std->vOutro;1688 $cean = !empty($std->cEAN) ? trim(strtoupper($std->cEAN)) : '';1689 $ceantrib = !empty($std->cEANTrib) ? trim(strtoupper($std->cEANTrib)) : '';1690 //throw exception if not is Valid1691 try {1692 Gtin::isValid($cean);1693 } catch (\InvalidArgumentException $e) {1694 $this->errors[] = "cEANT {$cean} " . $e->getMessage();1695 }1696 try {1697 Gtin::isValid($ceantrib);1698 } catch (\InvalidArgumentException $e) {1699 $this->errors[] = "cEANTrib {$ceantrib} " . $e->getMessage();1700 }1701 $identificador = 'I01 <prod> - ';1702 $prod = $this->dom->createElement("prod");1703 $this->dom->addChild(1704 $prod,1705 "cProd",1706 $std->cProd,1707 true,1708 $identificador . "[item $std->item] Código do produto ou serviço"1709 );1710 $this->dom->addChild(1711 $prod,1712 "cEAN",1713 $cean,1714 true,1715 $identificador . "[item $std->item] GTIN (Global Trade Item Number) do produto, antigo "1716 . "código EAN ou código de barras",1717 true1718 );1719 $xProd = $std->xProd;1720 if ($this->tpAmb == '2' && $this->mod == '65' && $std->item === 1) {1721 $xProd = 'NOTA FISCAL EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';1722 }1723 $this->dom->addChild(1724 $prod,1725 "xProd",1726 $xProd,1727 true,1728 $identificador . "[item $std->item] Descrição do produto ou serviço"1729 );1730 $this->dom->addChild(1731 $prod,1732 "NCM",1733 $std->NCM,1734 true,1735 $identificador . "[item $std->item] Código NCM com 8 dígitos ou 2 dígitos (gênero)"1736 );1737 //incluido no layout 4.001738 $this->dom->addChild(1739 $prod,1740 "cBenef",1741 $std->cBenef,1742 false,1743 $identificador . "[item $std->item] Código de Benefício Fiscal utilizado pela UF"1744 );1745 $this->dom->addChild(1746 $prod,1747 "EXTIPI",1748 $std->EXTIPI,1749 false,1750 $identificador . "[item $std->item] Preencher de acordo com o código EX da TIPI"1751 );1752 $this->dom->addChild(1753 $prod,1754 "CFOP",1755 $std->CFOP,1756 true,1757 $identificador . "[item $std->item] Código Fiscal de Operações e Prestações"1758 );1759 $this->dom->addChild(1760 $prod,1761 "uCom",1762 $std->uCom,1763 true,1764 $identificador . "[item $std->item] Unidade Comercial do produto"1765 );1766 $this->dom->addChild(1767 $prod,1768 "qCom",1769 $std->qCom,1770 true,1771 $identificador . "[item $std->item] Quantidade Comercial do produto"1772 );1773 $this->dom->addChild(1774 $prod,1775 "vUnCom",1776 $std->vUnCom,1777 true,1778 $identificador . "[item $std->item] Valor Unitário de Comercialização do produto"1779 );1780 $this->dom->addChild(1781 $prod,1782 "vProd",1783 $std->vProd,1784 true,1785 $identificador . "[item $std->item] Valor Total Bruto dos Produtos ou Serviços"1786 );1787 $this->dom->addChild(1788 $prod,1789 "cEANTrib",1790 $ceantrib,1791 true,1792 $identificador . "[item $std->item] GTIN (Global Trade Item Number) da unidade tributável, antigo "1793 . "código EAN ou código de barras",1794 true1795 );1796 $this->dom->addChild(1797 $prod,1798 "uTrib",1799 $std->uTrib,1800 true,1801 $identificador . "[item $std->item] Unidade Tributável do produto"1802 );1803 $this->dom->addChild(1804 $prod,1805 "qTrib",1806 $std->qTrib,1807 true,1808 $identificador . "[item $std->item] Quantidade Tributável do produto"1809 );1810 $this->dom->addChild(1811 $prod,1812 "vUnTrib",1813 $std->vUnTrib,1814 true,1815 $identificador . "[item $std->item] Valor Unitário de tributação do produto"1816 );1817 $this->dom->addChild(1818 $prod,1819 "vFrete",1820 $this->conditionalNumberFormatting($std->vFrete),1821 false,1822 $identificador . "[item $std->item] Valor Total do Frete"1823 );1824 $this->dom->addChild(1825 $prod,1826 "vSeg",1827 $this->conditionalNumberFormatting($std->vSeg),1828 false,1829 $identificador . "[item $std->item] Valor Total do Seguro"1830 );1831 $this->dom->addChild(1832 $prod,1833 "vDesc",1834 $this->conditionalNumberFormatting($std->vDesc),1835 false,1836 $identificador . "[item $std->item] Valor do Desconto"1837 );1838 $this->dom->addChild(1839 $prod,1840 "vOutro",1841 $this->conditionalNumberFormatting($std->vOutro),1842 false,1843 $identificador . "[item $std->item] Outras despesas acessórias"1844 );1845 $this->dom->addChild(1846 $prod,1847 "indTot",1848 $std->indTot,1849 true,1850 $identificador . "[item $std->item] Indica se valor do Item (vProd) entra no valor total da NF-e (vProd)"1851 );1852 $this->dom->addChild(1853 $prod,1854 "xPed",1855 $std->xPed,1856 false,1857 $identificador . "[item $std->item] Número do Pedido de Compra"1858 );1859 $this->dom->addChild(1860 $prod,1861 "nItemPed",1862 $std->nItemPed,1863 false,1864 $identificador . "[item $std->item] Item do Pedido de Compra"1865 );1866 $this->dom->addChild(1867 $prod,1868 "nFCI",1869 $std->nFCI,1870 false,1871 $identificador . "[item $std->item] Número de controle da FCI "1872 . "Ficha de Conteúdo de Importação"1873 );1874 $this->aProd[$std->item] = $prod;1875 return $prod;1876 }1877 /**1878 * NVE NOMENCLATURA DE VALOR ADUANEIRO E ESTATÍSTICA1879 * Podem ser até 8 NVE's por item1880 *1881 * @param stdClass $std1882 * @return DOMElement|null1883 */1884 public function tagNVE(stdClass $std)1885 {1886 $possible = ['item', 'NVE'];1887 $std = $this->equilizeParameters($std, $possible);1888 if ($std->NVE == '') {1889 return null;1890 }1891 $nve = $this->dom->createElement("NVE", $std->NVE);1892 $this->aNVE[$std->item][] = $nve;1893 return $nve;1894 }1895 /**1896 * Código Especificador da Substituição Tributária – CEST,1897 * que identifica a mercadoria sujeita aos regimes de substituição1898 * tributária e de antecipação do recolhimento do imposto.1899 * vide NT2015.003 I05C pai1900 * tag NFe/infNFe/det[item]/prod/CEST (opcional)1901 * NOTA: Ajustado para NT2016_002_v1.301902 * @param stdClass $std1903 * @return DOMElement1904 */1905 public function tagCEST(stdClass $std)1906 {1907 $possible = ['item', 'CEST', 'indEscala', 'CNPJFab'];1908 $std = $this->equilizeParameters($std, $possible);1909 $identificador = 'I05b <ctrltST> - ';1910 $ctrltST = $this->dom->createElement("ctrltST");1911 $this->dom->addChild(1912 $ctrltST,1913 "CEST",1914 Strings::onlyNumbers($std->CEST),1915 true,1916 "$identificador [item $std->item] Numero CEST"1917 );1918 //incluido no layout 4.001919 $this->dom->addChild(1920 $ctrltST,1921 "indEscala",1922 trim($std->indEscala),1923 false,1924 "$identificador [item $std->item] Indicador de Produção em escala relevante"1925 );1926 //incluido no layout 4.001927 $this->dom->addChild(1928 $ctrltST,1929 "CNPJFab",1930 Strings::onlyNumbers($std->CNPJFab),1931 false,1932 "$identificador [item $std->item] CNPJ do Fabricante da Mercadoria,"1933 . "obrigatório para produto em escala NÃO relevante."1934 );1935 $this->aCest[$std->item][] = $ctrltST;1936 return $ctrltST;1937 }1938 /**1939 * tag NFe/infNFe/det[item]/prod/nRECOPI1940 * @param stdClass $std1941 * @return DOMElement1942 */1943 public function tagRECOPI(stdClass $std)1944 {1945 $possible = ['item', 'nRECOPI'];1946 $std = $this->equilizeParameters($std, $possible);1947 $recopi = $this->dom->createElement("nRECOPI", $std->nRECOPI);1948 $this->aRECOPI[$std->item] = $recopi;1949 return $recopi;1950 }1951 /**1952 * Declaração de Importação I8 pai I011953 * tag NFe/infNFe/det[]/prod/DI1954 * @param stdClass $std1955 * @return DOMElement1956 */1957 public function tagDI(stdClass $std)1958 {1959 $possible = [1960 'item',1961 'nDI',1962 'dDI',1963 'xLocDesemb',1964 'UFDesemb',1965 'dDesemb',1966 'tpViaTransp',1967 'vAFRMM',1968 'tpIntermedio',1969 'CNPJ',1970 'UFTerceiro',1971 'cExportador'1972 ];1973 $std = $this->equilizeParameters($std, $possible);1974 $identificador = 'I8 <DI> - ';1975 $tDI = $this->dom->createElement("DI");1976 $this->dom->addChild(1977 $tDI,1978 "nDI",1979 $std->nDI,1980 true,1981 $identificador . "[item $std->item] Número do Documento de Importação (DI, DSI, DIRE, ...)"1982 );1983 $this->dom->addChild(1984 $tDI,1985 "dDI",1986 $std->dDI,1987 true,1988 $identificador . "[item $std->item] Data de Registro do documento"1989 );1990 $this->dom->addChild(1991 $tDI,1992 "xLocDesemb",1993 $std->xLocDesemb,1994 true,1995 $identificador . "[item $std->item] Local de desembaraço"1996 );1997 $this->dom->addChild(1998 $tDI,1999 "UFDesemb",2000 $std->UFDesemb,2001 true,2002 $identificador . "[item $std->item] Sigla da UF onde ocorreu o Desembaraço Aduaneiro"2003 );2004 $this->dom->addChild(2005 $tDI,2006 "dDesemb",2007 $std->dDesemb,2008 true,2009 $identificador . "[item $std->item] Data do Desembaraço Aduaneiro"2010 );2011 $this->dom->addChild(2012 $tDI,2013 "tpViaTransp",2014 $std->tpViaTransp,2015 true,2016 $identificador . "[item $std->item] Via de transporte internacional "2017 . "informada na Declaração de Importação (DI)"2018 );2019 $this->dom->addChild(2020 $tDI,2021 "vAFRMM",2022 $this->conditionalNumberFormatting($std->vAFRMM),2023 false,2024 $identificador . "[item $std->item] Valor da AFRMM "2025 . "- Adicional ao Frete para Renovação da Marinha Mercante"2026 );2027 $this->dom->addChild(2028 $tDI,2029 "tpIntermedio",2030 $std->tpIntermedio,2031 true,2032 $identificador . "[item $std->item] Forma de importação quanto a intermediação"2033 );2034 $this->dom->addChild(2035 $tDI,2036 "CNPJ",2037 $std->CNPJ,2038 false,2039 $identificador . "[item $std->item] CNPJ do adquirente ou do encomendante"2040 );2041 $this->dom->addChild(2042 $tDI,2043 "UFTerceiro",2044 $std->UFTerceiro,2045 false,2046 $identificador . "[item $std->item] Sigla da UF do adquirente ou do encomendante"2047 );2048 $this->dom->addChild(2049 $tDI,2050 "cExportador",2051 $std->cExportador,2052 true,2053 $identificador . "[item $std->item] Código do Exportador"2054 );2055 $this->aDI[$std->item][$std->nDI] = $tDI;2056 return $tDI;2057 }2058 /**2059 * Adições I25 pai I182060 * tag NFe/infNFe/det[]/prod/DI/adi2061 * @param stdClass $std2062 * @return DOMElement2063 */2064 public function tagadi(stdClass $std)2065 {2066 $possible = [2067 'item',2068 'nDI',2069 'nAdicao',2070 'nSeqAdic',2071 'cFabricante',2072 'vDescDI',2073 'nDraw'2074 ];2075 $std = $this->equilizeParameters($std, $possible);2076 $identificador = 'I25 <adi> - ';2077 $adi = $this->dom->createElement("adi");2078 $this->dom->addChild(2079 $adi,2080 "nAdicao",2081 $std->nAdicao,2082 true,2083 $identificador . "[item $std->item] Número da Adição"2084 );2085 $this->dom->addChild(2086 $adi,2087 "nSeqAdic",2088 $std->nSeqAdic,2089 true,2090 $identificador . "[item $std->item] Número sequencial do item dentro da Adição"2091 );2092 $this->dom->addChild(2093 $adi,2094 "cFabricante",2095 $std->cFabricante,2096 true,2097 $identificador . "[item $std->item] Código do fabricante estrangeiro"2098 );2099 $this->dom->addChild(2100 $adi,2101 "vDescDI",2102 $this->conditionalNumberFormatting($std->vDescDI),2103 false,2104 $identificador . "[item $std->item] Valor do desconto do item da DI Adição"2105 );2106 $this->dom->addChild(2107 $adi,2108 "nDraw",2109 $std->nDraw,2110 false,2111 $identificador . "[item $std->item] Número do ato concessório de Drawback"2112 );2113 $this->aAdi[$std->item][$std->nDI][] = $adi;2114 //colocar a adi em seu DI respectivo2115 $nodeDI = $this->aDI[$std->item][$std->nDI];2116 $this->dom->appChild($nodeDI, $adi);2117 $this->aDI[$std->item][$std->nDI] = $nodeDI;2118 return $adi;2119 }2120 /**2121 * Grupo de informações de exportação para o item I50 pai I012122 * tag NFe/infNFe/det[]/prod/detExport2123 * @param stdClass $std2124 * @return DOMElement2125 */2126 public function tagdetExport(stdClass $std)2127 {2128 $possible = [2129 'item',2130 'nDraw'2131 ];2132 $std = $this->equilizeParameters($std, $possible);2133 $identificador = 'I50 <detExport> - ';2134 $detExport = $this->dom->createElement("detExport");2135 $this->dom->addChild(2136 $detExport,2137 "nDraw",2138 Strings::onlyNumbers($std->nDraw),2139 false,2140 $identificador . "[item $std->item] Número do ato concessório de Drawback"2141 );2142 $this->aDetExport[$std->item][] = $detExport;2143 return $detExport;2144 }2145 /**2146 * Grupo de informações de exportação para o item I52 pai I522147 * tag NFe/infNFe/det[]/prod/detExport2148 * @param stdClass $std2149 * @return DOMElement2150 */2151 public function tagdetExportInd(stdClass $std)2152 {2153 $possible = [2154 'item',2155 'nRE',2156 'chNFe',2157 'qExport'2158 ];2159 $std = $this->equilizeParameters($std, $possible);2160 $identificador = 'I52 <exportInd> - ';2161 $exportInd = $this->dom->createElement("exportInd");2162 $this->dom->addChild(2163 $exportInd,2164 "nRE",2165 Strings::onlyNumbers($std->nRE),2166 true,2167 $identificador . "[item $std->item] Número do Registro de Exportação"2168 );2169 $this->dom->addChild(2170 $exportInd,2171 "chNFe",2172 Strings::onlyNumbers($std->chNFe),2173 true,2174 $identificador . "[item $std->item] Chave de Acesso da NF-e recebida para exportação"2175 );2176 $this->dom->addChild(2177 $exportInd,2178 "qExport",2179 $this->conditionalNumberFormatting($std->qExport, 4),2180 true,2181 $identificador . "[item $std->item] Quantidade do item realmente exportado"2182 );2183 //obtem o ultimo detExport2184 $nDE = count($this->aDetExport[$std->item]) - 1;2185 if ($nDE < 0) {2186 throw new RuntimeException('A TAG detExportInd deve ser criada depois da detExport, pois pertence a ela.');2187 }2188 //colocar a exportInd em seu DetExport respectivo2189 $nodeDetExport = $this->aDetExport[$std->item][$nDE];2190 $this->dom->appChild($nodeDetExport, $exportInd);2191 $this->aDetExport[$std->item][$nDE] = $nodeDetExport;2192 return $exportInd;2193 }2194 /**2195 * Rastreabilidade do produto podem ser até 500 por item TAG I80 pai I012196 * NOTA: Ajustado para NT2016_002_v1.002197 * tag NFe/infNFe/det[]/prod/rastro2198 * @param stdClass $std2199 * @return DOMElement2200 */2201 public function tagRastro(stdClass $std)2202 {2203 $possible = [2204 'item',2205 'nLote',2206 'qLote',2207 'dFab',2208 'dVal',2209 'cAgreg'2210 ];2211 $std = $this->equilizeParameters($std, $possible);2212 $identificador = 'I80 <rastro> - ';2213 $rastro = $this->dom->createElement("rastro");2214 $this->dom->addChild(2215 $rastro,2216 "nLote",2217 substr(trim($std->nLote), 0, 20),2218 true,2219 $identificador . "[item $std->item] Número do lote"2220 );2221 $this->dom->addChild(2222 $rastro,2223 "qLote",2224 $this->conditionalNumberFormatting($std->qLote, 3),2225 true,2226 $identificador . "[item $std->item] Quantidade do lote"2227 );2228 $this->dom->addChild(2229 $rastro,2230 "dFab",2231 trim($std->dFab),2232 true,2233 $identificador . "[item $std->item] Data de fabricação"2234 );2235 $this->dom->addChild(2236 $rastro,2237 "dVal",2238 trim($std->dVal),2239 true,2240 $identificador . "[item $std->item] Data da validade"2241 );2242 $this->dom->addChild(2243 $rastro,2244 "cAgreg",2245 Strings::onlyNumbers($std->cAgreg),2246 false,2247 $identificador . "[item $std->item] Código de Agregação"2248 );2249 $this->aRastro[$std->item][] = $rastro;2250 return $rastro;2251 }2252 /**2253 * Detalhamento de Veículos novos J01 pai I902254 * tag NFe/infNFe/det[]/prod/veicProd (opcional)2255 * @param stdClass $std2256 * @return DOMElement2257 */2258 public function tagveicProd(stdClass $std)2259 {2260 $possible = [2261 'item',2262 'tpOp',2263 'chassi',2264 'cCor',2265 'xCor',2266 'pot',2267 'cilin',2268 'pesoL',2269 'pesoB',2270 'nSerie',2271 'tpComb',2272 'nMotor',2273 'CMT',2274 'dist',2275 'anoMod',2276 'anoFab',2277 'tpPint',2278 'tpVeic',2279 'espVeic',2280 'VIN',2281 'condVeic',2282 'cMod',2283 'cCorDENATRAN',2284 'lota',2285 'tpRest'2286 ];2287 $std = $this->equilizeParameters($std, $possible);2288 $identificador = 'J01 <veicProd> - ';2289 $veicProd = $this->dom->createElement("veicProd");2290 $this->dom->addChild(2291 $veicProd,2292 "tpOp",2293 $std->tpOp,2294 true,2295 "$identificador [item $std->item] Tipo da operação do veículo"2296 );2297 $this->dom->addChild(2298 $veicProd,2299 "chassi",2300 $std->chassi,2301 true,2302 "$identificador [item $std->item] Chassi do veículo"2303 );2304 $this->dom->addChild(2305 $veicProd,2306 "cCor",2307 $std->cCor,2308 true,2309 "$identificador [item $std->item] Cor do veículo"2310 );2311 $this->dom->addChild(2312 $veicProd,2313 "xCor",2314 $std->xCor,2315 true,2316 "$identificador [item $std->item] Descrição da Cor do veículo"2317 );2318 $this->dom->addChild(2319 $veicProd,2320 "pot",2321 $std->pot,2322 true,2323 "$identificador [item $std->item] Potência Motor (CV) do veículo"2324 );2325 $this->dom->addChild(2326 $veicProd,2327 "cilin",2328 $std->cilin,2329 true,2330 "$identificador [item $std->item] Cilindradas do veículo"2331 );2332 $this->dom->addChild(2333 $veicProd,2334 "pesoL",2335 $this->conditionalNumberFormatting($std->pesoL, 3),2336 true,2337 "$identificador [item $std->item] Peso Líquido do veículo"2338 );2339 $this->dom->addChild(2340 $veicProd,2341 "pesoB",2342 $this->conditionalNumberFormatting($std->pesoB, 3),2343 true,2344 "$identificador [item $std->item] Peso Bruto do veículo"2345 );2346 $this->dom->addChild(2347 $veicProd,2348 "nSerie",2349 $std->nSerie,2350 true,2351 "$identificador [item $std->item] Serial (série) do veículo"2352 );2353 $this->dom->addChild(2354 $veicProd,2355 "tpComb",2356 $std->tpComb,2357 true,2358 "$identificador [item $std->item] Tipo de combustível do veículo"2359 );2360 $this->dom->addChild(2361 $veicProd,2362 "nMotor",2363 $std->nMotor,2364 true,2365 "$identificador [item $std->item] Número de Motor do veículo"2366 );2367 $this->dom->addChild(2368 $veicProd,2369 "CMT",2370 $this->conditionalNumberFormatting($std->CMT, 4),2371 true,2372 "$identificador [item $std->item] Capacidade Máxima de Tração do veículo"2373 );2374 $this->dom->addChild(2375 $veicProd,2376 "dist",2377 $std->dist,2378 true,2379 "$identificador [item $std->item] Distância entre eixos do veículo"2380 );2381 $this->dom->addChild(2382 $veicProd,2383 "anoMod",2384 $std->anoMod,2385 true,2386 "$identificador [item $std->item] Ano Modelo de Fabricação do veículo"2387 );2388 $this->dom->addChild(2389 $veicProd,2390 "anoFab",2391 $std->anoFab,2392 true,2393 "$identificador [item $std->item] Ano de Fabricação do veículo"2394 );2395 $this->dom->addChild(2396 $veicProd,2397 "tpPint",2398 $std->tpPint,2399 true,2400 "$identificador [item $std->item] Tipo de Pintura do veículo"2401 );2402 $this->dom->addChild(2403 $veicProd,2404 "tpVeic",2405 $std->tpVeic,2406 true,2407 "$identificador [item $std->item] Tipo de Veículo"2408 );2409 $this->dom->addChild(2410 $veicProd,2411 "espVeic",2412 $std->espVeic,2413 true,2414 "$identificador [item $std->item] Espécie de Veículo"2415 );2416 $this->dom->addChild(2417 $veicProd,2418 "VIN",2419 $std->VIN,2420 true,2421 "$identificador [item $std->item] Condição do VIN do veículo"2422 );2423 $this->dom->addChild(2424 $veicProd,2425 "condVeic",2426 $std->condVeic,2427 true,2428 "$identificador [item $std->item] Condição do Veículo"2429 );2430 $this->dom->addChild(2431 $veicProd,2432 "cMod",2433 $std->cMod,2434 true,2435 "$identificador [item $std->item] Código Marca Modelo do veículo"2436 );2437 $this->dom->addChild(2438 $veicProd,2439 "cCorDENATRAN",2440 $std->cCorDENATRAN,2441 true,2442 "$identificador [item $std->item] Código da Cor do veículo"2443 );2444 $this->dom->addChild(2445 $veicProd,2446 "lota",2447 $std->lota,2448 true,2449 "$identificador [item $std->item] Capacidade máxima de lotação do veículo"2450 );2451 $this->dom->addChild(2452 $veicProd,2453 "tpRest",2454 $std->tpRest,2455 true,2456 "$identificador [item $std->item] Restrição do veículo"2457 );2458 $this->aVeicProd[$std->item] = $veicProd;2459 return $veicProd;2460 }2461 /**2462 * Detalhamento de medicamentos K01 pai I902463 * NOTA: Ajustado para NT2018.0052464 * tag NFe/infNFe/det[]/prod/med (opcional)2465 * @param stdClass $std2466 * @return DOMElement2467 */2468 public function tagmed(stdClass $std)2469 {2470 $possible = [2471 'item',2472 'vPMC',2473 'cProdANVISA',2474 'xMotivoIsencao'2475 ];2476 $std = $this->equilizeParameters($std, $possible);2477 $identificador = 'K01 <med> - ';2478 $med = $this->dom->createElement("med");2479 $this->dom->addChild(2480 $med,2481 "cProdANVISA",2482 $std->cProdANVISA,2483 false,2484 "$identificador [item $std->item] Numero ANVISA"2485 );2486 $this->dom->addChild(2487 $med,2488 "xMotivoIsencao",2489 $std->xMotivoIsencao,2490 false,2491 "$identificador [item $std->item] Motivo da isenção da ANVISA"2492 );2493 $this->dom->addChild(2494 $med,2495 "vPMC",2496 $this->conditionalNumberFormatting($std->vPMC),2497 true,2498 "$identificador [item $std->item] Preço máximo consumidor"2499 );2500 $this->aMed[$std->item] = $med;2501 return $med;2502 }2503 /**2504 * Detalhamento de armas L01 pai I902505 * tag NFe/infNFe/det[]/prod/arma (opcional)2506 * @param stdClass $std2507 * @return DOMElement2508 */2509 public function tagarma(stdClass $std)2510 {2511 $possible = [2512 'item',2513 'nAR',2514 'tpArma',2515 'nSerie',2516 'nCano',2517 'descr'2518 ];2519 $std = $this->equilizeParameters($std, $possible);2520 $identificador = 'L01 <arma> - ';2521 $arma = $this->dom->createElement("arma");2522 $this->dom->addChild(2523 $arma,2524 "tpArma",2525 $std->tpArma,2526 true,2527 "$identificador [item $std->item] Indicador do tipo de arma de fogo"2528 );2529 $this->dom->addChild(2530 $arma,2531 "nSerie",2532 $std->nSerie,2533 true,2534 "$identificador [item $std->item] Número de série da arma"2535 );2536 $this->dom->addChild(2537 $arma,2538 "nCano",2539 $std->nCano,2540 true,2541 "$identificador [item $std->item] Número de série do cano"2542 );2543 $this->dom->addChild(2544 $arma,2545 "descr",2546 $std->descr,2547 true,2548 "$identificador [item $std->item] Descrição completa da arma, compreendendo: calibre, marca, capacidade, "2549 . "tipo de funcionamento, comprimento e demais elementos que "2550 . "permitam a sua perfeita identificação."2551 );2552 $this->aArma[$std->item][$std->nAR] = $arma;2553 return $arma;2554 }2555 /**2556 * Detalhamento de combustiveis L101 pai I902557 * tag NFe/infNFe/det[]/prod/comb (opcional)2558 * LA|cProdANP|pMixGN|CODIF|qTemp|UFCons|2559 *2560 * NOTA: Ajustado para NT2016_002_v1.302561 * LA|cProdANP|descANP|pGLP|pGNn|pGNi|vPart|CODIF|qTemp|UFCons|2562 * @param stdClass $std2563 * @return DOMElement2564 */2565 public function tagcomb(stdClass $std)2566 {2567 $possible = [2568 'item',2569 'cProdANP',2570 'descANP',2571 'pGLP',2572 'pGNn',2573 'pGNi',2574 'vPart',2575 'CODIF',2576 'qTemp',2577 'UFCons',2578 'qBCProd',2579 'vAliqProd',2580 'vCIDE'2581 ];2582 $std = $this->equilizeParameters($std, $possible);2583 $identificador = 'L101 <comb> - ';2584 $comb = $this->dom->createElement("comb");2585 $this->dom->addChild(2586 $comb,2587 "cProdANP",2588 $std->cProdANP,2589 true,2590 "$identificador [item $std->item] Código de produto da ANP"2591 );2592 //incluso no layout 4.002593 $this->dom->addChild(2594 $comb,2595 "descANP",2596 $std->descANP,2597 false,2598 "$identificador [item $std->item] Utilizar a descrição de produtos do "2599 . "Sistema de Informações de Movimentação de Produtos - "2600 . "SIMP (http://www.anp.gov.br/simp/"2601 );2602 //incluso no layout 4.002603 $this->dom->addChild(2604 $comb,2605 "pGLP",2606 $this->conditionalNumberFormatting($std->pGLP, 4),2607 false,2608 "$identificador [item $std->item] Percentual do GLP derivado do "2609 . "petróleo no produto GLP (cProdANP=210203001) 1v4"2610 );2611 //incluso no layout 4.002612 $this->dom->addChild(2613 $comb,2614 "pGNn",2615 $this->conditionalNumberFormatting($std->pGNn, 4),2616 false,2617 "$identificador [item $std->item] Percentual de Gás Natural Nacional"2618 . " – GLGNn para o produto GLP (cProdANP=210203001) 1v4"2619 );2620 //incluso no layout 4.002621 $this->dom->addChild(2622 $comb,2623 "pGNi",2624 $this->conditionalNumberFormatting($std->pGNi, 4),2625 false,2626 "$identificador [item $std->item] Percentual de Gás Natural Importado"2627 . " – GLGNi para o produto GLP (cProdANP=210203001) 1v4"2628 );2629 //incluso no layout 4.002630 $this->dom->addChild(2631 $comb,2632 "vPart",2633 $this->conditionalNumberFormatting($std->vPart),2634 false,2635 "$identificador [item $std->item] Valor de partida (cProdANP=210203001) "2636 );2637 $this->dom->addChild(2638 $comb,2639 "CODIF",2640 $std->CODIF,2641 false,2642 "[item $std->item] Código de autorização / registro do CODIF"2643 );2644 $this->dom->addChild(2645 $comb,2646 "qTemp",2647 $this->conditionalNumberFormatting($std->qTemp, 4),2648 false,2649 "$identificador [item $std->item] Quantidade de combustível faturada à temperatura ambiente."2650 );2651 $this->dom->addChild(2652 $comb,2653 "UFCons",2654 $std->UFCons,2655 true,2656 "[item $std->item] Sigla da UF de consumo"2657 );2658 if ($std->qBCProd != "") {2659 $tagCIDE = $this->dom->createElement("CIDE");2660 $this->dom->addChild(2661 $tagCIDE,2662 "qBCProd",2663 $std->qBCProd,2664 true,2665 "$identificador [item $std->item] BC da CIDE"2666 );2667 $this->dom->addChild(2668 $tagCIDE,2669 "vAliqProd",2670 $this->conditionalNumberFormatting($std->vAliqProd, 4),2671 true,2672 "$identificador [item $std->item] Valor da alíquota da CIDE"2673 );2674 $this->dom->addChild(2675 $tagCIDE,2676 "vCIDE",2677 $this->conditionalNumberFormatting($std->vCIDE),2678 true,2679 "$identificador [item $std->item] Valor da CIDE"2680 );2681 $this->dom->appChild($comb, $tagCIDE);2682 }2683 $this->aComb[$std->item] = $comb;2684 return $comb;2685 }2686 /**2687 * informações relacionadas com as operações de combustíveis, subgrupo de2688 * encerrante que permite o controle sobre as operações de venda de combustíveis2689 * LA11 pai LA012690 * tag NFe/infNFe/det[]/prod/comb/encerrante (opcional)2691 * @param stdClass $std2692 * @return DOMElement2693 */2694 public function tagencerrante(stdClass $std)2695 {2696 $possible = [2697 'item',2698 'nBico',2699 'nBomba',2700 'nTanque',2701 'vEncIni',2702 'vEncFin'2703 ];2704 $std = $this->equilizeParameters($std, $possible);2705 $identificador = 'LA11 <encerrante> - ';2706 $encerrante = $this->dom->createElement("encerrante");2707 $this->dom->addChild(2708 $encerrante,2709 "nBico",2710 $std->nBico,2711 true,2712 "$identificador [item $std->item] Número de identificação do bico utilizado no abastecimento"2713 );2714 $this->dom->addChild(2715 $encerrante,2716 "nBomba",2717 $std->nBomba,2718 false,2719 "$identificador [item $std->item] Número de identificação da bomba ao qual o bico está interligado"2720 );2721 $this->dom->addChild(2722 $encerrante,2723 "nTanque",2724 $std->nTanque,2725 true,2726 "$identificador [item $std->item] Número de identificação do tanque ao qual o bico está interligado"2727 );2728 $this->dom->addChild(2729 $encerrante,2730 "vEncIni",2731 $this->conditionalNumberFormatting($std->vEncIni),2732 true,2733 "$identificador [item $std->item] Valor do Encerrante no início do abastecimento"2734 );2735 $this->dom->addChild(2736 $encerrante,2737 "vEncFin",2738 $this->conditionalNumberFormatting($std->vEncFin),2739 true,2740 "$identificador [item $std->item] Valor do Encerrante no final do abastecimento"2741 );2742 $this->aEncerrante[$std->item] = $encerrante;2743 return $encerrante;2744 }2745 /**2746 * Impostos com o valor total tributado M01 pai H012747 * tag NFe/infNFe/det[]/imposto2748 * @param stdClass $std2749 * @return DOMElement2750 */2751 public function tagimposto(stdClass $std)2752 {2753 $possible = ['item', 'vTotTrib'];2754 $std = $this->equilizeParameters($std, $possible);2755 //totalizador dos valores dos itens2756 $this->stdTot->vTotTrib += (float) $std->vTotTrib;2757 $identificador = 'M01 <imposto> - ';2758 $imposto = $this->dom->createElement("imposto");2759 $this->dom->addChild(2760 $imposto,2761 "vTotTrib",2762 $this->conditionalNumberFormatting($std->vTotTrib),2763 false,2764 "$identificador [item $std->item] Valor aproximado total de tributos federais, estaduais e municipais."2765 );2766 $this->aImposto[$std->item] = $imposto;2767 return $imposto;2768 }2769 /**2770 * Informações do ICMS da Operação própria e ST N01 pai M012771 * tag NFe/infNFe/det[]/imposto/ICMS2772 * @param stdClass $std2773 * @return DOMElement2774 */2775 public function tagICMS(stdClass $std)2776 {2777 $possible = [2778 'item',2779 'orig',2780 'CST',2781 'modBC',2782 'vBC',2783 'pICMS',2784 'vICMS',2785 'pFCP',2786 'vFCP',2787 'vBCFCP',2788 'modBCST',2789 'pMVAST',2790 'pRedBCST',2791 'vBCST',2792 'pICMSST',2793 'vICMSST',2794 'vBCFCPST',2795 'pFCPST',2796 'vFCPST',2797 'vICMSDeson',2798 'motDesICMS',2799 'pRedBC',2800 'vICMSOp',2801 'pDif',2802 'vICMSDif',2803 'vBCSTRet',2804 'pST',2805 'vICMSSTRet',2806 'vBCFCPSTRet',2807 'pFCPSTRet',2808 'vFCPSTRet',2809 'pRedBCEfet',2810 'vBCEfet',2811 'pICMSEfet',2812 'vICMSEfet',2813 'vICMSSubstituto'2814 ];2815 $std = $this->equilizeParameters($std, $possible);2816 //totalização generica2817 $this->stdTot->vICMSDeson += (float) !empty($std->vICMSDeson) ? $std->vICMSDeson : 0;2818 $this->stdTot->vFCP += (float) !empty($std->vFCP) ? $std->vFCP : 0;2819 $this->stdTot->vFCPST += (float) !empty($std->vFCPST) ? $std->vFCPST : 0;2820 $this->stdTot->vFCPSTRet += (float) !empty($std->vFCPSTRet) ? $std->vFCPSTRet : 0;2821 $identificador = 'N01 <ICMSxx> - ';2822 switch ($std->CST) {2823 case '00':2824 $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;2825 $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;2826 $icms = $this->dom->createElement("ICMS00");2827 $this->dom->addChild(2828 $icms,2829 'orig',2830 $std->orig,2831 true,2832 "$identificador [item $std->item] Origem da mercadoria"2833 );2834 $this->dom->addChild(2835 $icms,2836 'CST',2837 $std->CST,2838 true,2839 "$identificador [item $std->item] Tributação do ICMS = 00"2840 );2841 $this->dom->addChild(2842 $icms,2843 'modBC',2844 $std->modBC,2845 true,2846 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"2847 );2848 $this->dom->addChild(2849 $icms,2850 'vBC',2851 $this->conditionalNumberFormatting($std->vBC),2852 true,2853 "$identificador [item $std->item] Valor da BC do ICMS"2854 );2855 $this->dom->addChild(2856 $icms,2857 'pICMS',2858 $this->conditionalNumberFormatting($std->pICMS, 4),2859 true,2860 "$identificador [item $std->item] Alíquota do imposto"2861 );2862 $this->dom->addChild(2863 $icms,2864 'vICMS',2865 $this->conditionalNumberFormatting($std->vICMS),2866 true,2867 "$identificador [item $std->item] Valor do ICMS"2868 );2869 $this->dom->addChild(2870 $icms,2871 'pFCP',2872 $this->conditionalNumberFormatting($std->pFCP, 4),2873 false,2874 "$identificador [item $std->item] Percentual do Fundo de "2875 . "Combate à Pobreza (FCP)"2876 );2877 $this->dom->addChild(2878 $icms,2879 'vFCP',2880 $this->conditionalNumberFormatting($std->vFCP),2881 false,2882 "$identificador [item $std->item] Valor do Fundo de Combate "2883 . "à Pobreza (FCP)"2884 );2885 break;2886 case '10':2887 $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;2888 $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;2889 $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;2890 $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;2891 $icms = $this->dom->createElement("ICMS10");2892 $this->dom->addChild(2893 $icms,2894 'orig',2895 $std->orig,2896 true,2897 "$identificador [item $std->item] Origem da mercadoria"2898 );2899 $this->dom->addChild(2900 $icms,2901 'CST',2902 $std->CST,2903 true,2904 "$identificador [item $std->item] Tributação do ICMS = 10"2905 );2906 $this->dom->addChild(2907 $icms,2908 'modBC',2909 $std->modBC,2910 true,2911 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"2912 );2913 $this->dom->addChild(2914 $icms,2915 'vBC',2916 $this->conditionalNumberFormatting($std->vBC),2917 true,2918 "$identificador [item $std->item] Valor da BC do ICMS"2919 );2920 $this->dom->addChild(2921 $icms,2922 'pICMS',2923 $this->conditionalNumberFormatting($std->pICMS, 4),2924 true,2925 "$identificador [item $std->item] Alíquota do imposto"2926 );2927 $this->dom->addChild(2928 $icms,2929 'vICMS',2930 $this->conditionalNumberFormatting($std->vICMS),2931 true,2932 "$identificador [item $std->item] Valor do ICMS"2933 );2934 $this->dom->addChild(2935 $icms,2936 'vBCFCP',2937 $this->conditionalNumberFormatting($std->vBCFCP),2938 false,2939 "$identificador [item $std->item] Valor da Base de Cálculo do FCP"2940 );2941 $this->dom->addChild(2942 $icms,2943 'pFCP',2944 $this->conditionalNumberFormatting($std->pFCP, 4),2945 false,2946 "$identificador [item $std->item] Percentual do Fundo de "2947 . "Combate à Pobreza (FCP)"2948 );2949 $this->dom->addChild(2950 $icms,2951 'vFCP',2952 $this->conditionalNumberFormatting($std->vFCP),2953 false,2954 "$identificador [item $std->item] Valor do FCP"2955 );2956 $this->dom->addChild(2957 $icms,2958 'modBCST',2959 $std->modBCST,2960 true,2961 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS ST"2962 );2963 $this->dom->addChild(2964 $icms,2965 'pMVAST',2966 $this->conditionalNumberFormatting($std->pMVAST, 4),2967 false,2968 "$identificador [item $std->item] Percentual da margem de valor Adicionado do ICMS ST"2969 );2970 $this->dom->addChild(2971 $icms,2972 'pRedBCST',2973 $this->conditionalNumberFormatting($std->pRedBCST, 4),2974 false,2975 "$identificador [item $std->item] Percentual da Redução de BC do ICMS ST"2976 );2977 $this->dom->addChild(2978 $icms,2979 'vBCST',2980 $this->conditionalNumberFormatting($std->vBCST),2981 true,2982 "$identificador [item $std->item] Valor da BC do ICMS ST"2983 );2984 $this->dom->addChild(2985 $icms,2986 'pICMSST',2987 $this->conditionalNumberFormatting($std->pICMSST, 4),2988 true,2989 "$identificador [item $std->item] Alíquota do imposto do ICMS ST"2990 );2991 $this->dom->addChild(2992 $icms,2993 'vICMSST',2994 $this->conditionalNumberFormatting($std->vICMSST),2995 true,2996 "$identificador [item $std->item] Valor do ICMS ST"2997 );2998 $this->dom->addChild(2999 $icms,3000 'vBCFCPST',3001 $this->conditionalNumberFormatting($std->vBCFCPST),3002 false,3003 "$identificador [item $std->item] Valor da Base de Cálculo do FCP ST"3004 );3005 $this->dom->addChild(3006 $icms,3007 'pFCPST',3008 $this->conditionalNumberFormatting($std->pFCPST, 4),3009 false,3010 "$identificador [item $std->item] Percentual do Fundo de "3011 . "Combate à Pobreza (FCP) ST"3012 );3013 $this->dom->addChild(3014 $icms,3015 'vFCPST',3016 $this->conditionalNumberFormatting($std->vFCPST),3017 false,3018 "$identificador [item $std->item] Valor do FCP ST"3019 );3020 break;3021 case '20':3022 $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;3023 $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;3024 $icms = $this->dom->createElement("ICMS20");3025 $this->dom->addChild(3026 $icms,3027 'orig',3028 $std->orig,3029 true,3030 "$identificador [item $std->item] Origem da mercadoria"3031 );3032 $this->dom->addChild(3033 $icms,3034 'CST',3035 $std->CST,3036 true,3037 "$identificador [item $std->item] Tributação do ICMS = 20"3038 );3039 $this->dom->addChild(3040 $icms,3041 'modBC',3042 $std->modBC,3043 true,3044 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"3045 );3046 $this->dom->addChild(3047 $icms,3048 'pRedBC',3049 $this->conditionalNumberFormatting($std->pRedBC, 4),3050 true,3051 "$identificador [item $std->item] Percentual da Redução de BC"3052 );3053 $this->dom->addChild(3054 $icms,3055 'vBC',3056 $this->conditionalNumberFormatting($std->vBC),3057 true,3058 "$identificador [item $std->item] Valor da BC do ICMS"3059 );3060 $this->dom->addChild(3061 $icms,3062 'pICMS',3063 $this->conditionalNumberFormatting($std->pICMS, 4),3064 true,3065 "$identificador [item $std->item] Alíquota do imposto"3066 );3067 $this->dom->addChild(3068 $icms,3069 'vICMS',3070 $this->conditionalNumberFormatting($std->vICMS),3071 true,3072 "$identificador [item $std->item] Valor do ICMS"3073 );3074 $this->dom->addChild(3075 $icms,3076 'vBCFCP',3077 $this->conditionalNumberFormatting($std->vBCFCP),3078 false,3079 "$identificador [item $std->item] Valor da Base de Cálculo do FCP"3080 );3081 $this->dom->addChild(3082 $icms,3083 'pFCP',3084 $this->conditionalNumberFormatting($std->pFCP, 4),3085 false,3086 "$identificador [item $std->item] Percentual do Fundo de "3087 . "Combate à Pobreza (FCP)"3088 );3089 $this->dom->addChild(3090 $icms,3091 'vFCP',3092 $this->conditionalNumberFormatting($std->vFCP),3093 false,3094 "$identificador [item $std->item] Valor do FCP"3095 );3096 $this->dom->addChild(3097 $icms,3098 'vICMSDeson',3099 $this->conditionalNumberFormatting($std->vICMSDeson),3100 false,3101 "$identificador [item $std->item] Valor do ICMS desonerado"3102 );3103 $this->dom->addChild(3104 $icms,3105 'motDesICMS',3106 $std->motDesICMS,3107 false,3108 "$identificador [item $std->item] Motivo da desoneração do ICMS"3109 );3110 break;3111 case '30':3112 $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;3113 $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;3114 $icms = $this->dom->createElement("ICMS30");3115 $this->dom->addChild(3116 $icms,3117 'orig',3118 $std->orig,3119 true,3120 "$identificador [item $std->item] Origem da mercadoria"3121 );3122 $this->dom->addChild(3123 $icms,3124 'CST',3125 $std->CST,3126 true,3127 "$identificador [item $std->item] Tributação do ICMS = 30"3128 );3129 $this->dom->addChild(3130 $icms,3131 'modBCST',3132 $std->modBCST,3133 true,3134 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS ST"3135 );3136 $this->dom->addChild(3137 $icms,3138 'pMVAST',3139 $this->conditionalNumberFormatting($std->pMVAST, 4),3140 false,3141 "$identificador [item $std->item] Percentual da margem de valor Adicionado do ICMS ST"3142 );3143 $this->dom->addChild(3144 $icms,3145 'pRedBCST',3146 $this->conditionalNumberFormatting($std->pRedBCST, 4),3147 false,3148 "$identificador [item $std->item] Percentual da Redução de BC do ICMS ST"3149 );3150 $this->dom->addChild(3151 $icms,3152 'vBCST',3153 $this->conditionalNumberFormatting($std->vBCST),3154 true,3155 "$identificador [item $std->item] Valor da BC do ICMS ST"3156 );3157 $this->dom->addChild(3158 $icms,3159 'pICMSST',3160 $this->conditionalNumberFormatting($std->pICMSST, 4),3161 true,3162 "$identificador [item $std->item] Alíquota do imposto do ICMS ST"3163 );3164 $this->dom->addChild(3165 $icms,3166 'vICMSST',3167 $this->conditionalNumberFormatting($std->vICMSST),3168 true,3169 "$identificador [item $std->item] Valor do ICMS ST"3170 );3171 $this->dom->addChild(3172 $icms,3173 'vBCFCPST',3174 $this->conditionalNumberFormatting($std->vBCFCPST),3175 false,3176 "$identificador [item $std->item] Valor da Base de Cálculo do FCP ST"3177 );3178 $this->dom->addChild(3179 $icms,3180 'pFCPST',3181 $this->conditionalNumberFormatting($std->pFCPST, 4),3182 false,3183 "$identificador [item $std->item] Percentual do Fundo de "3184 . "Combate à Pobreza (FCP) ST"3185 );3186 $this->dom->addChild(3187 $icms,3188 'vFCPST',3189 $this->conditionalNumberFormatting($std->vFCPST),3190 false,3191 "$identificador [item $std->item] Valor do FCP ST"3192 );3193 $this->dom->addChild(3194 $icms,3195 'vICMSDeson',3196 $this->conditionalNumberFormatting($std->vICMSDeson),3197 false,3198 "$identificador [item $std->item] Valor do ICMS desonerado"3199 );3200 $this->dom->addChild(3201 $icms,3202 'motDesICMS',3203 $std->motDesICMS,3204 false,3205 "$identificador [item $std->item] Motivo da desoneração do ICMS"3206 );3207 break;3208 case '40':3209 case '41':3210 case '50':3211 $icms = $this->dom->createElement("ICMS40");3212 $this->dom->addChild(3213 $icms,3214 'orig',3215 $std->orig,3216 true,3217 "$identificador [item $std->item] Origem da mercadoria"3218 );3219 $this->dom->addChild(3220 $icms,3221 'CST',3222 $std->CST,3223 true,3224 "$identificador [item $std->item] Tributação do ICMS $std->CST"3225 );3226 $this->dom->addChild(3227 $icms,3228 'vICMSDeson',3229 $this->conditionalNumberFormatting($std->vICMSDeson),3230 false,3231 "$identificador [item $std->item] Valor do ICMS desonerado"3232 );3233 $this->dom->addChild(3234 $icms,3235 'motDesICMS',3236 $std->motDesICMS,3237 false,3238 "$identificador [item $std->item] Motivo da desoneração do ICMS"3239 );3240 break;3241 case '51':3242 $icms = $this->dom->createElement("ICMS51");3243 $this->dom->addChild(3244 $icms,3245 'orig',3246 $std->orig,3247 true,3248 "$identificador [item $std->item] Origem da mercadoria"3249 );3250 $this->dom->addChild(3251 $icms,3252 'CST',3253 $std->CST,3254 true,3255 "$identificador [item $std->item] Tributação do ICMS = 51"3256 );3257 $this->dom->addChild(3258 $icms,3259 'modBC',3260 $std->modBC,3261 false,3262 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"3263 );3264 $this->dom->addChild(3265 $icms,3266 'pRedBC',3267 $this->conditionalNumberFormatting($std->pRedBC, 4),3268 false,3269 "$identificador [item $std->item] Percentual da Redução de BC"3270 );3271 $this->dom->addChild(3272 $icms,3273 'vBC',3274 $this->conditionalNumberFormatting($std->vBC),3275 false,3276 "$identificador [item $std->item] Valor da BC do ICMS"3277 );3278 $this->dom->addChild(3279 $icms,3280 'pICMS',3281 $this->conditionalNumberFormatting($std->pICMS, 4),3282 false,3283 "$identificador [item $std->item] Alíquota do imposto"3284 );3285 $this->dom->addChild(3286 $icms,3287 'vICMSOp',3288 $this->conditionalNumberFormatting($std->vICMSOp),3289 false,3290 "$identificador [item $std->item] Valor do ICMS da Operação"3291 );3292 $this->dom->addChild(3293 $icms,3294 'pDif',3295 $this->conditionalNumberFormatting($std->pDif, 4),3296 false,3297 "$identificador [item $std->item] Percentual do diferimento"3298 );3299 $this->dom->addChild(3300 $icms,3301 'vICMSDif',3302 $this->conditionalNumberFormatting($std->vICMSDif),3303 false,3304 "$identificador [item $std->item] Valor do ICMS diferido"3305 );3306 $this->dom->addChild(3307 $icms,3308 'vICMS',3309 $this->conditionalNumberFormatting($std->vICMS),3310 false,3311 "$identificador [item $std->item] Valor do ICMS realmente devido"3312 );3313 $this->dom->addChild(3314 $icms,3315 'vBCFCP',3316 $this->conditionalNumberFormatting($std->vBCFCP),3317 false,3318 "$identificador [item $std->item] Valor da Base de Cálculo do FCP"3319 );3320 $this->dom->addChild(3321 $icms,3322 'pFCP',3323 $this->conditionalNumberFormatting($std->pFCP, 4),3324 false,3325 "$identificador [item $std->item] Percentual do Fundo de "3326 . "Combate à Pobreza (FCP)"3327 );3328 $this->dom->addChild(3329 $icms,3330 'vFCP',3331 $this->conditionalNumberFormatting($std->vFCP),3332 false,3333 "$identificador [item $std->item] Valor do FCP"3334 );3335 break;3336 case '60':3337 $icms = $this->dom->createElement("ICMS60");3338 $this->dom->addChild(3339 $icms,3340 'orig',3341 $std->orig,3342 true,3343 "$identificador [item $std->item] Origem da mercadoria"3344 );3345 $this->dom->addChild(3346 $icms,3347 'CST',3348 $std->CST,3349 true,3350 "$identificador [item $std->item] Tributação do ICMS = 60"3351 );3352 $this->dom->addChild(3353 $icms,3354 'vBCSTRet',3355 $this->conditionalNumberFormatting($std->vBCSTRet),3356 false,3357 "$identificador [item $std->item] Valor da BC do ICMS ST retido"3358 );3359 $this->dom->addChild(3360 $icms,3361 'pST',3362 $this->conditionalNumberFormatting($std->pST, 4),3363 false,3364 "$identificador [item $std->item] Valor do ICMS ST retido"3365 );3366 $this->dom->addChild(3367 $icms,3368 'vICMSSubstituto',3369 $this->conditionalNumberFormatting($std->vICMSSubstituto),3370 false,3371 "$identificador [item $std->item] Valor do ICMS próprio do Substituto"3372 );3373 $this->dom->addChild(3374 $icms,3375 'vICMSSTRet',3376 $this->conditionalNumberFormatting($std->vICMSSTRet),3377 false,3378 "$identificador [item $std->item] Valor do ICMS ST retido"3379 );3380 $this->dom->addChild(3381 $icms,3382 'vBCFCPSTRet',3383 $this->conditionalNumberFormatting($std->vBCFCPSTRet),3384 false,3385 "$identificador [item $std->item] Valor da Base de Cálculo "3386 . "do FCP retido anteriormente por ST"3387 );3388 $this->dom->addChild(3389 $icms,3390 'pFCPSTRet',3391 $this->conditionalNumberFormatting($std->pFCPSTRet, 4),3392 false,3393 "$identificador [item $std->item] Percentual do FCP retido "3394 . "anteriormente por Substituição Tributária"3395 );3396 $this->dom->addChild(3397 $icms,3398 'vFCPSTRet',3399 $this->conditionalNumberFormatting($std->vFCPSTRet),3400 false,3401 "$identificador [item $std->item] Valor do FCP retido por "3402 . "Substituição Tributária"3403 );3404 $this->dom->addChild(3405 $icms,3406 'pRedBCEfet',3407 $this->conditionalNumberFormatting($std->pRedBCEfet, 4),3408 false,3409 "$identificador [item $std->item] Percentual de redução "3410 . "para obtenção da base de cálculo efetiva (vBCEfet)"3411 );3412 $this->dom->addChild(3413 $icms,3414 'vBCEfet',3415 $this->conditionalNumberFormatting($std->vBCEfet),3416 false,3417 "$identificador [item $std->item] base de calculo efetiva"3418 );3419 $this->dom->addChild(3420 $icms,3421 'pICMSEfet',3422 $this->conditionalNumberFormatting($std->pICMSEfet, 4),3423 false,3424 "$identificador [item $std->item] Alíquota do ICMS na operação a consumidor final"3425 );3426 $this->dom->addChild(3427 $icms,3428 'vICMSEfet',3429 $this->conditionalNumberFormatting($std->vICMSEfet),3430 false,3431 "$identificador [item $std->item] Valor do ICMS efetivo"3432 );3433 break;3434 case '70':3435 $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;3436 $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;3437 $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;3438 $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;3439 $icms = $this->dom->createElement("ICMS70");3440 $this->dom->addChild(3441 $icms,3442 'orig',3443 $std->orig,3444 true,3445 "$identificador [item $std->item] Origem da mercadoria"3446 );3447 $this->dom->addChild(3448 $icms,3449 'CST',3450 $std->CST,3451 true,3452 "$identificador [item $std->item] Tributação do ICMS = 70"3453 );3454 $this->dom->addChild(3455 $icms,3456 'modBC',3457 $std->modBC,3458 true,3459 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"3460 );3461 $this->dom->addChild(3462 $icms,3463 'pRedBC',3464 $this->conditionalNumberFormatting($std->pRedBC, 4),3465 true,3466 "$identificador [item $std->item] Percentual da Redução de BC"3467 );3468 $this->dom->addChild(3469 $icms,3470 'vBC',3471 $this->conditionalNumberFormatting($std->vBC),3472 true,3473 "$identificador [item $std->item] Valor da BC do ICMS"3474 );3475 $this->dom->addChild(3476 $icms,3477 'pICMS',3478 $this->conditionalNumberFormatting($std->pICMS, 4),3479 true,3480 "$identificador [item $std->item] Alíquota do imposto"3481 );3482 $this->dom->addChild(3483 $icms,3484 'vICMS',3485 $this->conditionalNumberFormatting($std->vICMS),3486 true,3487 "$identificador [item $std->item] Valor do ICMS"3488 );3489 $this->dom->addChild(3490 $icms,3491 'vBCFCP',3492 $this->conditionalNumberFormatting($std->vBCFCP),3493 false,3494 "$identificador [item $std->item] Valor da Base de Cálculo do FCP"3495 );3496 $this->dom->addChild(3497 $icms,3498 'pFCP',3499 $this->conditionalNumberFormatting($std->pFCP, 4),3500 false,3501 "$identificador [item $std->item] Percentual do Fundo de "3502 . "Combate à Pobreza (FCP)"3503 );3504 $this->dom->addChild(3505 $icms,3506 'vFCP',3507 $std->vFCP,3508 false,3509 "$identificador [item $std->item] Valor do FCP"3510 );3511 $this->dom->addChild(3512 $icms,3513 'modBCST',3514 $std->modBCST,3515 true,3516 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS ST"3517 );3518 $this->dom->addChild(3519 $icms,3520 'pMVAST',3521 $this->conditionalNumberFormatting($std->pMVAST, 4),3522 false,3523 "$identificador [item $std->item] Percentual da margem de valor Adicionado do ICMS ST"3524 );3525 $this->dom->addChild(3526 $icms,3527 'pRedBCST',3528 $this->conditionalNumberFormatting($std->pRedBCST, 4),3529 false,3530 "$identificador [item $std->item] Percentual da Redução de BC do ICMS ST"3531 );3532 $this->dom->addChild(3533 $icms,3534 'vBCST',3535 $this->conditionalNumberFormatting($std->vBCST),3536 true,3537 "$identificador [item $std->item] Valor da BC do ICMS ST"3538 );3539 $this->dom->addChild(3540 $icms,3541 'pICMSST',3542 $this->conditionalNumberFormatting($std->pICMSST, 4),3543 true,3544 "$identificador [item $std->item] Alíquota do imposto do ICMS ST"3545 );3546 $this->dom->addChild(3547 $icms,3548 'vICMSST',3549 $this->conditionalNumberFormatting($std->vICMSST),3550 true,3551 "$identificador [item $std->item] Valor do ICMS ST"3552 );3553 $this->dom->addChild(3554 $icms,3555 'vBCFCPST',3556 $this->conditionalNumberFormatting($std->vBCFCPST),3557 false,3558 "$identificador [item $std->item] Valor da Base de Cálculo do FCP ST"3559 );3560 $this->dom->addChild(3561 $icms,3562 'pFCPST',3563 $this->conditionalNumberFormatting($std->pFCPST, 4),3564 false,3565 "$identificador [item $std->item] Percentual do Fundo de "3566 . "Combate à Pobreza (FCP) ST"3567 );3568 $this->dom->addChild(3569 $icms,3570 'vFCPST',3571 $this->conditionalNumberFormatting($std->vFCPST),3572 false,3573 "$identificador [item $std->item] Valor do FCP ST"3574 );3575 $this->dom->addChild(3576 $icms,3577 'vICMSDeson',3578 $this->conditionalNumberFormatting($std->vICMSDeson),3579 false,3580 "$identificador [item $std->item] Valor do ICMS desonerado"3581 );3582 $this->dom->addChild(3583 $icms,3584 'motDesICMS',3585 $std->motDesICMS,3586 false,3587 "$identificador [item $std->item] Motivo da desoneração do ICMS"3588 );3589 break;3590 case '90':3591 $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;3592 $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;3593 $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;3594 $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;3595 $icms = $this->dom->createElement("ICMS90");3596 $this->dom->addChild(3597 $icms,3598 'orig',3599 $std->orig,3600 true,3601 "$identificador [item $std->item] Origem da mercadoria"3602 );3603 $this->dom->addChild(3604 $icms,3605 'CST',3606 $std->CST,3607 true,3608 "$identificador [item $std->item] Tributação do ICMS = 90"3609 );3610 $this->dom->addChild(3611 $icms,3612 'modBC',3613 $std->modBC,3614 false,3615 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"3616 );3617 $this->dom->addChild(3618 $icms,3619 'vBC',3620 $this->conditionalNumberFormatting($std->vBC),3621 false,3622 "$identificador [item $std->item] Valor da BC do ICMS"3623 );3624 $this->dom->addChild(3625 $icms,3626 'pRedBC',3627 $this->conditionalNumberFormatting($std->pRedBC, 4),3628 false,3629 "$identificador [item $std->item] Percentual da Redução de BC"3630 );3631 $this->dom->addChild(3632 $icms,3633 'pICMS',3634 $this->conditionalNumberFormatting($std->pICMS, 4),3635 false,3636 "$identificador [item $std->item] Alíquota do imposto"3637 );3638 $this->dom->addChild(3639 $icms,3640 'vICMS',3641 $this->conditionalNumberFormatting($std->vICMS),3642 false,3643 "$identificador [item $std->item] Valor do ICMS"3644 );3645 $this->dom->addChild(3646 $icms,3647 'vBCFCP',3648 $this->conditionalNumberFormatting($std->vBCFCP),3649 false,3650 "$identificador [item $std->item] Valor da Base de Cálculo do FCP"3651 );3652 $this->dom->addChild(3653 $icms,3654 'pFCP',3655 $this->conditionalNumberFormatting($std->pFCP, 4),3656 false,3657 "$identificador [item $std->item] Percentual do Fundo de "3658 . "Combate à Pobreza (FCP)"3659 );3660 $this->dom->addChild(3661 $icms,3662 'vFCP',3663 $this->conditionalNumberFormatting($std->vFCP),3664 false,3665 "$identificador [item $std->item] Valor do FCP"3666 );3667 $this->dom->addChild(3668 $icms,3669 'modBCST',3670 $std->modBCST,3671 false,3672 "$identificador [item $std->item] Modalidade de determinação da BC do ICMS ST"3673 );3674 $this->dom->addChild(3675 $icms,3676 'pMVAST',3677 $this->conditionalNumberFormatting($std->pMVAST, 4),3678 false,3679 "$identificador [item $std->item] Percentual da margem de valor Adicionado do ICMS ST"3680 );3681 $this->dom->addChild(3682 $icms,3683 'pRedBCST',3684 $this->conditionalNumberFormatting($std->pRedBCST, 4),3685 false,3686 "$identificador [item $std->item] Percentual da Redução de BC do ICMS ST"3687 );3688 $this->dom->addChild(3689 $icms,3690 'vBCST',3691 $this->conditionalNumberFormatting($std->vBCST),3692 false,3693 "$identificador [item $std->item] Valor da BC do ICMS ST"3694 );3695 $this->dom->addChild(3696 $icms,3697 'pICMSST',3698 $this->conditionalNumberFormatting($std->pICMSST, 4),3699 false,3700 "$identificador [item $std->item] Alíquota do imposto do ICMS ST"3701 );3702 $this->dom->addChild(3703 $icms,3704 'vICMSST',3705 $this->conditionalNumberFormatting($std->vICMSST),3706 false,3707 "$identificador [item $std->item] Valor do ICMS ST"3708 );3709 $this->dom->addChild(3710 $icms,3711 'vBCFCPST',3712 $this->conditionalNumberFormatting($std->vBCFCPST),3713 false,3714 "$identificador [item $std->item] Valor da Base de Cálculo do FCP ST"3715 );3716 $this->dom->addChild(3717 $icms,3718 'pFCPST',3719 $this->conditionalNumberFormatting($std->pFCPST, 4),3720 false,3721 "$identificador [item $std->item] Percentual do Fundo de "3722 . "Combate à Pobreza (FCP) ST"3723 );3724 $this->dom->addChild(3725 $icms,3726 'vFCPST',3727 $this->conditionalNumberFormatting($std->vFCPST),3728 false,3729 "$identificador [item $std->item] Valor do FCP ST"3730 );3731 $this->dom->addChild(3732 $icms,3733 'vICMSDeson',3734 $this->conditionalNumberFormatting($std->vICMSDeson),3735 false,3736 "$identificador [item $std->item] Valor do ICMS desonerado"3737 );3738 $this->dom->addChild(3739 $icms,3740 'motDesICMS',3741 $std->motDesICMS,3742 false,3743 "$identificador [item $std->item] Motivo da desoneração do ICMS"3744 );3745 break;3746 }3747 $tagIcms = $this->dom->createElement('ICMS');3748 if (isset($icms)) {3749 $tagIcms->appendChild($icms);3750 }3751 $this->aICMS[$std->item] = $tagIcms;3752 return $tagIcms;3753 }3754 /**3755 * Grupo de Partilha do ICMS entre a UF de origem e UF de destino ou3756 * a UF definida na legislação. N10a pai N013757 * tag NFe/infNFe/det[]/imposto/ICMS/ICMSPart3758 * @param stdClass $std3759 * @return DOMElement3760 */3761 public function tagICMSPart(stdClass $std)3762 {3763 $possible = [3764 'item',3765 'orig',3766 'CST',3767 'modBC',3768 'vBC',3769 'pRedBC',3770 'pICMS',3771 'vICMS',3772 'modBCST',3773 'pMVAST',3774 'pRedBCST',3775 'vBCST',3776 'pICMSST',3777 'vICMSST',3778 'pBCOp',3779 'UFST'3780 ];3781 $std = $this->equilizeParameters($std, $possible);3782 $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;3783 $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;3784 $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;3785 $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;3786 $icmsPart = $this->dom->createElement("ICMSPart");3787 $this->dom->addChild(3788 $icmsPart,3789 'orig',3790 $std->orig,3791 true,3792 "[item $std->item] Origem da mercadoria"3793 );3794 $this->dom->addChild(3795 $icmsPart,3796 'CST',3797 $std->CST,3798 true,3799 "[item $std->item] Tributação do ICMS 10 ou 90"3800 );3801 $this->dom->addChild(3802 $icmsPart,3803 'modBC',3804 $std->modBC,3805 true,3806 "[item $std->item] Modalidade de determinação da BC do ICMS"3807 );3808 $this->dom->addChild(3809 $icmsPart,3810 'vBC',3811 $this->conditionalNumberFormatting($std->vBC),3812 true,3813 "[item $std->item] Valor da BC do ICMS"3814 );3815 $this->dom->addChild(3816 $icmsPart,3817 'pRedBC',3818 $this->conditionalNumberFormatting($std->pRedBC, 4),3819 false,3820 "[item $std->item] Percentual da Redução de BC"3821 );3822 $this->dom->addChild(3823 $icmsPart,3824 'pICMS',3825 $this->conditionalNumberFormatting($std->pICMS, 4),3826 true,3827 "[item $std->item] Alíquota do imposto"3828 );3829 $this->dom->addChild(3830 $icmsPart,3831 'vICMS',3832 $this->conditionalNumberFormatting($std->vICMS),3833 true,3834 "[item $std->item] Valor do ICMS"3835 );3836 $this->dom->addChild(3837 $icmsPart,3838 'modBCST',3839 $std->modBCST,3840 true,3841 "[item $std->item] Modalidade de determinação da BC do ICMS ST"3842 );3843 $this->dom->addChild(3844 $icmsPart,3845 'pMVAST',3846 $this->conditionalNumberFormatting($std->pMVAST, 4),3847 false,3848 "[item $std->item] Percentual da margem de valor Adicionado do ICMS ST"3849 );3850 $this->dom->addChild(3851 $icmsPart,3852 'pRedBCST',3853 $this->conditionalNumberFormatting($std->pRedBCST, 4),3854 false,3855 "[item $std->item] Percentual da Redução de BC do ICMS ST"3856 );3857 $this->dom->addChild(3858 $icmsPart,3859 'vBCST',3860 $this->conditionalNumberFormatting($std->vBCST),3861 true,3862 "[item $std->item] Valor da BC do ICMS ST"3863 );3864 $this->dom->addChild(3865 $icmsPart,3866 'pICMSST',3867 $this->conditionalNumberFormatting($std->pICMSST, 4),3868 true,3869 "[item $std->item] Alíquota do imposto do ICMS ST"3870 );3871 $this->dom->addChild(3872 $icmsPart,3873 'vICMSST',3874 $this->conditionalNumberFormatting($std->vICMSST),3875 true,3876 "[item $std->item] Valor do ICMS ST"3877 );3878 $this->dom->addChild(3879 $icmsPart,3880 'pBCOp',3881 $this->conditionalNumberFormatting($std->pBCOp, 4),3882 true,3883 "[item $std->item] Percentual da BC operação própria"3884 );3885 $this->dom->addChild(3886 $icmsPart,3887 'UFST',3888 $std->UFST,3889 true,3890 "[item $std->item] UF para qual é devido o ICMS ST"3891 );3892 //caso exista a tag aICMS[$std->item] inserir nela caso contrario criar3893 if (!empty($this->aICMS[$std->item])) {3894 $tagIcms = $this->aICMS[$std->item];3895 } else {3896 $tagIcms = $this->dom->createElement('ICMS');3897 }3898 $this->dom->appChild($tagIcms, $icmsPart, "Inserindo ICMSPart em ICMS[$std->item]");3899 $this->aICMS[$std->item] = $tagIcms;3900 return $tagIcms;3901 }3902 /**3903 * Grupo de Repasse de ICMSST retido anteriormente em operações3904 * interestaduais com repasses através do Substituto Tributário3905 * NOTA: ajustado NT 2018.0053906 * tag NFe/infNFe/det[]/imposto/ICMS/ICMSST N10b pai N013907 * @param stdClass $std3908 * @return DOMElement3909 */3910 public function tagICMSST(stdClass $std)3911 {3912 $possible = [3913 'item',3914 'orig',3915 'CST',3916 'vBCSTRet',3917 'vICMSSTRet',3918 'vBCSTDest',3919 'vICMSSTDest',3920 'vBCFCPSTRet',3921 'pFCPSTRet',3922 'vFCPSTRet',3923 'pST',3924 'vICMSSubstituto',3925 'pRedBCEfet',3926 'vBCEfet',3927 'pICMSEfet',3928 'vICMSEfet'3929 ];3930 $std = $this->equilizeParameters($std, $possible);3931 $icmsST = $this->dom->createElement("ICMSST");3932 $this->dom->addChild(3933 $icmsST,3934 'orig',3935 $std->orig,3936 true,3937 "[item $std->item] Origem da mercadoria"3938 );3939 $this->dom->addChild(3940 $icmsST,3941 'CST',3942 $std->CST,3943 true,3944 "[item $std->item] Tributação do ICMS 41 ou 60"3945 );3946 $this->dom->addChild(3947 $icmsST,3948 'vBCSTRet',3949 $this->conditionalNumberFormatting($std->vBCSTRet),3950 true,3951 "[item $std->item] Valor do BC do ICMS ST retido na UF remetente"3952 );3953 $this->dom->addChild(3954 $icmsST,3955 'pST',3956 $this->conditionalNumberFormatting($std->pST, 4),3957 false,3958 "[item $std->item] Alíquota suportada pelo Consumidor Final"3959 );3960 $this->dom->addChild(3961 $icmsST,3962 'vICMSSubstituto',3963 $this->conditionalNumberFormatting($std->vICMSSubstituto),3964 false,3965 "[item $std->item] Valor do ICMS próprio do Substituto"3966 );3967 $this->dom->addChild(3968 $icmsST,3969 'vICMSSTRet',3970 $this->conditionalNumberFormatting($std->vICMSSTRet),3971 true,3972 "[item $std->item] Valor do ICMS ST retido na UF remetente"3973 );3974 $this->dom->addChild(3975 $icmsST,3976 'vBCFCPSTRet',3977 $this->conditionalNumberFormatting($std->vBCFCPSTRet),3978 false,3979 "[item $std->item] Valor da Base de Cálculo do FCP"3980 );3981 $this->dom->addChild(3982 $icmsST,3983 'pFCPSTRet',3984 $this->conditionalNumberFormatting($std->pFCPSTRet, 4),3985 false,3986 "[item $std->item] Percentual do FCP retido"3987 );3988 $this->dom->addChild(3989 $icmsST,3990 'vFCPSTRet',3991 $this->conditionalNumberFormatting($std->vFCPSTRet),3992 false,3993 "[item $std->item] Valor do FCP retido"3994 );3995 $this->dom->addChild(3996 $icmsST,3997 'vBCSTDest',3998 $this->conditionalNumberFormatting($std->vBCSTDest),3999 true,4000 "[item $std->item] Valor da BC do ICMS ST da UF destino"4001 );4002 $this->dom->addChild(4003 $icmsST,4004 'vICMSSTDest',4005 $this->conditionalNumberFormatting($std->vICMSSTDest),4006 true,4007 "[item $std->item] Valor do ICMS ST da UF destino"4008 );4009 $this->dom->addChild(4010 $icmsST,4011 'pRedBCEfet',4012 $this->conditionalNumberFormatting($std->pRedBCEfet, 4),4013 false,4014 "[item $std->item] Percentual de redução da base de cálculo efetiva"4015 );4016 $this->dom->addChild(4017 $icmsST,4018 'vBCEfet',4019 $this->conditionalNumberFormatting($std->vBCEfet),4020 false,4021 "[item $std->item] Valor da base de cálculo efetiva"4022 );4023 $this->dom->addChild(4024 $icmsST,4025 'pICMSEfet',4026 $this->conditionalNumberFormatting($std->pICMSEfet, 4),4027 false,4028 "[item $std->item] Alíquota do ICMS efetiva"4029 );4030 $this->dom->addChild(4031 $icmsST,4032 'vICMSEfet',4033 $this->conditionalNumberFormatting($std->vICMSEfet),4034 false,4035 "[item $std->item] Valor do ICMS efetivo"4036 );4037 //caso exista a tag aICMS[$std->item] inserir nela caso contrario criar4038 if (!empty($this->aICMS[$std->item])) {4039 $tagIcms = $this->aICMS[$std->item];4040 } else {4041 $tagIcms = $this->dom->createElement('ICMS');4042 }4043 $this->dom->appChild($tagIcms, $icmsST, "Inserindo ICMSST em ICMS[$std->item]");4044 $this->aICMS[$std->item] = $tagIcms;4045 return $tagIcms;4046 }4047 /**4048 * Tributação ICMS pelo Simples Nacional N10c pai N014049 * tag NFe/infNFe/det[]/imposto/ICMS/ICMSSN N10c pai N014050 * @param stdClass $std4051 * @return DOMElement4052 */4053 public function tagICMSSN(stdClass $std)4054 {4055 $possible = [4056 'item',4057 'orig',4058 'CSOSN',4059 'pCredSN',4060 'vCredICMSSN',4061 'modBCST',4062 'pMVAST',4063 'pRedBCST',4064 'vBCST',4065 'pICMSST',4066 'vICMSST',4067 'vBCFCPST',4068 'pFCPST',4069 'vFCPST',4070 'vBCSTRet',4071 'pST',4072 'vICMSSTRet',4073 'vBCFCPSTRet',4074 'pFCPSTRet',4075 'vFCPSTRet',4076 'modBC',4077 'vBC',4078 'pRedBC',4079 'pICMS',4080 'vICMS',4081 'pRedBCEfet',4082 'vBCEfet',4083 'pICMSEfet',4084 'vICMSEfet',4085 'vICMSSubstituto'4086 ];4087 $std = $this->equilizeParameters($std, $possible);4088 //totalizador generico4089 $this->stdTot->vFCPST += (float) !empty($std->vFCPST) ? $std->vFCPST : 0;4090 $this->stdTot->vFCPSTRet += (float) !empty($std->vFCPSTRet) ? $std->vFCPSTRet : 0;4091 switch ($std->CSOSN) {4092 case '101':4093 $icmsSN = $this->dom->createElement("ICMSSN101");4094 $this->dom->addChild(4095 $icmsSN,4096 'orig',4097 $std->orig,4098 true,4099 "[item $std->item] Origem da mercadoria"4100 );4101 $this->dom->addChild(4102 $icmsSN,4103 'CSOSN',4104 $std->CSOSN,4105 true,4106 "[item $std->item] Código de Situação da Operação Simples Nacional"4107 );4108 $this->dom->addChild(4109 $icmsSN,4110 'pCredSN',4111 $this->conditionalNumberFormatting($std->pCredSN, 2),4112 true,4113 "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."4114 );4115 $this->dom->addChild(4116 $icmsSN,4117 'vCredICMSSN',4118 $this->conditionalNumberFormatting($std->vCredICMSSN),4119 true,4120 "[item $std->item] Valor crédito do ICMS que pode ser aproveitado nos termos do"4121 . " art. 23 da LC 123 (Simples Nacional)"4122 );4123 break;4124 case '102':4125 case '103':4126 case '300':4127 case '400':4128 $icmsSN = $this->dom->createElement("ICMSSN102");4129 $this->dom->addChild(4130 $icmsSN,4131 'orig',4132 $std->orig,4133 true,4134 "[item $std->item] Origem da mercadoria"4135 );4136 $this->dom->addChild(4137 $icmsSN,4138 'CSOSN',4139 $std->CSOSN,4140 true,4141 "[item $std->item] Código de Situação da Operação Simples Nacional"4142 );4143 break;4144 case '201':4145 $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;4146 $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;4147 $icmsSN = $this->dom->createElement("ICMSSN201");4148 $this->dom->addChild(4149 $icmsSN,4150 'orig',4151 $std->orig,4152 true,4153 "[item $std->item] Origem da mercadoria"4154 );4155 $this->dom->addChild(4156 $icmsSN,4157 'CSOSN',4158 $std->CSOSN,4159 true,4160 "[item $std->item] Código de Situação da Operação Simples Nacional"4161 );4162 $this->dom->addChild(4163 $icmsSN,4164 'modBCST',4165 $std->modBCST,4166 true,4167 "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."4168 );4169 $this->dom->addChild(4170 $icmsSN,4171 'pMVAST',4172 $this->conditionalNumberFormatting($std->pMVAST, 4),4173 false,4174 "[item $std->item] Percentual da margem de valor Adicionado do ICMS ST"4175 );4176 $this->dom->addChild(4177 $icmsSN,4178 'pRedBCST',4179 $this->conditionalNumberFormatting($std->pRedBCST, 4),4180 false,4181 "[item $std->item] Percentual da Redução de BC do ICMS ST"4182 );4183 $this->dom->addChild(4184 $icmsSN,4185 'vBCST',4186 $this->conditionalNumberFormatting($std->vBCST),4187 true,4188 "[item $std->item] Valor da BC do ICMS ST"4189 );4190 $this->dom->addChild(4191 $icmsSN,4192 'pICMSST',4193 $this->conditionalNumberFormatting($std->pICMSST, 4),4194 true,4195 "[item $std->item] Alíquota do imposto do ICMS ST"4196 );4197 $this->dom->addChild(4198 $icmsSN,4199 'vICMSST',4200 $this->conditionalNumberFormatting($std->vICMSST),4201 true,4202 "[item $std->item] Valor do ICMS ST"4203 );4204 $this->dom->addChild(4205 $icmsSN,4206 'vBCFCPST',4207 $this->conditionalNumberFormatting($std->vBCFCPST),4208 isset($std->vBCFCPST) ? true : false,4209 "[item $std->item] Valor da Base de Cálculo do FCP "4210 . "retido por Substituição Tributária"4211 );4212 $this->dom->addChild(4213 $icmsSN,4214 'pFCPST',4215 $this->conditionalNumberFormatting($std->pFCPST, 4),4216 isset($std->pFCPST) ? true : false,4217 "[item $std->item] Percentual do FCP retido por "4218 . "Substituição Tributária"4219 );4220 $this->dom->addChild(4221 $icmsSN,4222 'vFCPST',4223 $this->conditionalNumberFormatting($std->vFCPST),4224 isset($std->vFCPST) ? true : false,4225 "[item $std->item] Valor do FCP retido por Substituição Tributária"4226 );4227 $this->dom->addChild(4228 $icmsSN,4229 'pCredSN',4230 $this->conditionalNumberFormatting($std->pCredSN, 4),4231 false,4232 "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."4233 );4234 $this->dom->addChild(4235 $icmsSN,4236 'vCredICMSSN',4237 $this->conditionalNumberFormatting($std->vCredICMSSN),4238 false,4239 "[item $std->item] Valor crédito do ICMS que pode ser aproveitado nos "4240 . "termos do art. 23 da LC 123 (Simples Nacional)"4241 );4242 break;4243 case '202':4244 case '203':4245 $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;4246 $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;4247 $icmsSN = $this->dom->createElement("ICMSSN202");4248 $this->dom->addChild(4249 $icmsSN,4250 'orig',4251 $std->orig,4252 true,4253 "[item $std->item] Origem da mercadoria"4254 );4255 $this->dom->addChild(4256 $icmsSN,4257 'CSOSN',4258 $std->CSOSN,4259 true,4260 "[item $std->item] Código de Situação da Operação Simples Nacional"4261 );4262 $this->dom->addChild(4263 $icmsSN,4264 'modBCST',4265 $std->modBCST,4266 true,4267 "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."4268 );4269 $this->dom->addChild(4270 $icmsSN,4271 'pMVAST',4272 $this->conditionalNumberFormatting($std->pMVAST, 4),4273 false,4274 "[item $std->item] Percentual da margem de valor Adicionado do ICMS ST"4275 );4276 $this->dom->addChild(4277 $icmsSN,4278 'pRedBCST',4279 $this->conditionalNumberFormatting($std->pRedBCST, 4),4280 false,4281 "[item $std->item] Percentual da Redução de BC do ICMS ST"4282 );4283 $this->dom->addChild(4284 $icmsSN,4285 'vBCST',4286 $this->conditionalNumberFormatting($std->vBCST),4287 true,4288 "[item $std->item] Valor da BC do ICMS ST"4289 );4290 $this->dom->addChild(4291 $icmsSN,4292 'pICMSST',4293 $this->conditionalNumberFormatting($std->pICMSST, 4),4294 true,4295 "[item $std->item] Alíquota do imposto do ICMS ST"4296 );4297 $this->dom->addChild(4298 $icmsSN,4299 'vICMSST',4300 $this->conditionalNumberFormatting($std->vICMSST),4301 true,4302 "[item $std->item] Valor do ICMS ST"4303 );4304 $this->dom->addChild(4305 $icmsSN,4306 'vBCFCPST',4307 $this->conditionalNumberFormatting($std->vBCFCPST),4308 isset($std->vBCFCPST) ? true : false,4309 "[item $std->item] Valor da Base de Cálculo do FCP "4310 . "retido por Substituição Tributária"4311 );4312 $this->dom->addChild(4313 $icmsSN,4314 'pFCPST',4315 $this->conditionalNumberFormatting($std->pFCPST, 4),4316 isset($std->pFCPST) ? true : false,4317 "[item $std->item] Percentual do FCP retido por "4318 . "Substituição Tributária"4319 );4320 $this->dom->addChild(4321 $icmsSN,4322 'vFCPST',4323 $this->conditionalNumberFormatting($std->vFCPST),4324 isset($std->vFCPST) ? true : false,4325 "[item $std->item] Valor do FCP retido por Substituição Tributária"4326 );4327 break;4328 case '500':4329 $icmsSN = $this->dom->createElement("ICMSSN500");4330 $this->dom->addChild(4331 $icmsSN,4332 'orig',4333 $std->orig,4334 true,4335 "[item $std->item] Origem da mercadoria"4336 );4337 $this->dom->addChild(4338 $icmsSN,4339 'CSOSN',4340 $std->CSOSN,4341 true,4342 "[item $std->item] Código de Situação da Operação Simples Nacional"4343 );4344 $this->dom->addChild(4345 $icmsSN,4346 'vBCSTRet',4347 $this->conditionalNumberFormatting($std->vBCSTRet),4348 isset($std->vBCSTRet) ? true : false,4349 "[item $std->item] Valor da BC do ICMS ST retido"4350 );4351 $this->dom->addChild(4352 $icmsSN,4353 'pST',4354 $this->conditionalNumberFormatting($std->pST, 4),4355 isset($std->pST) ? true : false,4356 "[item $std->item] Alíquota suportada pelo Consumidor Final"4357 );4358 $this->dom->addChild(4359 $icmsSN,4360 'vICMSSubstituto',4361 $this->conditionalNumberFormatting($std->vICMSSubstituto),4362 false,4363 "[item $std->item] Valor do ICMS próprio do Substituto"4364 );4365 $this->dom->addChild(4366 $icmsSN,4367 'vICMSSTRet',4368 $this->conditionalNumberFormatting($std->vICMSSTRet),4369 isset($std->vICMSSTRet) ? true : false,4370 "[item $std->item] Valor do ICMS ST retido"4371 );4372 $this->dom->addChild(4373 $icmsSN,4374 'vBCFCPSTRet',4375 $this->conditionalNumberFormatting($std->vBCFCPSTRet, 2),4376 isset($std->vBCFCPSTRet) ? true : false,4377 "[item $std->item] Valor da Base de Cálculo do FCP "4378 . "retido anteriormente por Substituição Tributária"4379 );4380 $this->dom->addChild(4381 $icmsSN,4382 'pFCPSTRet',4383 $this->conditionalNumberFormatting($std->pFCPSTRet, 4),4384 isset($std->pFCPSTRet) ? true : false,4385 "[item $std->item] Percentual do FCP retido anteriormente por "4386 . "Substituição Tributária"4387 );4388 $this->dom->addChild(4389 $icmsSN,4390 'vFCPSTRet',4391 $this->conditionalNumberFormatting($std->vFCPSTRet),4392 isset($std->vFCPSTRet) ? true : false,4393 "[item $std->item] Valor do FCP retido anteiormente por "4394 . "Substituição Tributária"4395 );4396 $this->dom->addChild(4397 $icmsSN,4398 'pRedBCEfet',4399 $this->conditionalNumberFormatting($std->pRedBCEfet, 4),4400 isset($std->pRedBCEfet) ? true : false,4401 "[item $std->item] Percentual de redução da base "4402 . "de cálculo efetiva"4403 );4404 $this->dom->addChild(4405 $icmsSN,4406 'vBCEfet',4407 $this->conditionalNumberFormatting($std->vBCEfet),4408 isset($std->vBCEfet) ? true : false,4409 "[item $std->item] Valor da base de cálculo efetiva"4410 );4411 $this->dom->addChild(4412 $icmsSN,4413 'pICMSEfet',4414 $this->conditionalNumberFormatting($std->pICMSEfet, 4),4415 isset($std->pICMSEfet) ? true : false,4416 "[item $std->item] Alíquota do ICMS efetiva"4417 );4418 $this->dom->addChild(4419 $icmsSN,4420 'vICMSEfet',4421 $std->vICMSEfet,4422 isset($std->vICMSEfet) ? true : false,4423 "[item $std->item] Valor do ICMS efetivo"4424 );4425 break;4426 case '900':4427 $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;4428 $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;4429 $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;4430 $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;4431 $icmsSN = $this->dom->createElement("ICMSSN900");4432 $this->dom->addChild(4433 $icmsSN,4434 'orig',4435 $std->orig,4436 true,4437 "[item $std->item] Origem da mercadoria"4438 );4439 $this->dom->addChild(4440 $icmsSN,4441 'CSOSN',4442 $std->CSOSN,4443 true,4444 "[item $std->item] Código de Situação da Operação Simples Nacional"4445 );4446 $this->dom->addChild(4447 $icmsSN,4448 'modBC',4449 $std->modBC,4450 isset($std->modBC) ? true : false,4451 "[item $std->item] Modalidade de determinação da BC do ICMS"4452 );4453 $this->dom->addChild(4454 $icmsSN,4455 'vBC',4456 $std->vBC,4457 isset($std->vBC) ? true : false,4458 "[item $std->item] Valor da BC do ICMS"4459 );4460 $this->dom->addChild(4461 $icmsSN,4462 'pRedBC',4463 $this->conditionalNumberFormatting($std->pRedBC, 4),4464 false,4465 "[item $std->item] Percentual da Redução de BC"4466 );4467 $this->dom->addChild(4468 $icmsSN,4469 'pICMS',4470 $this->conditionalNumberFormatting($std->pICMS, 4),4471 isset($std->pICMS) ? true : false,4472 "[item $std->item] Alíquota do imposto"4473 );4474 $this->dom->addChild(4475 $icmsSN,4476 'vICMS',4477 $this->conditionalNumberFormatting($std->vICMS),4478 isset($std->pICMS) ? true : false,4479 "[item $std->item] Valor do ICMS"4480 );4481 $this->dom->addChild(4482 $icmsSN,4483 'modBCST',4484 $std->modBCST,4485 isset($std->modBCST) ? true : false,4486 "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."4487 );4488 $this->dom->addChild(4489 $icmsSN,4490 'pMVAST',4491 $this->conditionalNumberFormatting($std->pMVAST, 4),4492 false,4493 "[item $std->item] Percentual da margem de valor Adicionado do ICMS ST"4494 );4495 $this->dom->addChild(4496 $icmsSN,4497 'pRedBCST',4498 $this->conditionalNumberFormatting($std->pRedBCST, 4),4499 false,4500 "[item $std->item] Percentual da Redução de BC do ICMS ST"4501 );4502 $this->dom->addChild(4503 $icmsSN,4504 'vBCST',4505 $this->conditionalNumberFormatting($std->vBCST),4506 isset($std->vBCST) ? true : false,4507 "[item $std->item] Valor da BC do ICMS ST"4508 );4509 $this->dom->addChild(4510 $icmsSN,4511 'pICMSST',4512 $this->conditionalNumberFormatting($std->pICMSST, 4),4513 isset($std->pICMSST) ? true : false,4514 "[item $std->item] Alíquota do imposto do ICMS ST"4515 );4516 $this->dom->addChild(4517 $icmsSN,4518 'vICMSST',4519 $std->vICMSST,4520 isset($std->vICMSST) ? true : false,4521 "[item $std->item] Valor do ICMS ST"4522 );4523 $this->dom->addChild(4524 $icmsSN,4525 'vBCFCPST',4526 $this->conditionalNumberFormatting($std->vBCFCPST),4527 isset($std->vBCFCPST) ? true : false,4528 "[item $std->item] Valor da Base de Cálculo do FCP "4529 . "retido por Substituição Tributária"4530 );4531 $this->dom->addChild(4532 $icmsSN,4533 'pFCPST',4534 $this->conditionalNumberFormatting($std->pFCPST, 4),4535 isset($std->pFCPST) ? true : false,4536 "[item $std->item] Percentual do FCP retido por "4537 . "Substituição Tributária"4538 );4539 $this->dom->addChild(4540 $icmsSN,4541 'vFCPST',4542 $this->conditionalNumberFormatting($std->vFCPST),4543 isset($std->vFCPST) ? true : false,4544 "[item $std->item] Valor do FCP retido por Substituição Tributária"4545 );4546 $this->dom->addChild(4547 $icmsSN,4548 'pCredSN',4549 $this->conditionalNumberFormatting($std->pCredSN, 4),4550 isset($std->pCredSN) ? true : false,4551 "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."4552 );4553 $this->dom->addChild(4554 $icmsSN,4555 'vCredICMSSN',4556 $this->conditionalNumberFormatting($std->vCredICMSSN),4557 isset($std->vCredICMSSN) ? true : false,4558 "[item $std->item] Valor crédito do ICMS que pode ser aproveitado nos termos do"4559 . " art. 23 da LC 123 (Simples Nacional)"4560 );4561 break;4562 }4563 //caso exista a tag aICMS[$std-item] inserir nela caso contrario criar4564 if (!empty($this->aICMS[$std->item])) {4565 $tagIcms = $this->aICMS[$std->item];4566 } else {4567 $tagIcms = $this->dom->createElement('ICMS');4568 }4569 if (isset($icmsSN)) {4570 $this->dom->appChild($tagIcms, $icmsSN, "Inserindo ICMSST em ICMS[$std->item]");4571 }4572 $this->aICMS[$std->item] = $tagIcms;4573 return $tagIcms;4574 }4575 /**4576 * Grupo ICMSUFDest NA01 pai M014577 * tag NFe/infNFe/det[]/imposto/ICMSUFDest (opcional)4578 * Grupo a ser informado nas vendas interestaduais para consumidor final,4579 * não contribuinte do ICMS4580 * @param stdClass $std4581 * @return DOMElement4582 */4583 public function tagICMSUFDest(stdClass $std)4584 {4585 $possible = [4586 'item',4587 'vBCUFDest',4588 'vBCFCPUFDest',4589 'pFCPUFDest',4590 'pICMSUFDest',4591 'pICMSInter',4592 'pICMSInterPart',4593 'vFCPUFDest',4594 'vICMSUFDest',4595 'vICMSUFRemet'4596 ];4597 $std = $this->equilizeParameters($std, $possible);4598 $this->stdTot->vICMSUFDest += (float) $std->vICMSUFDest;4599 $this->stdTot->vFCPUFDest += (float) $std->vFCPUFDest;4600 $this->stdTot->vICMSUFRemet += (float) $std->vICMSUFRemet;4601 $icmsUFDest = $this->dom->createElement('ICMSUFDest');4602 $this->dom->addChild(4603 $icmsUFDest,4604 "vBCUFDest",4605 $std->vBCUFDest,4606 true,4607 "[item $std->item] Valor da BC do ICMS na UF do destinatário"4608 );4609 $this->dom->addChild(4610 $icmsUFDest,4611 "vBCFCPUFDest",4612 $std->vBCFCPUFDest,4613 false,4614 "[item $std->item] Valor da BC do ICMS na UF do destinatário"4615 );4616 $this->dom->addChild(4617 $icmsUFDest,4618 "pFCPUFDest",4619 $this->conditionalNumberFormatting($std->pFCPUFDest, 4),4620 false,4621 "[item $std->item] Percentual do ICMS relativo ao Fundo de Combate à Pobreza (FCP) na UF de destino"4622 );4623 $this->dom->addChild(4624 $icmsUFDest,4625 "pICMSUFDest",4626 $this->conditionalNumberFormatting($std->pICMSUFDest, 4),4627 true,4628 "[item $std->item] Alíquota interna da UF do destinatário"4629 );4630 $this->dom->addChild(4631 $icmsUFDest,4632 "pICMSInter",4633 $this->conditionalNumberFormatting($std->pICMSInter, 2),4634 true,4635 "[item $std->item] Alíquota interestadual das UF envolvidas"4636 );4637 $this->dom->addChild(4638 $icmsUFDest,4639 "pICMSInterPart",4640 $this->conditionalNumberFormatting($std->pICMSInterPart, 4),4641 true,4642 "[item $std->item] Percentual provisório de partilha entre os Estados"4643 );4644 $this->dom->addChild(4645 $icmsUFDest,4646 "vFCPUFDest",4647 $std->vFCPUFDest,4648 false,4649 "[item $std->item] Valor do ICMS relativo ao Fundo de Combate à Pobreza (FCP) da UF de destino"4650 );4651 $this->dom->addChild(4652 $icmsUFDest,4653 "vICMSUFDest",4654 $std->vICMSUFDest,4655 true,4656 "[item $std->item] Valor do ICMS de partilha para a UF do destinatário"4657 );4658 $this->dom->addChild(4659 $icmsUFDest,4660 "vICMSUFRemet",4661 $std->vICMSUFRemet,4662 true,4663 "[item $std->item] Valor do ICMS de partilha para a UF do remetente"4664 );4665 $this->aICMSUFDest[$std->item] = $icmsUFDest;4666 return $icmsUFDest;4667 }4668 /**4669 * Grupo IPI O01 pai M014670 * tag NFe/infNFe/det[]/imposto/IPI (opcional)4671 * @param stdClass $std4672 * @return DOMElement4673 */4674 public function tagIPI(stdClass $std)4675 {4676 $possible = [4677 'item',4678 'clEnq',4679 'CNPJProd',4680 'cSelo',4681 'qSelo',4682 'cEnq',4683 'CST',4684 'vIPI',4685 'vBC',4686 'pIPI',4687 'qUnid',4688 'vUnid'4689 ];4690 $std = $this->equilizeParameters($std, $possible);4691 $ipi = $this->dom->createElement('IPI');4692 $this->dom->addChild(4693 $ipi,4694 "clEnq",4695 $std->clEnq,4696 false,4697 "[item $std->item] Classe de enquadramento do IPI para Cigarros e Bebidas"4698 );4699 $this->dom->addChild(4700 $ipi,4701 "CNPJProd",4702 $std->CNPJProd,4703 false,4704 "[item $std->item] CNPJ do produtor da mercadoria, quando diferente do emitente. "4705 . "Somente para os casos de exportação direta ou indireta."4706 );4707 $this->dom->addChild(4708 $ipi,4709 "cSelo",4710 $std->cSelo,4711 false,4712 "[item $std->item] Código do selo de controle IPI"4713 );4714 $this->dom->addChild(4715 $ipi,4716 "qSelo",4717 $std->qSelo,4718 false,4719 "[item $std->item] Quantidade de selo de controle"4720 );4721 $this->dom->addChild(4722 $ipi,4723 "cEnq",4724 $std->cEnq,4725 true,4726 "[item $std->item] Código de Enquadramento Legal do IPI"4727 );4728 if ($std->CST == '00' || $std->CST == '49' || $std->CST == '50' || $std->CST == '99') {4729 //totalizador4730 $this->stdTot->vIPI += (float) $std->vIPI;4731 $ipiTrib = $this->dom->createElement('IPITrib');4732 $this->dom->addChild(4733 $ipiTrib,4734 "CST",4735 $std->CST,4736 true,4737 "[item $std->item] Código da situação tributária do IPI"4738 );4739 $this->dom->addChild(4740 $ipiTrib,4741 "vBC",4742 $this->conditionalNumberFormatting($std->vBC),4743 false,4744 "[item $std->item] Valor da BC do IPI"4745 );4746 $this->dom->addChild(4747 $ipiTrib,4748 "pIPI",4749 $this->conditionalNumberFormatting($std->pIPI, 4),4750 false,4751 "[item $std->item] Alíquota do IPI"4752 );4753 $this->dom->addChild(4754 $ipiTrib,4755 "qUnid",4756 $std->qUnid,4757 false,4758 "[item $std->item] Quantidade total na unidade padrão para tributação (somente para os "4759 . "produtos tributados por unidade)"4760 );4761 $this->dom->addChild(4762 $ipiTrib,4763 "vUnid",4764 $std->vUnid,4765 false,4766 "[item $std->item] Valor por Unidade Tributável"4767 );4768 $this->dom->addChild(4769 $ipiTrib,4770 "vIPI",4771 $this->conditionalNumberFormatting($std->vIPI),4772 true,4773 "[item $std->item] Valor do IPI"4774 );4775 $ipi->appendChild($ipiTrib);4776 } else {4777 $ipINT = $this->dom->createElement('IPINT');4778 $this->dom->addChild(4779 $ipINT,4780 "CST",4781 $std->CST,4782 true,4783 "[item $std->item] Código da situação tributária do IPINT"4784 );4785 $ipi->appendChild($ipINT);4786 }4787 $this->aIPI[$std->item] = $ipi;4788 return $ipi;4789 }4790 /**4791 * Grupo Imposto de Importação P01 pai M014792 * tag NFe/infNFe/det[]/imposto/II4793 * @param stdClass $std4794 * @return DOMElement4795 */4796 public function tagII(stdClass $std)4797 {4798 $possible = [4799 'item',4800 'vBC',4801 'vDespAdu',4802 'vII',4803 'vIOF'4804 ];4805 $std = $this->equilizeParameters($std, $possible);4806 //totalizador4807 $this->stdTot->vII += (float) $std->vII;4808 $tii = $this->dom->createElement('II');4809 $this->dom->addChild(4810 $tii,4811 "vBC",4812 $this->conditionalNumberFormatting($std->vBC),4813 true,4814 "[item $std->item] Valor BC do Imposto de Importação"4815 );4816 $this->dom->addChild(4817 $tii,4818 "vDespAdu",4819 $this->conditionalNumberFormatting($std->vDespAdu),4820 true,4821 "[item $std->item] Valor despesas aduaneiras"4822 );4823 $this->dom->addChild(4824 $tii,4825 "vII",4826 $this->conditionalNumberFormatting($std->vII),4827 true,4828 "[item $std->item] Valor Imposto de Importação"4829 );4830 $this->dom->addChild(4831 $tii,4832 "vIOF",4833 $this->conditionalNumberFormatting($std->vIOF),4834 true,4835 "[item $std->item] Valor Imposto sobre Operações Financeiras"4836 );4837 $this->aII[$std->item] = $tii;4838 return $tii;4839 }4840 /**4841 * Grupo PIS Q01 pai M014842 * tag NFe/infNFe/det[]/imposto/PIS4843 * @param stdClass $std4844 * @return DOMElement4845 */4846 public function tagPIS(stdClass $std)4847 {4848 $possible = [4849 'item',4850 'CST',4851 'vBC',4852 'pPIS',4853 'vPIS',4854 'qBCProd',4855 'vAliqProd'4856 ];4857 $std = $this->equilizeParameters($std, $possible);4858 4859 switch ($std->CST) {4860 case '01':4861 case '02':4862 $pisItem = $this->dom->createElement('PISAliq');4863 $this->dom->addChild(4864 $pisItem,4865 'CST',4866 $std->CST,4867 true,4868 "[item $std->item] Código de Situação Tributária do PIS"4869 );4870 $this->dom->addChild(4871 $pisItem,4872 'vBC',4873 $this->conditionalNumberFormatting($std->vBC),4874 true,4875 "[item $std->item] Valor da Base de Cálculo do PIS"4876 );4877 $this->dom->addChild(4878 $pisItem,4879 'pPIS',4880 $this->conditionalNumberFormatting($std->pPIS, 4),4881 true,4882 "[item $std->item] Alíquota do PIS (em percentual)"4883 );4884 $this->dom->addChild(4885 $pisItem,4886 'vPIS',4887 $this->conditionalNumberFormatting($std->vPIS),4888 true,4889 "[item $std->item] Valor do PIS"4890 );4891 //totalizador4892 $this->stdTot->vPIS += (float) !empty($std->vPIS) ? $std->vPIS : 0;4893 break;4894 case '03':4895 $pisItem = $this->dom->createElement('PISQtde');4896 $this->dom->addChild(4897 $pisItem,4898 'CST',4899 $std->CST,4900 true,4901 "[item $std->item] Código de Situação Tributária do PIS"4902 );4903 $this->dom->addChild(4904 $pisItem,4905 'qBCProd',4906 $std->qBCProd,4907 true,4908 "[item $std->item] Quantidade Vendida"4909 );4910 $this->dom->addChild(4911 $pisItem,4912 'vAliqProd',4913 $std->vAliqProd,4914 true,4915 "[item $std->item] Alíquota do PIS (em reais)"4916 );4917 $this->dom->addChild(4918 $pisItem,4919 'vPIS',4920 $this->conditionalNumberFormatting($std->vPIS),4921 true,4922 "[item $std->item] Valor do PIS"4923 );4924 //totalizador4925 $this->stdTot->vPIS += (float) !empty($std->vPIS) ? $std->vPIS : 0;4926 break;4927 case '04':4928 case '05':4929 case '06':4930 case '07':4931 case '08':4932 case '09':4933 $pisItem = $this->dom->createElement('PISNT');4934 $this->dom->addChild(4935 $pisItem,4936 'CST',4937 $std->CST,4938 true,4939 "[item $std->item] Código de Situação Tributária do PIS"4940 );4941 break;4942 case '49':4943 case '50':4944 case '51':4945 case '52':4946 case '53':4947 case '54':4948 case '55':4949 case '56':4950 case '60':4951 case '61':4952 case '62':4953 case '63':4954 case '64':4955 case '65':4956 case '66':4957 case '67':4958 case '70':4959 case '71':4960 case '72':4961 case '73':4962 case '74':4963 case '75':4964 case '98':4965 case '99':4966 $pisItem = $this->dom->createElement('PISOutr');4967 $this->dom->addChild(4968 $pisItem,4969 'CST',4970 $std->CST,4971 true,4972 "[item $std->item] Código de Situação Tributária do PIS"4973 );4974 $this->dom->addChild(4975 $pisItem,4976 'vBC',4977 $this->conditionalNumberFormatting($std->vBC),4978 ($std->vBC !== null) ? true : false,4979 "[item $std->item] Valor da Base de Cálculo do PIS"4980 );4981 $this->dom->addChild(4982 $pisItem,4983 'pPIS',4984 $this->conditionalNumberFormatting($std->pPIS, 4),4985 ($std->pPIS !== null) ? true : false,4986 "[item $std->item] Alíquota do PIS (em percentual)"4987 );4988 $this->dom->addChild(4989 $pisItem,4990 'qBCProd',4991 $std->qBCProd,4992 ($std->qBCProd !== null) ? true : false,4993 "[item $std->item] Quantidade Vendida"4994 );4995 $this->dom->addChild(4996 $pisItem,4997 'vAliqProd',4998 $std->vAliqProd,4999 ($std->vAliqProd !== null) ? true : false,5000 "[item $std->item] Alíquota do PIS (em reais)"5001 );5002 $this->dom->addChild(5003 $pisItem,5004 'vPIS',5005 $this->conditionalNumberFormatting($std->vPIS),5006 true,5007 "[item $std->item] Valor do PIS"5008 );5009 //totalizador5010 $this->stdTot->vPIS += (float) !empty($std->vPIS) ? $std->vPIS : 0;5011 break;5012 }5013 $pis = $this->dom->createElement('PIS');5014 if (isset($pisItem)) {5015 $pis->appendChild($pisItem);5016 }5017 $this->aPIS[$std->item] = $pis;5018 return $pis;5019 }5020 /**5021 * Grupo PIS Substituição Tributária R01 pai M015022 * tag NFe/infNFe/det[]/imposto/PISST (opcional)5023 * @param stdClass $std5024 * @return DOMElement5025 */5026 public function tagPISST(stdClass $std)5027 {5028 $possible = [5029 'item',5030 'vPIS',5031 'vBC',5032 'pPIS',5033 'qBCProd',5034 'vAliqProd'5035 ];5036 $std = $this->equilizeParameters($std, $possible);5037 $pisst = $this->dom->createElement('PISST');5038 if (!isset($std->qBCProd)) {5039 $this->dom->addChild(5040 $pisst,5041 'vBC',5042 $this->conditionalNumberFormatting($std->vBC),5043 true,5044 "[item $std->item] Valor da Base de Cálculo do PIS"5045 );5046 $this->dom->addChild(5047 $pisst,5048 'pPIS',5049 $this->conditionalNumberFormatting($std->pPIS, 4),5050 true,5051 "[item $std->item] Alíquota do PIS (em percentual)"5052 );5053 } else {5054 $this->dom->addChild(5055 $pisst,5056 'qBCProd',5057 $std->qBCProd,5058 true,5059 "[item $std->item] Quantidade Vendida"5060 );5061 $this->dom->addChild(5062 $pisst,5063 'vAliqProd',5064 $std->vAliqProd,5065 true,5066 "[item $std->item] Alíquota do PIS (em reais)"5067 );5068 }5069 $this->dom->addChild(5070 $pisst,5071 'vPIS',5072 $this->conditionalNumberFormatting($std->vPIS),5073 true,5074 "[item $std->item] Valor do PIS"5075 );5076 $this->aPISST[$std->item] = $pisst;5077 return $pisst;5078 }5079 /**5080 * Grupo COFINS S01 pai M015081 * tag det[item]/imposto/COFINS (opcional)5082 * @param stdClass $std5083 * @return DOMElement5084 */5085 public function tagCOFINS(stdClass $std)5086 {5087 $possible = [5088 'item',5089 'CST',5090 'vBC',5091 'pCOFINS',5092 'vCOFINS',5093 'qBCProd',5094 'vAliqProd'5095 ];5096 $std = $this->equilizeParameters($std, $possible);5097 switch ($std->CST) {5098 case '01':5099 case '02':5100 $confinsItem = $this->buildCOFINSAliq($std);5101 //totalizador5102 $this->stdTot->vCOFINS += (float) $std->vCOFINS;5103 break;5104 case '03':5105 $confinsItem = $this->dom->createElement('COFINSQtde');5106 $this->dom->addChild(5107 $confinsItem,5108 'CST',5109 $std->CST,5110 true,5111 "[item $std->item] Código de Situação Tributária da COFINS"5112 );5113 $this->dom->addChild(5114 $confinsItem,5115 'qBCProd',5116 $std->qBCProd,5117 true,5118 "[item $std->item] Quantidade Vendida"5119 );5120 $this->dom->addChild(5121 $confinsItem,5122 'vAliqProd',5123 $std->vAliqProd,5124 true,5125 "[item $std->item] Alíquota do COFINS (em reais)"5126 );5127 $this->dom->addChild(5128 $confinsItem,5129 'vCOFINS',5130 $this->conditionalNumberFormatting($std->vCOFINS),5131 true,5132 "[item $std->item] Valor do COFINS"5133 );5134 //totalizador5135 $this->stdTot->vCOFINS += (float) $std->vCOFINS;5136 break;5137 case '04':5138 case '05':5139 case '06':5140 case '07':5141 case '08':5142 case '09':5143 $confinsItem = $this->buildCOFINSNT($std);5144 break;5145 case '49':5146 case '50':5147 case '51':5148 case '52':5149 case '53':5150 case '54':5151 case '55':5152 case '56':5153 case '60':5154 case '61':5155 case '62':5156 case '63':5157 case '64':5158 case '65':5159 case '66':5160 case '67':5161 case '70':5162 case '71':5163 case '72':5164 case '73':5165 case '74':5166 case '75':5167 case '98':5168 case '99':5169 $confinsItem = $this->buildCOFINSoutr($std);5170 //totalizador5171 $this->stdTot->vCOFINS += (float) $std->vCOFINS;5172 break;5173 }5174 $confins = $this->dom->createElement('COFINS');5175 if (isset($confinsItem)) {5176 $confins->appendChild($confinsItem);5177 }5178 $this->aCOFINS[$std->item] = $confins;5179 return $confins;5180 }5181 /**5182 * Grupo COFINS Substituição Tributária T01 pai M015183 * tag NFe/infNFe/det[]/imposto/COFINSST (opcional)5184 * @param stdClass $std5185 * @return DOMElement5186 */5187 public function tagCOFINSST(stdClass $std)5188 {5189 $possible = [5190 'item',5191 'vCOFINS',5192 'vBC',5193 'pCOFINS',5194 'qBCProd',5195 'vAliqProd'5196 ];5197 $std = $this->equilizeParameters($std, $possible);5198 $cofinsst = $this->dom->createElement("COFINSST");5199 if (!isset($std->qBCProd)) {5200 $this->dom->addChild(5201 $cofinsst,5202 "vBC",5203 $this->conditionalNumberFormatting($std->vBC),5204 true,5205 "[item $std->item] Valor da Base de Cálculo da COFINS"5206 );5207 $this->dom->addChild(5208 $cofinsst,5209 "pCOFINS",5210 $this->conditionalNumberFormatting($std->pCOFINS, 4),5211 true,5212 "[item $std->item] Alíquota da COFINS (em percentual)"5213 );5214 } else {5215 $this->dom->addChild(5216 $cofinsst,5217 "qBCProd",5218 $std->qBCProd,5219 true,5220 "[item $std->item] Quantidade Vendida"5221 );5222 $this->dom->addChild(5223 $cofinsst,5224 "vAliqProd",5225 $std->vAliqProd,5226 true,5227 "[item $std->item] Alíquota da COFINS (em reais)"5228 );5229 }5230 $this->dom->addChild(5231 $cofinsst,5232 "vCOFINS",5233 $this->conditionalNumberFormatting($std->vCOFINS),5234 true,5235 "[item $std->item] Valor da COFINS"5236 );5237 $this->aCOFINSST[$std->item] = $cofinsst;5238 return $cofinsst;5239 }5240 /**5241 * Grupo ISSQN U01 pai M015242 * tag NFe/infNFe/det[]/imposto/ISSQN (opcional)5243 * @param stdClass $std5244 * @return DOMElement5245 */5246 public function tagISSQN(stdClass $std)5247 {5248 $possible = [5249 'item',5250 'vBC',5251 'vAliq',5252 'vISSQN',5253 'cMunFG',5254 'cListServ',5255 'vDeducao',5256 'vOutro',5257 'vDescIncond',5258 'vDescCond',5259 'vISSRet',5260 'indISS',5261 'cServico',5262 'cMun',5263 'cPais',5264 'nProcesso',5265 'indIncentivo'5266 ];5267 $std = $this->equilizeParameters($std, $possible);5268 $issqn = $this->dom->createElement("ISSQN");5269 $this->dom->addChild(5270 $issqn,5271 "vBC",5272 $this->conditionalNumberFormatting($std->vBC),5273 true,5274 "[item $std->item] Valor da Base de Cálculo do ISSQN"5275 );5276 $this->dom->addChild(5277 $issqn,5278 "vAliq",5279 $this->conditionalNumberFormatting($std->vAliq, 4),5280 true,5281 "[item $std->item] Alíquota do ISSQN"5282 );5283 $this->dom->addChild(5284 $issqn,5285 "vISSQN",5286 $this->conditionalNumberFormatting($std->vISSQN),5287 true,5288 "[item $std->item] Valor do ISSQN"5289 );5290 $this->dom->addChild(5291 $issqn,5292 "cMunFG",5293 $std->cMunFG,5294 true,5295 "[item $std->item] Código do município de ocorrência do fato gerador do ISSQN"5296 );5297 $this->dom->addChild(5298 $issqn,5299 "cListServ",5300 $std->cListServ,5301 true,5302 "[item $std->item] Item da Lista de Serviços"5303 );5304 $this->dom->addChild(5305 $issqn,5306 "vDeducao",5307 $this->conditionalNumberFormatting($std->vDeducao),5308 false,5309 "[item $std->item] Valor dedução para redução da Base de Cálculo"5310 );5311 $this->dom->addChild(5312 $issqn,5313 "vOutro",5314 $this->conditionalNumberFormatting($std->vOutro),5315 false,5316 "[item $std->item] Valor outras retenções"5317 );5318 $this->dom->addChild(5319 $issqn,5320 "vDescIncond",5321 $this->conditionalNumberFormatting($std->vDescIncond),5322 false,5323 "[item $std->item] Valor desconto incondicionado"5324 );5325 $this->dom->addChild(5326 $issqn,5327 "vDescCond",5328 $this->conditionalNumberFormatting($std->vDescCond),5329 false,5330 "[item $std->item] Valor desconto condicionado"5331 );5332 $this->dom->addChild(5333 $issqn,5334 "vISSRet",5335 $this->conditionalNumberFormatting($std->vISSRet),5336 false,5337 "[item $std->item] Valor retenção ISS"5338 );5339 $this->dom->addChild(5340 $issqn,5341 "indISS",5342 $std->indISS,5343 true,5344 "[item $std->item] Indicador da exigibilidade do ISS"5345 );5346 $this->dom->addChild(5347 $issqn,5348 "cServico",5349 $std->cServico,5350 false,5351 "[item $std->item] Código do serviço prestado dentro do município"5352 );5353 $this->dom->addChild(5354 $issqn,5355 "cMun",5356 $std->cMun,5357 false,5358 "[item $std->item] Código do Município de incidência do imposto"5359 );5360 $this->dom->addChild(5361 $issqn,5362 "cPais",5363 $std->cPais,5364 false,5365 "[item $std->item] Código do País onde o serviço foi prestado"5366 );5367 $this->dom->addChild(5368 $issqn,5369 "nProcesso",5370 $std->nProcesso,5371 false,5372 "[item $std->item] Número do processo judicial ou administrativo de suspensão da exigibilidade"5373 );5374 $this->dom->addChild(5375 $issqn,5376 "indIncentivo",5377 $std->indIncentivo,5378 true,5379 "[item $std->item] Indicador de incentivo Fiscal"5380 );5381 $this->aISSQN[$std->item] = $issqn;5382 return $issqn;5383 }5384 /**5385 * Informação do Imposto devolvido U50 pai H015386 * tag NFe/infNFe/det[]/impostoDevol (opcional)5387 * @param stdClass $std5388 * @return DOMElement5389 */5390 public function tagimpostoDevol(stdClass $std)5391 {5392 $possible = [5393 'item',5394 'pDevol',5395 'vIPIDevol'5396 ];5397 $std = $this->equilizeParameters($std, $possible);5398 //totalizador5399 $this->stdTot->vIPIDevol += (float) $std->vIPIDevol;5400 $impostoDevol = $this->dom->createElement("impostoDevol");5401 $this->dom->addChild(5402 $impostoDevol,5403 "pDevol",5404 $this->conditionalNumberFormatting($std->pDevol, 2),5405 true,5406 "[item $std->item] Percentual da mercadoria devolvida"5407 );5408 $parent = $this->dom->createElement("IPI");5409 $this->dom->addChild(5410 $parent,5411 "vIPIDevol",5412 $this->conditionalNumberFormatting($std->vIPIDevol),5413 true,5414 "[item $std->item] Valor do IPI devolvido"5415 );5416 $impostoDevol->appendChild($parent);5417 $this->aImpostoDevol[$std->item] = $impostoDevol;5418 return $impostoDevol;5419 }5420 /**5421 * Grupo Totais referentes ao ICMS W02 pai W015422 * tag NFe/infNFe/total/ICMSTot5423 * @param stdClass $std5424 * @return DOMElement5425 */5426 public function tagICMSTot(stdClass $std)5427 {5428 $this->buildTotal();5429 $vBC = isset($std->vBC) ? $std->vBC : $this->stdTot->vBC;5430 $vICMS = isset($std->vICMS) ? $std->vICMS : $this->stdTot->vICMS;5431 $vICMSDeson = !empty($std->vICMSDeson) ? $std->vICMSDeson : $this->stdTot->vICMSDeson;5432 $vBCST = !empty($std->vBCST) ? $std->vBCST : $this->stdTot->vBCST;5433 $vST = !empty($std->vST) ? $std->vST : $this->stdTot->vST;5434 $vProd = !empty($std->vProd) ? $std->vProd : $this->stdTot->vProd;5435 $vFrete = !empty($std->vFrete) ? $std->vFrete : $this->stdTot->vFrete;5436 $vSeg = !empty($std->vSeg) ? $std->vSeg : $this->stdTot->vSeg;5437 $vDesc = !empty($std->vDesc) ? $std->vDesc : $this->stdTot->vDesc;5438 $vII = !empty($std->vII) ? $std->vII : $this->stdTot->vII;5439 $vIPI = !empty($std->vIPI) ? $std->vIPI : $this->stdTot->vIPI;5440 $vPIS = !empty($std->vPIS) ? $std->vPIS : $this->stdTot->vPIS;5441 $vCOFINS = !empty($std->vCOFINS) ? $std->vCOFINS : $this->stdTot->vCOFINS;5442 $vOutro = !empty($std->vOutro) ? $std->vOutro : $this->stdTot->vOutro;5443 $vNF = !empty($std->vNF) ? $std->vNF : $this->stdTot->vNF;5444 $vIPIDevol = !empty($std->vIPIDevol) ? $std->vIPIDevol : $this->stdTot->vIPIDevol;5445 $vTotTrib = !empty($std->vTotTrib) ? $std->vTotTrib : $this->stdTot->vTotTrib;5446 $vFCP = !empty($std->vFCP) ? $std->vFCP : $this->stdTot->vFCP;5447 $vFCPST = !empty($std->vFCPST) ? $std->vFCPST : $this->stdTot->vFCPST;5448 $vFCPSTRet = !empty($std->vFCPSTRet) ? $std->vFCPSTRet : $this->stdTot->vFCPSTRet;5449 $vFCPUFDest = !empty($std->vFCPUFDest) ? $std->vFCPUFDest : $this->stdTot->vFCPUFDest;5450 $vICMSUFDest = !empty($std->vICMSUFDest) ? $std->vICMSUFDest : $this->stdTot->vICMSUFDest;5451 $vICMSUFRemet = !empty($std->vICMSUFRemet) ? $std->vICMSUFRemet : $this->stdTot->vICMSUFRemet;5452 //campos opcionais incluir se maior que zero5453 $vFCPUFDest = ($vFCPUFDest > 0) ? number_format($vFCPUFDest, 2, '.', '') : null;5454 $vICMSUFDest = ($vICMSUFDest > 0) ? number_format($vICMSUFDest, 2, '.', '') : null;5455 $vICMSUFRemet = ($vICMSUFRemet > 0) ? number_format($vICMSUFRemet, 2, '.', '') : null;5456 $vTotTrib = ($vTotTrib > 0) ? number_format($vTotTrib, 2, '.', '') : null;5457 //campos obrigatórios para 4.005458 $vFCP = number_format($vFCP, 2, '.', '');5459 $vFCPST = number_format($vFCPST, 2, '.', '');5460 $vFCPSTRet = number_format($vFCPSTRet, 2, '.', '');5461 $vIPIDevol = number_format($vIPIDevol, 2, '.', '');5462 $ICMSTot = $this->dom->createElement("ICMSTot");5463 $this->dom->addChild(5464 $ICMSTot,5465 "vBC",5466 number_format($vBC, 2, '.', ''),5467 true,5468 "Base de Cálculo do ICMS"5469 );5470 $this->dom->addChild(5471 $ICMSTot,5472 "vICMS",5473 number_format($vICMS, 2, '.', ''),5474 true,5475 "Valor Total do ICMS"5476 );5477 $this->dom->addChild(5478 $ICMSTot,5479 "vICMSDeson",5480 number_format($vICMSDeson, 2, '.', ''),5481 true,5482 "Valor Total do ICMS desonerado"5483 );5484 $this->dom->addChild(5485 $ICMSTot,5486 "vFCPUFDest",5487 $vFCPUFDest,5488 false,5489 "Valor total do ICMS relativo ao Fundo de Combate à Pobreza(FCP) "5490 . "para a UF de destino"5491 );5492 $this->dom->addChild(5493 $ICMSTot,5494 "vICMSUFDest",5495 $vICMSUFDest,5496 false,5497 "Valor total do ICMS de partilha para a UF do destinatário"5498 );5499 $this->dom->addChild(5500 $ICMSTot,5501 "vICMSUFRemet",5502 $vICMSUFRemet,5503 false,5504 "Valor total do ICMS de partilha para a UF do remetente"5505 );5506 //incluso no layout 4.005507 $this->dom->addChild(5508 $ICMSTot,5509 "vFCP",5510 $vFCP,5511 false,5512 "Valor total do ICMS relativo ao Fundo de Combate à Pobreza(FCP) "5513 . "para a UF de destino"5514 );5515 $this->dom->addChild(5516 $ICMSTot,5517 "vBCST",5518 number_format($vBCST, 2, '.', ''),5519 true,5520 "Base de Cálculo do ICMS ST"5521 );5522 $this->dom->addChild(5523 $ICMSTot,5524 "vST",5525 number_format($vST, 2, '.', ''),5526 true,5527 "Valor Total do ICMS ST"5528 );5529 //incluso na 4.005530 $this->dom->addChild(5531 $ICMSTot,5532 "vFCPST",5533 $vFCPST,5534 false, //true para 4.005535 "Valor Total do FCP (Fundo de Combate à Pobreza) "5536 . "retido por substituição tributária"5537 );5538 //incluso na 4.005539 $this->dom->addChild(5540 $ICMSTot,5541 "vFCPSTRet",5542 $vFCPSTRet,5543 false, //true para 4.005544 "Valor Total do FCP retido anteriormente por "5545 . "Substituição Tributária"5546 );5547 $this->dom->addChild(5548 $ICMSTot,5549 "vProd",5550 number_format($vProd, 2, '.', ''),5551 true,5552 "Valor Total dos produtos e serviços"5553 );5554 $this->dom->addChild(5555 $ICMSTot,5556 "vFrete",5557 number_format($vFrete, 2, '.', ''),5558 true,5559