Created
February 28, 2014 10:57
-
-
Save viniciusss/9269152 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
require_once(dirname(__FILE__) . "/../includes/funcoes.inc.php"); | |
require_once(dirname(__FILE__) . "/../includes/global.php"); | |
require_once(dirname(__FILE__) . "/../includes/geral.class.php"); | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL); | |
set_time_limit(0); | |
ini_set('memory_limit', '1024M'); | |
geraDebugOn(); | |
$dbExecutaSapiens = new Vs_Db_Executa('sapiens'); | |
$query = <<<QUERY | |
select codfil, codsnf, numnfv | |
from e210mvp | |
where 1=1 | |
and datmov between to_date('17/02/2014', 'dd/mm/yyyy') and to_date('19/02/2014', 'dd/mm/yyyy') | |
and e210mvp.numnfv > 0 | |
and SUBSTR(e210mvp.codsnf, 1, 1) = 'C' | |
and not exists( | |
select 'x' | |
from e140nfv | |
where 1=1 | |
and e140nfv.codfil = e210mvp.codfil | |
and e140nfv.codsnf = e210mvp.codsnf | |
and e140nfv.numnfv = e210mvp.numnfv | |
); | |
QUERY; | |
$estoques = $dbExecutaSapiens->fetchAll( | |
new Vs_Db_Select($query) | |
); | |
foreach( $estoques as $estoque ) { | |
$dbExecutaSapiens->execute( | |
sprintf( | |
" | |
delete from e210mvp | |
where codfil = %d | |
and codsnf = '%s' | |
and numnfv = %s | |
", | |
$estoque['codfil'], | |
$estoque['codsnf'], | |
$estoque['numnfv'] | |
) | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
require_once(dirname(__FILE__) . "/../includes/funcoes.inc.php"); | |
require_once(dirname(__FILE__) . "/../includes/global.php"); | |
require_once(dirname(__FILE__) . "/../includes/geral.class.php"); | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL); | |
set_time_limit(0); | |
ini_set('memory_limit', '1024M'); | |
geraDebugOn(); | |
$dbExecutaSapiens = new Vs_Db_Executa('sapiens'); | |
$dbExecuta = new Vs_Db_Executa(); | |
$oIntegracao = new Integracao(); | |
$apagarCupom = function ($codFilial, $codSnf, $numNota) use ($dbExecutaSapiens) { | |
$numNfv = $dbExecutaSapiens->fetchOne( | |
new Vs_Db_Select( | |
sprintf( | |
" | |
SELECT numnfv | |
from e140nfv | |
where codfil = %d | |
and codsnf = '%s' | |
and numcfi = '%s'", | |
$codFilial, | |
$codSnf, | |
$numNota | |
) | |
) | |
); | |
$separador = $dbExecutaSapiens->fetchOne( | |
new Vs_Db_Select( | |
sprintf( | |
' | |
select despar | |
from e020par | |
where codemp = 1 | |
and codfil = %d | |
and codsnf = \'%s\' | |
and codpar = 1', | |
$codFilial, | |
$codSnf | |
) | |
) | |
); | |
$separador = substr($separador, 0, strpos($separador, 0) + 1); | |
$deletes = [ | |
'DELETE E301RAT WHERE NUMTIT = \'%s\' AND CODFIL = %d', | |
'DELETE E301MCR WHERE NUMTIT = \'%s\' AND CODFIL = %d', | |
'DELETE E301MOR WHERE NUMTIT = \'%s\' AND CODFIL = %d', | |
'DELETE E301TCR WHERE NUMTIT = \'%s\' AND CODFIL = %d', | |
]; | |
$titulos = $dbExecutaSapiens->fetchAll( | |
new Vs_Db_Select( | |
sprintf( | |
" | |
SELECT NUMTIT | |
FROM e140par | |
WHERE codfil = '%s' | |
AND codsnf = '%s' | |
AND numnfv = '%s' | |
", | |
$codFilial, | |
$codSnf, | |
$numNfv | |
) | |
) | |
); | |
foreach($titulos as $titulo) { | |
foreach ($deletes as $delete) { | |
$dbExecutaSapiens->execute( | |
sprintf( | |
$delete, | |
$titulo['NUMTIT'], | |
'%', | |
$codFilial | |
) | |
); | |
} | |
} | |
$deletes = [ | |
'delete from e140obs where codfil = %d and codsnf = \'%s\' and numnfv IN(%d)', | |
'delete from e140rat where codfil = %d and codsnf = \'%s\' and numnfv IN(%d)', | |
'delete from e140par where codfil = %d and codsnf = \'%s\' and numnfv IN(%d)', | |
'delete from e140ipv where codfil = %d and codsnf = \'%s\' and numnfv IN(%d)', | |
'delete from e140ide where codfil = %d and codsnf = \'%s\' and numnfv IN(%d)', | |
'delete from e140tnf where codfil = %d and codsnf = \'%s\' and numnfv IN(%d)', | |
'delete from e140nfv where codfil = %d and codsnf = \'%s\' and numnfv IN(%d)', | |
'delete from e210mvp where codfil = %d and codsnf = \'%s\' and numnfv IN(%d)', | |
]; | |
foreach ($deletes as $delete) { | |
$dbExecutaSapiens->execute( | |
sprintf( | |
$delete, | |
$codFilial, | |
$codSnf, | |
$numNfv | |
) | |
); | |
} | |
$deletes = [ | |
"DELETE FROM E301RAT WHERE CODFIL = %d AND NUMTIT = '%s'", | |
"DELETE FROM E301MCR WHERE CODFIL = %d AND NUMTIT = '%s'", | |
"DELETE FROM E301MOR WHERE CODFIL = %d AND NUMTIT = '%s'", | |
"DELETE FROM E301TCR WHERE CODFIL = %d AND NUMTIT = '%s'", | |
]; | |
foreach($titulos as $titulo) { | |
foreach ($deletes as $delete) { | |
$dbExecutaSapiens->execute( | |
sprintf( | |
$delete, | |
$codFilial, | |
$titulo['NUMTIT'], | |
'%' | |
) | |
); | |
} | |
} | |
$deletes = [ | |
"DELETE FROM E501RAT WHERE NUMTIT LIKE '%s%s' AND CODTPT = 'DEV'", | |
"DELETE FROM E501MCP WHERE NUMTIT LIKE '%s%s' AND CODTPT = 'DEV'", | |
"DELETE FROM E501MOP WHERE NUMTIT LIKE '%s%s' AND CODTPT = 'DEV'", | |
"DELETE FROM E501TCP WHERE NUMTIT LIKE '%s%s' AND CODTPT = 'DEV'", | |
]; | |
foreach ($deletes as $delete) { | |
$dbExecutaSapiens->execute( | |
sprintf( | |
$delete, | |
$numNfv . $separador, | |
'%' | |
) | |
); | |
} | |
}; | |
function getIdRequisicao($storeno, $ecfno, $coo) | |
{ | |
$idVenda = g_arr_executa_query( | |
sprintf( | |
' | |
select v.id_venda | |
from foxpaf.paf p | |
left join foxpaf.venda v on | |
(v.id_paf = p.id_paf and v.coo = %d) | |
where storeno = %d | |
and ecfno = %d', | |
$coo, | |
$storeno, | |
$ecfno | |
), | |
'getOne' | |
); | |
return g_arr_executa_query( | |
sprintf( | |
' | |
select id, parametros | |
from webpdv.sapiens_requisicao | |
where 1=1 | |
and metodo = "NotaFiscalSaida" | |
and identificador = "%s" | |
and status IN("Pendente", "Sucesso", "Erro")', | |
$idVenda | |
) | |
)[0]; | |
} | |
if (isset($_POST['importar'])) { | |
$file = new SplFileObject($_FILES['arquivo']['tmp_name']); | |
$cupons = []; | |
$file->fgetcsv(); | |
while (!$file->eof()) { | |
$cupons[] = $file->fgetcsv(';'); | |
} | |
foreach ($cupons as $cupom) { | |
if (empty($cupom[0])) { | |
continue; | |
} | |
$requisicao = getIdRequisicao($cupom[1], $cupom[6], $cupom[5]); | |
$oIntegracao->recarregaRequisicaoSapiens($cupom[1], $requisicao['id']); | |
$requisicao = getIdRequisicao($cupom[1], $cupom[6], $cupom[5]); | |
$requisicao['parametros'] = json_decode( | |
$requisicao['parametros'], | |
true | |
); | |
$requisicao['parametros']['tipoProcessamento'] = 4; | |
$requisicao['parametros'] = json_encode( | |
$requisicao['parametros'] | |
); | |
$requisicao['status'] = 'Pendente'; | |
$dbExecuta->execute( | |
sprintf( | |
'UPDATE webpdv.sapiens_requisicao SET | |
parametros = \'%s\', | |
status = \'%s\' | |
WHERE id = %d | |
', | |
$requisicao['parametros'], | |
$requisicao['status'], | |
$requisicao['id'] | |
) | |
); | |
try { | |
$dbExecutaSapiens->startTransaction(); | |
$apagarCupom($cupom[1], $cupom[2], $cupom[5]); | |
$dbExecutaSapiens->commitTransaction(); | |
} catch (Exception $e) { | |
echo '<br>' . $e->getMessage() . '<br>'; | |
$dbExecutaSapiens->rollBackTransaction(); | |
exit; | |
} | |
} | |
exit; | |
} | |
?> | |
<!doctype html> | |
<html> | |
<head> | |
<title>Importar arquivo CSV</title> | |
</head> | |
<body> | |
<form action="sapiens_reintegrar_cupons_pagamento_99.php" method="post" enctype="multipart/form-data"> | |
<input type="hidden" name="importar" value="1"/> | |
<fieldset> | |
<label for="arquivo"> | |
<input type="file" name="arquivo" id="arqvuido" required=""/> | |
</label> | |
</fieldset> | |
<input type="submit" value="Enviar Arquivo"/> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment