Created
July 22, 2021 01:46
-
-
Save FredAzevedo/cd0c935624a3b6bade5915813d8e4bc9 to your computer and use it in GitHub Desktop.
BoletoController
This file contains 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 | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Crypt; | |
use App\Models\Pedido; | |
use App\Models\Cliente; | |
use App\Models\EmailCliente; | |
use App\Models\TelefonesCliente; | |
use App\Libs\PJBankApi; | |
use App\Libs\Utilidades; | |
use App\Models\BoletoApi; | |
use App\Models\SystemUnit; | |
use App\Models\ApiIntegracao; | |
use DB; | |
use App\Models\Site; | |
class BoletoController extends Controller | |
{ | |
/** | |
* Display a listing of the resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function index(Request $request, $param) | |
{ | |
$pedido_id = Crypt::decrypt($param); | |
$pedido = Pedido::where('id',$pedido_id)->first(); | |
$cliente_id = $pedido->cliente_faturamento_id; | |
$cliente = Cliente::where('id',$cliente_id)->first(); | |
$clienteEmail = EmailCliente::where('cliente_id','=',$cliente_id)->first(); | |
$clienteTelefone = TelefonesCliente::where('cliente_id','=',$cliente_id)->first(); | |
$unit = SystemUnit::where('id',$pedido->unit_id)->first(); | |
$dados_api_integracao = ApiIntegracao::where('unit_id','=',$pedido->unit_id) | |
->where('tipo','=', 1) | |
->where('producao','=', $unit->producao) | |
->first(); | |
$credencial = $dados_api_integracao->credencial; | |
$ambiente = $dados_api_integracao->url; | |
$chave = $dados_api_integracao->chave; | |
try | |
{ | |
DB::beginTransaction(); | |
if($pedido->boleto_emitido == "N") | |
{ | |
$datavencimentoDB = $pedido->data_vencimento; | |
$boleto = [ | |
'vencimento' => $datavencimentoDB, | |
'valor' => $pedido->total_pedido, | |
'juros' => 1.0, | |
'multa' => 2.0, | |
'desconto' => 0, | |
'cliente_id' => $cliente_id, | |
'nome_cliente' => $cliente->razao_social, | |
'cpf_cliente' => Utilidades::removerCaracteresEspeciais($cliente->cpf_cnpj), | |
'endereco_cliente' => $cliente->logradouro, | |
'numero_cliente' => $cliente->numero, | |
'complemento_cliente' => $cliente->complemento, | |
'bairro_cliente' => $cliente->bairro, | |
'cidade_cliente' => $cliente->cidade, | |
'estado_cliente' => $cliente->uf, | |
'cep_cliente' => Utilidades::removerCaracteresEspeciais($cliente->cep), | |
'email_cliente' => $clienteEmail->email, | |
'telefone_cliente' => Utilidades::removerCaracteresEspeciais($clienteTelefone->telefone), | |
'logo_url' => "", | |
'texto' => "BOLETO REFERENTE A SERVIÇOS DE CERTIFICAÇÃO DIGITAL. PEDIDO Nº: ".$pedido->id, | |
'grupo' => "Boleto", | |
'juros_fixo' => 0, | |
'multa_fixo' => 0, | |
'diasdesconto1' => 0, | |
'desconto2' => 0, | |
'diasdesconto2' => 0, | |
'desconto3' => 0, | |
'diasdesconto3' => 0, | |
'nunca_atualizar_boleto' => 0,//0 - 1 | |
'instrucao_adicional' => '', | |
'webhook' => '', | |
'especie_documento' => 'DS', | |
'unit_id' => $pedido->unit_id, | |
'user_id' => $pedido->user_id, | |
'formato' => 'BOLETO', | |
'contas_receber_id' => 0, | |
'pedido_numero' => $pedido_id, | |
'credencial' => $credencial, | |
'ambiente' => $ambiente, | |
'chave' => $chave, | |
'pedido_numero' => $pedido_id | |
]; | |
$boletoCriado = BoletoApi::create($boleto); | |
$boleto_emitido = PJBankApi::emitirBoleto($boleto); // falta somente aqui... | |
if($boleto_emitido->status == '201' || $boleto_emitido->status == '200'){ | |
$boletoUP = BoletoApi::where('pedido_numero',$pedido_id)->first(); | |
$boleto_array = [ | |
'vencimento' => $datavencimentoDB, | |
'status' => $boleto_emitido->status, | |
'msg' => $boleto_emitido->msg, | |
'nossonumero' => $boleto_emitido->nossonumero, | |
'id_unico' => $boleto_emitido->id_unico, | |
'banco_numero' => $boleto_emitido->banco_numero, | |
'token_facilitador' => $boleto_emitido->token_facilitador, | |
'credencial' => $boleto_emitido->credencial, | |
'linkBoleto' => $boleto_emitido->linkBoleto, | |
'linkGrupo' => $boleto_emitido->linkGrupo, | |
'linhaDigitavel' => $boleto_emitido->linhaDigitavel | |
]; | |
$boletoUP->fill($boleto_array)->save(); | |
$pedido_data = [ | |
'boleto_pdf' => $boletoUP->linkBoleto, | |
'boleto_emitido' => "S", | |
]; | |
$pedido->fill($pedido_data)->save(); | |
// $site = Site::all(); | |
// return view('site.boleto', [ | |
// 'pedido' => $pedido, | |
// 'site' => $site | |
// ]); | |
} | |
} | |
else | |
{ | |
} | |
DB::commit(); | |
}catch(\Exception $e){ | |
DB::rollBack(); | |
\Log::error($e); | |
return back()->withInput(); | |
} | |
} | |
/** | |
* Show the form for creating a new resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function create() | |
{ | |
// | |
} | |
/** | |
* Store a newly created resource in storage. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return \Illuminate\Http\Response | |
*/ | |
public function store(Request $request) | |
{ | |
// | |
} | |
/** | |
* Display the specified resource. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function show($id) | |
{ | |
$pedido_id = Crypt::decrypt($id); | |
$pedido = Pedido::where('id',$pedido_id)->first(); | |
return view('site.boleto', ['pedido' => $pedido]); | |
} | |
/** | |
* Show the form for editing the specified resource. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function edit($id) | |
{ | |
// | |
} | |
/** | |
* Update the specified resource in storage. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function update(Request $request, $id) | |
{ | |
// | |
} | |
/** | |
* Remove the specified resource from storage. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function destroy($id) | |
{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment