| Server IP : 54.233.248.239 / Your IP : 172.28.1.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/PedidoEntrega/Models/ |
Upload File : |
<?php
namespace App\Modules\PedidoEntrega\Models;
use DB;
use App\MyModel;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
use App\CampoModulo;
class PedidoEntrega extends MyModel
{
use LogsActivity;
//use HasSlug;
protected $table = 'pedido_entrega';
protected $guarded = [];
private $rules = array();
private $messages = array();
public function __construct(){
parent::__construct();
$this->setMessages($this->messages);
$this->setRules($this->rules);
}
public function getLogNameToUse(string $eventName = ''): string
{
return 'log_pedido_entrega';
}
/**
* 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];
}
$pedido_entrega = new PedidoEntrega();
$pedido_entrega->fill($insert);
$pedido_entrega->save();
return $pedido_entrega->id;
}
public function editar($fields, $input, $id){
$insert = [];
foreach ($fields as $field) {
$insert[$field] = $input[$field];
}
$pedido_entrega = PedidoEntrega::find($id);
$pedido_entrega->fill($insert);
$pedido_entrega->save();
return $id;
}
public function deletar($id){
$pedido_entrega = PedidoEntrega::find($id);
$pedido_entrega->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_pedido_entrega', $id)->get();
}
public function criar_imagem($input){
return DB::table($this->table.'_imagens')->insert([
[
'id_pedido_entrega' => $input['id_pedido_entrega'],
'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;
}
public function endereco(){
return $this->belongsTo('App\Modules\CadastroEndereco\Models\CadastroEndereco', 'id_cadastro_endereco');
}
public function adega(){
return $this->belongsTo('App\Modules\Adega\Models\Adega', 'id_adega');
}
public function pedidoVendaFrete(){
return $this->belongsTo('App\Modules\PedidoVenda\Models\PedidoVenda', 'id_pedido_venda_frete');
}
public function empresa(){
return $this->belongsTo('App\Modules\Empresa\Models\Empresa', 'empresa_id');
}
public function unidadeNegocio(){
return $this->belongsTo('App\Modules\UnidadeNegocio\Models\UnidadeNegocio', 'unidade_negocio_id');
}
public function cotacaoValor(){
return $this->belongsTo('App\Modules\CotacaoValor\Models\CotacaoValor', 'id_cotacao_valor');
}
public function status(){
return $this->belongsTo('App\Modules\PedidoEntregaStatus\Models\PedidoEntregaStatus', 'id_pedido_entrega_status');
}
public function confraria(){
return $this->belongsTo('App\Modules\Confraria\Models\Confraria', 'confraria_id');
}
public function statusHistorico(){
return $this->hasMany('App\Modules\PedidoEntregaHasStatus\Models\PedidoEntregaHasStatus', 'id_pedido_entrega')->orderBy('data', 'DESC')->orderBy('id', 'DESC');
}
public function statusAtual(){
return $this->hasMany('App\Modules\PedidoEntregaHasStatus\Models\PedidoEntregaHasStatus', 'id_pedido_entrega')->orderBy('data', 'DESC')->orderBy('id', 'DESC')->first();
}
public function statusAtualCliente(){
return $this->hasMany('App\Modules\PedidoEntregaHasStatus\Models\PedidoEntregaHasStatus', 'id_pedido_entrega')->whereRaw('notificar_cliente = 1 OR id_pedido_entrega_status IN (2)')->orderBy('data', 'DESC')->orderBy('id', 'DESC')->first();
}
public function cotacao(){
return $this->hasOne('App\Modules\Cotacao\Models\Cotacao', 'pedido_entrega_id');
}
public function transportadora(){
return $this->hasOne('App\Modules\Transportadora\Models\Transportadora', 'id', 'id_transportadora');
}
}