| Server IP : 54.94.228.101 / Your IP : 172.28.20.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/app/Modules/ContaReceberLog/Models/ |
Upload File : |
<?php
namespace App\Modules\ContaReceberLog\Models;
use DB;
use App\MyModel;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
use \Dimsav\Translatable\Translatable;
use App\CampoModulo;
class ContaReceberLog extends MyModel
{
use LogsActivity;
use HasSlug;
use Translatable;
protected $table = 'conta_receber_log';
protected $guarded = [];
private $rules = array();
private $messages = array();
public $translatedAttributes = [];
public $translationModel = 'App\Modules\ContaReceberLog\Models\ContaReceberLogDescricao';
public function __construct(){
parent::__construct();
$this->setMessages($this->messages);
$this->setRules($this->rules);
$this->translatedAttributes = CampoModulo::join('sis_modulos', 'sis_campo_modulo.id_modulo', '=', 'sis_modulos.id')->where('sis_campo_modulo.translatable', 1)->where('sis_modulos.nome', 'ContaReceberLog')->pluck('sis_campo_modulo.nome')->toArray();
}
public function getLogNameToUse(string $eventName = ''): string
{
return 'log_conta_receber_log';
}
/**
* Get the options for generating the slug.
*/
public function getSlugOptions() : SlugOptions
{
return SlugOptions::create()
->generateSlugsFrom(['nome', 'titulo'])
->saveSlugsTo('slug');
}
public function getBySlug($slug){
return DB::table($this->table)->where('slug',$slug)->firstOrFail();
}
public function criar($fields, $input){
$insert = [];
foreach ($fields as $field) {
$insert[$field] = $input[$field];
}
$conta_receber_log = new ContaReceberLog();
$conta_receber_log->fill($insert);
$conta_receber_log->save();
return $conta_receber_log->id;
}
public function editar($fields, $input, $id){
$insert = [];
foreach ($fields as $field) {
$insert[$field] = $input[$field];
}
$conta_receber_log = ContaReceberLog::find($id);
$conta_receber_log->fill($insert);
$conta_receber_log->save();
return $id;
}
public static function saveLog($objConta, $response, $body){
try {
if(isset($objConta->id_pedido_venda)){
$ContaReceberLog = ContaReceberLog::where('tipo_titulo', $objConta->tipo)
->where('data_titulo', $objConta->data_titulo)
->where('empresa_id', $objConta->empresa)
->where('id_pedido_venda', $objConta->id_pedido_venda)->first();
}else{
$ContaReceberLog = ContaReceberLog::where('tipo_titulo', $objConta->tipo)
->where('data_titulo', $objConta->data_titulo)
->where('empresa_id', $objConta->empresa)->first();
}
if(!$ContaReceberLog){
$ContaReceberLog = new ContaReceberLog;
$ContaReceberLog->empresa_id = $objConta->empresa;
$ContaReceberLog->data_titulo = $objConta->data_titulo;
$ContaReceberLog->tipo_titulo = $objConta->tipo;
}
$ContaReceberLog->valor_titulo = $objConta->valor;
$ContaReceberLog->status_processamento = (isset($response->retorno->status_processamento) ? $response->retorno->status_processamento : '');
$ContaReceberLog->mensagem_processamento = (isset($response->retorno->status) ? $response->retorno->status : '');
$ContaReceberLog->body = json_encode($body);
$ContaReceberLog->response = json_encode($response);
if(isset($objConta->id_pedido_venda)){
$ContaReceberLog->id_pedido_venda = $objConta->id_pedido_venda;
}
$ContaReceberLog->save();
return $ContaReceberLog;
} catch (Exception $e) {
return ['status' => false, 'message' => $e->getMessage()];
}
}
public function deletar($id){
$conta_receber_log = ContaReceberLog::find($id);
$conta_receber_log->delete();
return true;
}
public function getImagem($id){
return DB::table($this->table.'_imagens')->find($id);
}
public function getImagens($id){
return DB::table($this->table.'_imagens')->where('id_conta_receber_log', $id)->get();
}
public function criar_imagem($input){
return DB::table($this->table.'_imagens')->insert([
[
'id_conta_receber_log' => $input['id_conta_receber_log'],
'thumbnail_principal' => $input['thumbnail_principal'],
]
]);
}
public function deletar_imagem($id){
return DB::table($this->table.'_imagens')
->where('id', $id)
->delete();
}
public function getNextAutoIncrement(){
$lastId = DB::select("SELECT AUTO_INCREMENT FROM information_schema.tables WHERE TABLE_NAME = '$this->table' ORDER BY table_name;")[0]->AUTO_INCREMENT;
return $lastId;
}
}