diff --git a/vendor/model/ProductsCompanies.class.php b/vendor/model/ProductsCompanies.class.php index 926580a..bc6abff 100644 --- a/vendor/model/ProductsCompanies.class.php +++ b/vendor/model/ProductsCompanies.class.php @@ -197,7 +197,7 @@ class ProductsCompanies c.contract_type, c.contract_date, cp.maturity, - (select cp.maturity from client_products cp where cp.company_id = c.company_id limit 0, 1) as due_date + (select cp.maturity from products_companies cp where cp.company_id = c.company_id limit 0, 1) as due_date from companies c left join products_companies pc on c.company_id = pc.company_id where cp.readjustment = :readjustment @@ -230,7 +230,7 @@ class ProductsCompanies /** Consulta SQL */ $this->sql = 'select count(client_product_id) as qtde - from client_products where company_id = :company_id '; + from products_companies where company_id = :company_id '; /** Preparo o SQL para execução */ $this->stmt = $this->connection->connect()->prepare($this->sql); @@ -268,7 +268,7 @@ class ProductsCompanies if($this->clientProductId > 0){ /** Consulta SQL */ - $this->sql = 'update client_products set products_id = :products_id, + $this->sql = 'update products_companies set products_id = :products_id, date_contract = :date_contract, date_update = CURRENT_TIMESTAMP, user_id_update = :user_id_update, @@ -281,7 +281,7 @@ class ProductsCompanies }else{//Se o ID não foi informado, grava-se um novo registro /** Consulta SQL */ - $this->sql = 'insert into client_products(client_product_id, + $this->sql = 'insert into products_companies(client_product_id, company_id, products_id, user_id_create, @@ -337,7 +337,7 @@ class ProductsCompanies $this->usersIdDelete = $_SESSION['USERSID'];//Carrega o ID do usuário logado /** Consulta SQL */ - $this->sql = 'update client_products set status = \'E\', + $this->sql = 'update products_companies set status = \'E\', date_delete = CURRENT_TIMESTAMP, user_id_delete = :user_id_delete where client_product_id = :client_product_id'; @@ -364,7 +364,7 @@ class ProductsCompanies $this->productValue = $productValue; /** Consulta SQL */ - $this->sql = 'update client_products set product_value = :product_value + $this->sql = 'update products_companies set product_value = :product_value where company_id = :company_id and products_id = :products_id'; diff --git a/vendor/model/ProductsCompanies.php b/vendor/model/ProductsCompanies.php deleted file mode 100644 index 926580a..0000000 --- a/vendor/model/ProductsCompanies.php +++ /dev/null @@ -1,389 +0,0 @@ -connection = new Mysql(); - } - - /** Carrega os campos de uma tabela */ - public function Describe() - { - - /** Consulta SQL */ - $this->sql = "describe products_companies"; - - /** Preparo o SQL para execução */ - $this->stmt = $this->connection->connect()->prepare($this->sql); - - /** Executo o SQL */ - $this->stmt->execute(); - - /** Retorno o resultado */ - $this->field = $this->stmt->fetchAll(\PDO::FETCH_OBJ); - - /** Declara o objeto */ - $resultDescribe = new \stdClass(); - $Field = ''; - - /** Lista os campos da tabela para objetos */ - foreach($this->field as $UsersKey => $Result){ - - /** Pega o nome do Field/Campo */ - $Field = $Result->Field; - - /** Carrega os objetos como null */ - $resultDescribe->$Field = null; - - } - - /** Retorna os campos declarados como vazios */ - return $resultDescribe; - - } - - /** Lista os registros do banco de dados com limitação */ - public function Get(int $clientProductId) - { - - /** Parametros de entrada */ - $this->clientProductId = $clientProductId; - - /** Consulta SQL */ - $this->sql = 'select * from products_companies - where client_product_id = :client_product_id'; - - /** Preparo o SQL para execução */ - $this->stmt = $this->connection->connect()->prepare($this->sql); - - /** Preencho os parâmetros do SQL */ - $this->stmt->bindParam(':client_product_id', $this->clientProductId); - - /** Executo o SQL */ - $this->stmt->execute(); - - /** Retorno o resultado */ - return $this->stmt->fetchObject(); - - } - - /** Lista todos os egistros do banco com ou sem paginação*/ - public function All(int $clientsId) - { - /** Parametros de entrada */ - $this->clientsId = $clientsId; - - /** Consulta SQL */ - $this->sql = 'select cp.client_product_id, - cp.products_id, - cp.company_id, - cp.description, - p.description as product, - p.reference, - cp.readjustment, - cp.product_value, - cp.maturity - from products_companies cp - left join products p on cp.products_id = p.products_id - where cp.company_id = :company_id - and cp.status = \'A\''; - - /** Preparo o SQL para execução */ - $this->stmt = $this->connection->connect()->prepare($this->sql); - - /** Preencho os parâmetros do SQL */ - $this->stmt->bindParam(':company_id', $this->clientsId); - - /** Executo o SQL */ - $this->stmt->execute(); - - /** Retorno o resultado */ - return $this->stmt->fetchAll(\PDO::FETCH_OBJ); - - } - - /** Lista todos os egistros do banco com ou sem paginação*/ - public function Readjustment(string $readjustment) - { - /** Parametros de entrada */ - $this->readjustment = $readjustment; - - /** Lista de meses do ano */ - $this->month = ['janeiro' => '01', - 'fevereiro' => '02', - 'março' => '03', - 'abril' => '04', - 'maio' => '05', - 'junho' => '06', - 'julho' => '07', - 'agosto' => '08', - 'setembro' => '09', - 'outubro' => '10', - 'novembro' => '11', - 'dezembro' => '12' - ]; - - /** Prepara a data de consulta */ - $this->dateStart = date('Y').'-'.$this->month[$this->readjustment].'-01'; - $this->dateEnd = (date('Y')+1).'-'.$this->month[$this->readjustment].'-01'; - - /** Consulta SQL */ - $this->sql = 'select distinct(c.company_id), - c.user_id, - c.company_id, - c.reference, - c.client_name, - c.fantasy_name, - c.document, - c.zip_code, - c.adress, - c.number, - c.complement, - c.district, - c.city, - c.state, - c.state_initials, - c.country, - c.date_register, - c.responsible, - c.active, - c.type, - c.student, - c.email, - c.contract_type, - c.contract_date, - cp.maturity, - (select cp.maturity from client_products cp where cp.company_id = c.company_id limit 0, 1) as due_date - from companies c - left join products_companies pc on c.company_id = pc.company_id - where cp.readjustment = :readjustment - and (select count(fm.financial_movements_id) - from financial_movements fm - where fm.movement_date_scheduled between \''.$this->dateStart.'\' and \''.$this->dateEnd.'\' - and fm.company_id = c.company_id) = 0 - order by cp.maturity asc'; - - /** Preparo o SQL para execução */ - $this->stmt = $this->connection->connect()->prepare($this->sql); - - /** Preencho os parâmetros do SQL */ - $this->stmt->bindParam(':readjustment', $this->readjustment); - - /** Executo o SQL */ - $this->stmt->execute(); - - /** Retorno o resultado */ - return $this->stmt->fetchAll(\PDO::FETCH_OBJ); - - } - - /** Conta a quantidades de registros */ - public function Count(int $clientsId) - { - - /** Parametros de entrada */ - $this->clientsId = $clientsId; - - /** Consulta SQL */ - $this->sql = 'select count(client_product_id) as qtde - from client_products where company_id = :company_id '; - - /** Preparo o SQL para execução */ - $this->stmt = $this->connection->connect()->prepare($this->sql); - - /** Preencho os parâmetros do SQL */ - $this->stmt->bindParam(':company_id', $this->clientsId); - - /** Executo o SQL */ - $this->stmt->execute(); - - /** Retorno o resultado */ - return $this->stmt->fetchObject()->qtde; - - } - - /** Insere um novo registro no banco */ - public function Save(int $clientProductId, int $clientsId, int $productsId, ? string $dateContract, string $description, string $readjustment, ? float $productValue, int $maturity) - { - - - /** Parametros */ - $this->clientProductId = $clientProductId; - $this->clientsId = $clientsId; - $this->productsId = $productsId; - $this->dateContract = $dateContract; - $this->usersIdCreate = $_SESSION['USERSID'];//Carrega o ID do usuário logado - $this->usersIdUpdate = $_SESSION['USERSID'];//Carrega o ID do usuário logado - $this->description = $description; - $this->readjustment = $readjustment; - $this->productValue = $productValue; - $this->maturity = $maturity; - - - /** Verifica se o ID do registro foi informado */ - if($this->clientProductId > 0){ - - /** Consulta SQL */ - $this->sql = 'update client_products set products_id = :products_id, - date_contract = :date_contract, - date_update = CURRENT_TIMESTAMP, - user_id_update = :user_id_update, - description = :description, - readjustment = :readjustment, - product_value = :product_value, - maturity = :maturity - where client_product_id = :client_product_id'; - - }else{//Se o ID não foi informado, grava-se um novo registro - - /** Consulta SQL */ - $this->sql = 'insert into client_products(client_product_id, - company_id, - products_id, - user_id_create, - date_contract, - description, - readjustment, - product_value, - maturity - ) values (:client_product_id, - :company_id, - :products_id, - :user_id_create, - :date_contract, - :description, - :readjustment, - :product_value, - :maturity)'; - - } - - /** Preparo o sql para receber os valores */ - $this->stmt = $this->connection->connect()->prepare($this->sql); - - /** Preencho os parâmetros do SQL */ - $this->stmt->bindParam('client_product_id', $this->clientProductId); - $this->stmt->bindParam('products_id', $this->productsId); - $this->stmt->bindParam('date_contract', $this->dateContract); - $this->stmt->bindParam('description', $this->description); - $this->stmt->bindParam('readjustment', $this->readjustment); - $this->stmt->bindParam('product_value', $this->productValue); - $this->stmt->bindParam('maturity', $this->maturity); - - if($this->clientProductId > 0){ - - $this->stmt->bindParam('user_id_update', $this->usersIdUpdate); - - }else{ - - $this->stmt->bindParam('user_id_create', $this->usersIdCreate); - $this->stmt->bindParam('company_id', $this->clientsId); - } - - /** Executo o SQL */ - return $this->stmt->execute(); - - } - - /** Deleta um determinado registro no banco de dados */ - function Delete(int $clientProductId) - { - /** Parametros de entrada */ - $this->clientProductId = $clientProductId; - $this->usersIdDelete = $_SESSION['USERSID'];//Carrega o ID do usuário logado - - /** Consulta SQL */ - $this->sql = 'update client_products set status = \'E\', - date_delete = CURRENT_TIMESTAMP, - user_id_delete = :user_id_delete - where client_product_id = :client_product_id'; - - /** Preparo o sql para receber os valores */ - $this->stmt = $this->connection->connect()->prepare($this->sql); - - /** Preencho os parâmetros do SQL */ - $this->stmt->bindParam('client_product_id', $this->clientProductId); - $this->stmt->bindParam('user_id_delete', $this->usersIdDelete); - - /** Executo o SQL */ - return $this->stmt->execute(); - - } - - /** Atualiza o valor do produto */ - public function UpdateValueProduct(int $clientsId, int $productsId, float $productValue) - { - - /** Parametros de entrada */ - $this->clientsId = $clientsId; - $this->productsId = $productsId; - $this->productValue = $productValue; - - /** Consulta SQL */ - $this->sql = 'update client_products set product_value = :product_value - where company_id = :company_id - and products_id = :products_id'; - - /** Preparo o sql para receber os valores */ - $this->stmt = $this->connection->connect()->prepare($this->sql); - - /** Preencho os parâmetros do SQL */ - $this->stmt->bindParam('company_id', $this->clientsId); - $this->stmt->bindParam('products_id', $this->productsId); - $this->stmt->bindParam('product_value', $this->productValue); - - /** Executo o SQL */ - return $this->stmt->execute(); - - } - - /** Fecha uma conexão aberta anteriormente com o banco de dados */ - function __destruct() - { - $this->connection = null; - } -}