D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
rosario
/
adm
/
app
/
gre
/
Models
/
Filename :
ModTradeFabricanteMarcaEditar.php
back
Copy
<?php namespace App\gre\Models; if (!defined('URL')) { header("Location: /"); exit(); } /** * Description of ModTradeDistribuidorEditar * * @copyright (c) year, Carlos Marques - CM */ class ModTradeFabricanteMarcaEditar { private $Resultado; private $Dados; private $DadosId; private $DadosMarca; private $DadosItemMarca; private $DadosDistr; private $DadosItemDistr; function getResultado() { return $this->Resultado; } public function verFabr($DadosId) { $this->DadosId = (int) $DadosId; $verFabr = new \App\adms\Models\helper\AdmsRead(); $verFabr->fullRead("SELECT fabr.* FROM ro_trade_fornecedor fabr WHERE fabr.id =:id", "id=" . $this->DadosId ); $this->Resultado = $verFabr->getResultado(); return $this->Resultado; } public function verMarcas($DadosId) { $this->DadosId = $DadosId; $verMarca = new \App\adms\Models\helper\AdmsRead(); $verMarca->fullRead("select m.id marca_id, m.nome marca_nome from ro_trade_fabr_marca fm inner join ro_marca m on m.id = fm.marca_id where fm.fabr_id = :id order by m.nome", "id=".$this->DadosId); $this->Resultado= $verMarca->getResultado(); return $this->Resultado; } public function verDistr($DadosId) { $this->DadosId = $DadosId; $verDistr = new \App\adms\Models\helper\AdmsRead(); $verDistr->fullRead("select f.forn_id distr_id, f.nome_fantasia distr_nome from ro_trade_fabr_distr dm inner join ro_trade_fornecedor f on f.forn_id = dm.distr_id where dm.fabr_id = :id order by f.nome_fantasia", "id=".$this->DadosId); $this->Resultado= $verDistr->getResultado(); // var_dump($this->Resultado); return $this->Resultado; } public function altFabr(array $Dados) { $this->Dados = $Dados; if(isset($this->Dados['marcas'])){ $this->updateEditUsuario(); }else{ $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'> Erro: Nenhuma marca selecionada para o Fabricante! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span></button> </div>"; $this->Resultado = false; } } private function updateEditUsuario() { $this->DadosMarca['marcas'] = $this->Dados['marcas']; $this->DadosDistr['distr'] = $this->Dados['distr']; $this->Dados['forn_id'] = $this->Dados['fabr_id']; unset($this->Dados['marcas']); unset($this->Dados['distr']); unset($this->Dados['fabr_id']); $upAltUser = new \App\adms\Models\helper\AdmsUpdate(); $upAltUser->exeUpdate("ro_trade_fornecedor", $this->Dados, "WHERE id =:id", "id=" . $this->Dados['id']); if ($upAltUser->getResultado()) { $this->atualizaMarca(); if(!empty($this->DadosDistr)){ $this->atualizaDistr(); } $_SESSION['msg'] = "<div class='alert alert-success' role='alert'> Fabricante editado com sucesso! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span></button> </div>"; $this->Resultado = true; } else { $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'> Fabricante não foi atualizado! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span></button> </div>"; $this->Resultado = false; } } private function atualizaMarca() { $apagarMarca = new \App\adms\Models\helper\AdmsDelete(); $apagarMarca->exeDelete("ro_trade_fabr_marca", "WHERE fabr_id =:id", "id={$this->Dados['forn_id']}"); if ($apagarMarca->getResultado()) { foreach($this->DadosMarca['marcas'] as $key => $value) { $this->DadosItemMarca['marca_id'] = $key; $this->DadosItemMarca['fabr_id'] = $this->Dados['forn_id']; $verExiste = new \App\adms\Models\helper\AdmsRead(); $verExiste->fullRead("select coalesce(max(id),0) id from ro_trade_fabr_marca WHERE marca_id =:marca_id", "marca_id=" . $this->DadosItemMarca['marca_id']); $this->ExisteId = $verExiste->getResultado(); if($this->ExisteId[0]['id'] == 0){ $cadItem = new \App\adms\Models\helper\AdmsCreate; $cadItem->exeCreate("ro_trade_fabr_marca", $this->DadosItemMarca); } } } } private function atualizaDistr() { $apagarDistr = new \App\adms\Models\helper\AdmsDelete(); $apagarDistr->exeDelete("ro_trade_fabr_distr", "WHERE fabr_id =:id", "id={$this->Dados['forn_id']}"); if ($apagarDistr->getResultado()) { var_dump($this->DadosDistr['distr']); foreach($this->DadosDistr['distr'] as $key => $value) { $this->DadosItemDistr['distr_id'] = $key; $this->DadosItemDistr['fabr_id'] = $this->Dados['forn_id']; $verExiste = new \App\adms\Models\helper\AdmsRead(); $verExiste->fullRead("select coalesce(max(id),0) id from ro_trade_fabr_distr WHERE distr_id =:distr_id and fabr_id = :fabr_id", "distr_id=" . $this->DadosItemDistr['distr_id']."&fabr_id=" . $this->DadosItemDistr['fabr_id']); $this->ExisteId = $verExiste->getResultado(); //var_dump($this->DadosDistr); //var_dump($this->ExisteId[0]['id']); //var_dump($this->DadosItemDistr); //die; if($this->ExisteId[0]['id'] == 0){ $cadItem = new \App\adms\Models\helper\AdmsCreate; $cadItem->exeCreate("ro_trade_fabr_distr", $this->DadosItemDistr); } } } } public function listarCadastrar($DadosId) { $this->DadosId = $DadosId; $listar = new \App\adms\Models\helper\AdmsRead(); $listar->fullRead("select m.id marca_id, m.nome marca_nome from ro_marca m where m.id not in (select fm.marca_id from ro_trade_fabr_marca fm) order by m.nome"); $registro['marcatot'] = $listar->getResultado(); $listar->fullRead("select f.forn_id distr_id, f.nome_fantasia distr_nome from ro_trade_fornecedor f where f.tipo_forn = 'D' order by f.nome_fantasia"); $registro['distrtot'] = $listar->getResultado(); $this->Resultado = ['marcatot' => $registro['marcatot'], 'distrtot' => $registro['distrtot']]; return $this->Resultado; } }