AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.216.59
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/www/lrsys_apps/regional/application/plugins/modulo_fiscal/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_apps/regional/application/plugins/modulo_fiscal/controllers/criaDataXML.php
<?php
	
	class criaDataXML {

		public $nota = "",
			   $xml = "",
			   $id = 0;

		public $product_inseted = array();

		public $xml_nome = "",
			   $xml_tipo = "",
			   $xml_temp = "",
			   $xml_erro = "",
			   $xml_tam = "",
			   $xml_id = "",
			   $xml_versao = "";

		//nota (infos + Assinatura + Protocolo)
		public $infoinfCpl = "",
			   $assDigestValue = "",
			   $assSignatureValue = "",
			   $assX509Certificate = "",
			   $prottpAmb = "",
			   $protverAplic = "",
			   $protchNFe = "",
		 	   $protdhRecbto = "",
			   $protnProt = "",
			   $protdigVal = "",
			   $protcStat = "",
			   $protxMotivo = "";

		//ide	   
		public $cUF = "",
			   $cNF = "",
			   $natOp = "",
			   $indPag = "",
			   $mod = "",
			   $serie = "",
			   $nNF = "",
			   $dhEmi = "",
			   $dhSaiEnt = "",
		 	   $tpNF = "",
		 	   $idDest = "",
			   $cMunFG = "",
			   $tpImp = "",
			   $tpEmis = "",
			   $cDV = "",
			   $tpAmb = "",
			   $finNFe = "",
			   $indFinal = "",
			   $indPres = "",
			   $procEmi = "",
			   $verProc = "";

		//emit
		public $emitCNPJ = "",
			   $emitxNome = "",
			   $emitxFant = "",
			   $emitIE = "",
			   $emitIM = "",
			   $emitCNAE = "",
			   $emitCRT = "",
			   $emitxLgr = "",
			   $emitnro = "",
			   $emitxBairro = "",
			   $emitcMun = "",
			   $emitxMun = "",
			   $emitUF = "",
			   $emitCEP = "",
			   $emitcPais = "",
			   $emitxPais = "",
			   $emitfone = "";

		//dest
		public $destCNPJ = "",
			   $destxNome = "",
			   $destIE = "",
			   $destemail = "",
			   $destxLgr = "",
			   $destnro = "",
			   $destxCpl = "",
			   $destxBairro = "",
			   $destcMun = "",
			   $destxMun = "",
			   $destUF = "",
			   $destCEP = "",
			   $destcPais = "",
			   $destxPais = "",
			   $destfone = "";

		//total
		public $totalvBC = "",
			   $totalvICMS = "",
			   $totalvBCST = "",
			   $totalvST = "",
			   $totalvProd = "",
			   $totalvFrete = "",
			   $totalvSeg = "",
			   $totalvDesc = "",
			   $totalvII = "",
			   $totalvIPI = "",
			   $totalvPIS = "",
			   $totalvCOFINS = "",
			   $totalvOutro = "",
			   $totalvNF = "";

		//transp
		// public $transpmodFrete = "",
		// 	   $transpCNPJ = "",
		// 	   $transpxNome = "",
		// 	   $transpIE = "",
		// 	   $transpxEnder = "",
		// 	   $transpxMun = "",
		// 	   $transpUF = "",
		// 	   $transpqVol = "",
		// 	   $transpesp = "",
		// 	   $transppesoL = "",
		// 	   $transppesoB = "";

		//cobr
		// public $cobrnFat = "",
		// 	   $cobrvOrig = "",
		// 	   $cobrvLiq = "",
		// 	   $cobrnDup = "",
		// 	   $cobrdVenc = "",
		// 	   $cobrvDup = "";

		public function __construct($xml = ''){
			$this->nota = $xml;
		}

		public function insDadosXML(){
			$this->xml_nome = $this->nota["name"];
			$this->xml_tipo = $this->nota["type"];
			$this->xml_temp = $this->nota["tmp_name"];
			$this->xml_erro = $this->nota["error"];
			$this->xml_tam = $this->nota["size"];
		}

		public function loadXML(){
			$this->xml = simplexml_load_file($this->xml_temp[0]);
		}

		public function create(){
			$this->cab();
			$this->ide();
			$this->emit();
			$this->dest();
			$this->total();
			// $this->transporte();
			// $this->cobranca();
			$this->nota();
		}

		private function cab(){
			foreach ($this->xml->NFe->infNFe->attributes() as $key => $value) {
				if($key == "Id")
					$this->xml_id = $value;
				else
					$this->xml_versao = $value;
			}
		}

		private function ide(){
			$this->cUF = $this->xml->NFe->infNFe->ide->cUF;
			$this->cNF = $this->xml->NFe->infNFe->ide->cNF;
			$this->natOp = $this->xml->NFe->infNFe->ide->natOp;
			$this->indPag = $this->xml->NFe->infNFe->ide->indPag;
			$this->mod = $this->xml->NFe->infNFe->ide->mod;
			$this->serie = $this->xml->NFe->infNFe->ide->serie;
			$this->nNF = $this->xml->NFe->infNFe->ide->nNF;
			$this->dEmi = $this->xml->NFe->infNFe->ide->dEmi;
			$this->tpNF = $this->xml->NFe->infNFe->ide->tpNF;
			$this->cMunFG = $this->xml->NFe->infNFe->ide->cMunFG;
			$this->tpImp = $this->xml->NFe->infNFe->ide->tpImp;
			$this->tpEmis = $this->xml->NFe->infNFe->ide->tpEmis;
			$this->cDV = $this->xml->NFe->infNFe->ide->cDV;
			$this->tpAmb = $this->xml->NFe->infNFe->ide->tpAmb;
			$this->finNFe = $this->xml->NFe->infNFe->ide->finNFe;
			$this->procEmi = $this->xml->NFe->infNFe->ide->procEmi;
			$this->verProc = $this->xml->NFe->infNFe->ide->verProc;
		}

		private function emit(){
			$this->emitCNPJ = $this->xml->NFe->infNFe->emit->CNPJ;
			$this->emitxNome = $this->xml->NFe->infNFe->emit->xNome;
			$this->emitxFant = $this->xml->NFe->infNFe->emit->xFant;
			$this->emitIE = $this->xml->NFe->infNFe->emit->IE;
			$this->emitCRT = $this->xml->NFe->infNFe->emit->CRT;
			//endereco
			$this->emitxLgr = $this->xml->NFe->infNFe->emit->enderEmit->xLgr;
			$this->emitnro = $this->xml->NFe->infNFe->emit->enderEmit->nro;
			$this->emitxBairro = $this->xml->NFe->infNFe->emit->enderEmit->xBairro;
			$this->emitcMun = $this->xml->NFe->infNFe->emit->enderEmit->cMun;
			$this->emitxMun = $this->xml->NFe->infNFe->emit->enderEmit->xMun;
			$this->emitUF = $this->xml->NFe->infNFe->emit->enderEmit->UF;
			$this->emitCEP = $this->xml->NFe->infNFe->emit->enderEmit->CEP;
			$this->emitcPais = $this->xml->NFe->infNFe->emit->enderEmit->cPais;
			$this->emitxPais = $this->xml->NFe->infNFe->emit->enderEmit->xPais;
			$this->emitfone = $this->xml->NFe->infNFe->emit->enderEmit->fone;
		}

		private function dest(){
			$this->destCNPJ = $this->xml->NFe->infNFe->dest->CNPJ;
			$this->destxNome = $this->xml->NFe->infNFe->dest->xNome;
			$this->destIE = $this->xml->NFe->infNFe->dest->IE;
			$this->destemail = $this->xml->NFe->infNFe->dest->email;
			//endereco
			$this->destxLgr = $this->xml->NFe->infNFe->dest->enderDest->xLgr;
			$this->destnro = $this->xml->NFe->infNFe->dest->enderDest->nro;
			$this->destxCpl = $this->xml->NFe->infNFe->dest->enderDest->xCpl;
			$this->destxBairro = $this->xml->NFe->infNFe->dest->enderDest->xBairro;
			$this->destcMun = $this->xml->NFe->infNFe->dest->enderDest->cMun;
			$this->destxMun = $this->xml->NFe->infNFe->dest->enderDest->xMun;
			$this->destUF = $this->xml->NFe->infNFe->dest->enderDest->UF;
			$this->destCEP = $this->xml->NFe->infNFe->dest->enderDest->CEP;
			$this->destcPais = $this->xml->NFe->infNFe->dest->enderDest->cPais;
			$this->destxPais = $this->xml->NFe->infNFe->dest->enderDest->xPais;
			$this->destfone = $this->xml->NFe->infNFe->dest->enderDest->fone;
		}

		private function total(){
			$this->totalvBC = $this->xml->NFe->infNFe->total->ICMSTot->vBC;
			$this->totalvICMS = $this->xml->NFe->infNFe->total->ICMSTot->vICMS;
			$this->totalvBCST = $this->xml->NFe->infNFe->total->ICMSTot->vBCST;
			$this->totalvST = $this->xml->NFe->infNFe->total->ICMSTot->vST;
			$this->totalvProd = $this->xml->NFe->infNFe->total->ICMSTot->vProd;
			$this->totalvFrete = $this->xml->NFe->infNFe->total->ICMSTot->vFrete;
			$this->totalvSeg = $this->xml->NFe->infNFe->total->ICMSTot->vSeg;
			$this->totalvDesc = $this->xml->NFe->infNFe->total->ICMSTot->vDesc;
			$this->totalvII = $this->xml->NFe->infNFe->total->ICMSTot->vII;
			$this->totalvIPI = $this->xml->NFe->infNFe->total->ICMSTot->vIPI;
			$this->totalvPIS = $this->xml->NFe->infNFe->total->ICMSTot->vPIS;
			$this->totalvCOFINS = $this->xml->NFe->infNFe->total->ICMSTot->vCOFINS;
			$this->totalvOutro = $this->xml->NFe->infNFe->total->ICMSTot->vOutro;
			$this->totalvNF = $this->xml->NFe->infNFe->total->ICMSTot->vNF;
		}

		// private function transporte(){
		// 	$this->transpmodFrete = $this->xml->NFe->infNFe->transp->modFrete;
		// 	$this->transpCNPJ = $this->xml->NFe->infNFe->transp->transporta->CNPJ;
		// 	$this->transpxNome = $this->xml->NFe->infNFe->transp->transporta->xNome;
		// 	$this->transpIE = $this->xml->NFe->infNFe->transp->transporta->IE;
		// 	$this->transpxEnder = $this->xml->NFe->infNFe->transp->transporta->xEnder;
		// 	$this->transpxMun = $this->xml->NFe->infNFe->transp->transporta->xMun;
		// 	$this->transpUF = $this->xml->NFe->infNFe->transp->transporta->UF;
		// 	$this->transpqVol = $this->xml->NFe->infNFe->transp->vol->qVol;
		// 	$this->transpesp = $this->xml->NFe->infNFe->transp->vol->esp;
		// 	$this->transppesoL = $this->xml->NFe->infNFe->transp->vol->pesoL;
		// 	$this->transppesoB = $this->xml->NFe->infNFe->transp->vol->pesoB;
		// }

		// private function cobranca(){
		// 	$this->cobrnFat = $this->xml->NFe->infNFe->cobr->fat->nFat;
		// 	$this->cobrvOrig = $this->xml->NFe->infNFe->cobr->fat->vOrig;
		// 	$this->cobrvLiq = $this->xml->NFe->infNFe->cobr->fat->vLiq;
		// 	$this->cobrnDup = $this->xml->NFe->infNFe->cobr->dup->nDup;
		// 	$this->cobrdVenc = $this->xml->NFe->infNFe->cobr->dup->dVenc;
		// 	$this->cobrvDup = $this->xml->NFe->infNFe->cobr->dup->vDup;
		// }

		private function nota(){
			$this->infoinfCpl = $this->xml->NFe->infNFe->infAdic->infCpl;
			
			$this->assDigestValue = $this->xml->NFe->Signature->SignedInfo->Reference->DigestValue;
			$this->assSignatureValue = $this->xml->NFe->Signature->SignatureValue;
			$this->assX509Certificate = $this->xml->NFe->Signature->KeyInfo->X509Data->X509Certificate;
			
			$this->prottpAmb = $this->xml->protNFe->infProt->tpAmb;
			$this->protverAplic = $this->xml->protNFe->infProt->verAplic;
			$this->protchNFe = $this->xml->protNFe->infProt->chNFe;
			$this->protdhRecbto = $this->xml->protNFe->infProt->dhRecbto;
			$this->protnProt = $this->xml->protNFe->infProt->nProt;
			$this->protdigVal = $this->xml->protNFe->infProt->digVal;
			$this->protcStat = $this->xml->protNFe->infProt->cStat;
			$this->protxMotivo = $this->xml->protNFe->infProt->xMotivo;
		}

		public function validaProdutos($xmlRetornado){

		    for($i=0; $i<sizeof($xmlRetornado->NFe->infNFe->det); $i++){

		        $cProd = $xmlRetornado->NFe->infNFe->det[$i]->prod->cProd;
		        $xProd = $xmlRetornado->NFe->infNFe->det[$i]->prod->xProd;
		        $NCM = $xmlRetornado->NFe->infNFe->det[$i]->prod->NCM;
		        $CFOP = $xmlRetornado->NFe->infNFe->det[$i]->prod->CFOP;
		        $uCom = $xmlRetornado->NFe->infNFe->det[$i]->prod->uCom;
		        $qCom = $xmlRetornado->NFe->infNFe->det[$i]->prod->qCom;
		        $vUnCom = $xmlRetornado->NFe->infNFe->det[$i]->prod->vUnCom;
		        $vProd = $xmlRetornado->NFe->infNFe->det[$i]->prod->vProd;
		        $uTrib = $xmlRetornado->NFe->infNFe->det[$i]->prod->uTrib;
		        $qTrib = $xmlRetornado->NFe->infNFe->det[$i]->prod->qTrib;
		        $vUnTrib = $xmlRetornado->NFe->infNFe->det[$i]->prod->vUnTrib;
		        $indTot = $xmlRetornado->NFe->infNFe->det[$i]->prod->indTot;
		        $infAdProd = $xmlRetornado->NFe->infNFe->det[$i]->infAdProd;

		        //impostos
		        $ISSQN_vBC = $xmlRetornado->NFe->infNFe->det[$i]->imposto->ISSQN->vBC;
		        $ISSQN_vAliq = $xmlRetornado->NFe->infNFe->det[$i]->imposto->ISSQN->vAliq;
		        $ISSQN_vISSQN = $xmlRetornado->NFe->infNFe->det[$i]->imposto->ISSQN->vISSQN;
		        $ISSQN_cMunFG = $xmlRetornado->NFe->infNFe->det[$i]->imposto->ISSQN->cMunFG;
		        $ISSQN_cListServ = $xmlRetornado->NFe->infNFe->det[$i]->imposto->ISSQN->cListServ;
		        $ISSQN_indISS = $xmlRetornado->NFe->infNFe->det[$i]->imposto->ISSQN->indISS;
		        $ISSQN_indIncentivo = $xmlRetornado->NFe->infNFe->det[$i]->imposto->ISSQN->indIncentivo;

		        $PIS_CST = $xmlRetornado->NFe->infNFe->det[$i]->imposto->PIS->PISAliq->CST;
		        $PIS_vBC = $xmlRetornado->NFe->infNFe->det[$i]->imposto->PIS->PISAliq->vBC;
		        $PIS_pPIS = $xmlRetornado->NFe->infNFe->det[$i]->imposto->PIS->PISAliq->pPIS;
		        $PIS_vPIS = $xmlRetornado->NFe->infNFe->det[$i]->imposto->PIS->PISAliq->vPIS;

		        $COFINS_CST = $xmlRetornado->NFe->infNFe->det[$i]->imposto->COFINS->COFINSAliq->CST;
		        $COFINS_vBC = $xmlRetornado->NFe->infNFe->det[$i]->imposto->COFINS->COFINSAliq->vBC;
		        $COFINS_pCOFINS = $xmlRetornado->NFe->infNFe->det[$i]->imposto->COFINS->COFINSAliq->pCOFINS;
		        $COFINS_vCOFINS = $xmlRetornado->NFe->infNFe->det[$i]->imposto->COFINS->COFINSAliq->vCOFINS;

		        //Criar o produto caso não exista na base..

		        //Validar se produto já existe
		        $prod_exsts = ORM::for_table('sys_items')
				        		  ->where('mercosur_nomenclature', $NCM)
				        		  ->find_one();

				if(! $prod_exsts){

			        //Buscar unidade do produto
			        $unit_prod = ORM::for_table('sys_items_unit')
					        		  ->where('initials', $uCom)
					        		  ->find_one();

					if(! isset($unit_prod['id']))
						$unit_prod = 1;
					else{
						$unit_prod = $unit_prod['id'];
					}

					//Inserção produto..
			        $d = ORM::for_table('sys_items')->create();
					$d->name = $xProd;
					$d->description = $xProd;
					$d->unit_id = $unit_prod;
					$d->sales_price = $vUnCom;
					$d->cost_price = $vUnCom;
					$d->unit_price = $vUnCom;
					$d->promo_price = $vUnCom;
					$d->type = "Product";
					$d->mercosur_nomenclature = $NCM;
					$d->status = "Active";
					$d->notes = null;
					$d->type_of_product = 'Finished product';
					$d->production = 'Own';
					$d->complementary_description = null;
					$d->item_number = 1;				
					$d->gross_weight = '0.000';
					$d->net_weight = '0.000';
					$d->barcode_marketing = null;
					$d->barcode = null;
					$d->category_id = null;
					$d->item_per_package = null;
					$d->ipi_framework = null;
					$d->ipi_fixed_amount = '0.00';
					$d->ipi_code = null;
					$d->cest_code = null;
					$d->save();

					$this->product_inseted[sizeof($this->product_inseted)+1] = $xProd;

					$prodct = ORM::for_table('sys_items')
					        		  ->where('mercosur_nomenclature', $NCM)
					        		  ->find_one();

					$stock_full = ORM::for_table('sys_stock')->create();
					$stock_full->sys_items_id = $prodct['id'];
					$stock_full->dt_cadastro = date("Y-m-d H:i:s");;
		            $stock_full->type = 'Entrada';
		            $stock_full->date = date("Y-m-d");
		            $stock_full->time = date("H:i:s");
		            $stock_full->quantity = $qCom;
		            $stock_full->unit_price = $vUnCom;
		            $stock_full->dt_atualizacao = date("Y-m-d H:i:s");
		            $stock_full->observation = 'Importação pela Nota Fiscal';
		            $stock_full->save();

					$stock = ORM::for_table('sys_items_stock')
					        		  ->where('sys_items_id', $prodct['id'])
					        		  ->find_one();
					
					if(! $stock){
						$stock = ORM::for_table('sys_items_stock')->create();
						$stock->sys_items_id = $prodct['id'];
					}else{
						$stock = ORM::for_table('sys_items_stock')
                        ->find_one($stock['id']);
					}

		            $stock->current_stock = Finance::amount_fix($qCom);
		            $stock->minumum_stock = '0.00';
		            $stock->maximum_stock = '0.00';
		            $stock->control_stock = 1;
		            $stock->save();

				}else{
					$prodct = ORM::for_table('sys_items')
					        		  ->where('mercosur_nomenclature', $NCM)
					        		  ->find_one();

					$stock_full = ORM::for_table('sys_stock')->create();
					$stock_full->sys_items_id = $prodct['id'];
					$stock_full->dt_cadastro = date("Y-m-d H:i:s");;
		            $stock_full->type = 'Entrada';
		            $stock_full->date = date("Y-m-d");
		            $stock_full->time = date("H:i:s");
		            $stock_full->quantity = $qCom;
		            $stock_full->unit_price = $vUnCom;
		            $stock_full->dt_atualizacao = date("Y-m-d H:i:s");
		            $stock_full->observation = 'Importação pela Nota Fiscal';
		            $stock_full->save();

					$stock = ORM::for_table('sys_items_stock')
					        		  ->where('sys_items_id', $prodct['id'])
					        		  ->find_one();
					
					if(! $stock){
						$stock = ORM::for_table('sys_items_stock')->create();
						$stock->sys_items_id = $prodct['id'];
					}else{
						$stock = ORM::for_table('sys_items_stock')
                        ->find_one($stock['id']);
					}

		            $stock->current_stock = Finance::amount_fix($qCom);
		            $stock->minumum_stock = '0.00';
		            $stock->maximum_stock = '0.00';
		            $stock->control_stock = 1;
		            $stock->save();
				}

		    }

		}

		public function trataRetorno($aResposta){
		    if($aResposta['xMotivo'] == 'Pedido de Download processado'){
		        if($aResposta['aRetNFe']['xMotivo'] == 'Download disponibilizado'){
		            //Tratar os produtos:
		            $xmlRetornado = simplexml_load_string($aResposta['aRetNFe']['nfeProc']);

		            $this->validaProdutos($xmlRetornado);

		            $retorno = "Nota baixada com sucesso!<br><br>Todos os produtos foram processados!";
		        }else{
		            if( $aResposta['aRetNFe']['xMotivo'] == 'Rejeicao: NF-e indisponivel para download devido a ausencia de Manifestacao do Destinatario'){
		                
		                $retorno = "Manifest";
		                
		            }else{
		                $retorno = $aResposta['aRetNFe']['xMotivo'];
		            }            
		        }
		    }else if($aResposta['xMotivo'] == 'Rejeicao: Falha no Esquema XML'){
		        $retorno = "Número da nota é inválido";
		    }else{
		        $retorno = $aResposta['xMotivo'];
		    }

		    return $retorno;
		}

	}

?>

Anon7 - 2022
AnonSec Team