| Server IP : 162.214.74.102 / Your IP : 216.73.217.103 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/public_html/lrsys_apps/gasch/application/plugins/modulo_fiscal/controllers/ |
Upload File : |
<?php
_auth();
$ui->assign('_application_menu', 'modulo_fiscal');
$ui->assign('_title', $_L['Fiscal Module'] . ' - ' . $config['CompanyName']);
$ui->assign('_st', $_L['Settings Company']);
$action = $routes['2'];
$user = User::_info();
$ui->assign('user', $user);
$dir = "application/plugins/modulo_fiscal";
switch ($action) {
case 'list':
$listaConfigApp = ORM::for_table('app_fiscal_config')->find_many();
foreach ($listaConfigApp as $da) {
$dataCompany[$da['key']] = $da['value'];
}
if(sizeof($listaConfigApp)<1){
$ui->assign('status','semConfig');
$ui->assign('_include','semConfigUpNfe');
$ui->display('wrapper.tpl');
break;
}
if(empty($dataCompany['note_environment']) ||
empty($dataCompany['company_cnpj']) ||
empty($dataCompany['certificate']) ){
$ui->assign('status','configInvalid');
$ui->assign('_include','semConfigUpNfe');
$ui->display('wrapper.tpl');
break;
}
if(! file_exists('application/plugins/modulo_fiscal/empresa/certs/'.$dataCompany['certificate'])){
$ui->assign('status','semCert');
$ui->assign('_include','semConfigUpNfe');
$ui->display('wrapper.tpl');
break;
}
$ui->assign('xheader', '<link rel="stylesheet" type="text/css" href="' . $dir . '/assets/css/default.css"><link rel="stylesheet" type="text/css" href="ui/lib/dropzone/dropzone.css">');
$ui->assign('xfooter', '<script type="text/javascript" src="' . $dir . '/assets/js/default.js"></script><script type="text/javascript" src="ui/lib/dropzone/dropzone.js"></script>');
$ui->assign('_include','importar-list');
$ui->display('wrapper.tpl');
break;
case 'import_nfe_xml':
require_once $dir.'/controllers/loadXML.php';
break;
case 'import_nfe_gov':
$chNFe = $routes['3'];
$validaNfe = ORM::for_table('app_fiscal_nfe_imported')
->select('*')
->where('key', $chNFe)
->find_many();
if(sizeof($validaNfe)>0){
echo "<br><br><div class='alert alert-danger'>Esta nota já foi importada!</div>";
return;
}
require_once $dir.'/nfephp/bootstrap.php';
require_once $dir.'/controllers/config_nota.php';
require_once $dir.'/controllers/criaDataXML.php';
$listaConfigApp = ORM::for_table('app_fiscal_config')->find_many();
foreach ($listaConfigApp as $da) {
$dataCompany[$da['key']] = $da['value'];
}
$nfe = new NFePHP\NFe\ToolsNFe(geraConfig($dataCompany,'Nfe'));
$nfe->setModelo('55');
$cnpj = str_replace('/', '', str_replace('-', '', str_replace('.', '', $dataCompany['company_cnpj'])));
$aResposta = array();
$tpAmb = ($dataCompany['note_environment'] == 'homologacao') ? 2 : 1;
$aResposta = array();
$resp = $nfe->sefazDownload($chNFe, $tpAmb, $cnpj, $aResposta);
$xml_Nfe = new criaDataXML();
$retorno = $xml_Nfe->trataRetorno($aResposta);
// $make->insDadosXML();
if($retorno == "Manifest"){
$xJust = '';
$tpEvento = '210210'; //ciencia da operação
$xml = $nfe->sefazManifesta($chNFe, $tpAmb, $xJust = '', $tpEvento, $aResposta);
$resp = $nfe->sefazDownload($chNFe, $tpAmb, $cnpj, $aResposta);
$retorno = trataRetorno($aResposta);
}
echo $retorno."<br><br>";
if(strpos($retorno, "sucesso")){
if(sizeof($xml_Nfe->product_inseted)>0){
echo "<div class='alert alert-success'>Produtos inseridos:<br><br>";
$i=1;
echo "<ul>";
while($i<=sizeof($xml_Nfe->product_inseted)){
echo "<li>".$xml_Nfe->product_inseted[$i]."</li>";
$i++;
}
echo "<ul></div>";
}else{
echo "<div class='alert alert-success'>Todos os produtos presentes na nota já haviam no sistema, não houveram inserções, mas o estoque foi atualizado de acordo com as quantidades presentes na nota.</div>";
}
$controle_nfe = ORM::for_table('app_fiscal_nfe_imported')
->create();
$controle_nfe->key = $chNFe;
$controle_nfe->save();
}
break;
case 'add':
// Include list.tpl file from views/add.tpl
$ui->assign('_include','add');
// Wrap the Contents & Display The Page
$ui->display('wrapper.tpl');
break;
case 'add_post':
// Grab the data from Previous Page
$title = _post('title');
$contents = _post('contents');
if($title == ''){
r2(U.'notes/init/add/','e','Note Title is Required');
}
// We want to store data to app_notes table
$note = ORM::for_table('app_notes')->create();
// Set data for title column
$note->title = $title;
// Set data for contents column
$note->contents = $contents;
// Finally Store the data
$note->save();
// All done, Let's redirect the user to list notes
r2(U.'notes/init/list/','s','Note Added Successfully');
break;
case 'edit':
// Get note id from the URL
$id = $routes['3'];
// Find note by id
$note = ORM::for_table('app_notes')->find_one($id);
// Assign Note for views
$ui->assign('note',$note);
// Include edit.tpl file from views/edit.tpl
$ui->assign('_include','edit');
// Wrap the Contents & Display The Page
$ui->display('wrapper.tpl');
break;
case 'edit_post':
// Grab the data from Previous Page
$id = _post('id');
// Find the note by id
$note = ORM::for_table('app_notes')->find_one($id);
if(!$note){
r2(U.'notes/init/list/','e','Note Not Found');
}
$title = _post('title');
$contents = _post('contents');
if($title == ''){
r2(U.'notes/init/edit/'.$id.'/','e','Note Title is Required');
}
// Set New data for note title
$note->title = $title;
// Set data for note contents
$note->contents = $contents;
// Finally Store the data
$note->save();
// All done, Let's redirect the user and show that Note Updated
r2(U.'notes/init/edit/'.$id.'/','s','Note Edited Successfully');
break;
case 'delete':
// Get note id from the URL
$id = $routes['3'];
// Find note by id
$note = ORM::for_table('app_notes')->find_one($id);
// Delete Note
if($note){
$note->delete();
}
// Done, Let's Redirect the User to the List Notes
r2(U.'notes/init/list/','s','Note Deleted Successfully');
break;
default:
echo 'action not defined';
}