Skip to content

Commit

Permalink
feature/pix qr code (#1234)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr3d4dor authored Feb 12, 2021
1 parent 5f659d9 commit e4c766b
Show file tree
Hide file tree
Showing 32 changed files with 803 additions and 422 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ Todas as alterações serão documentadas neste arquivo
Formato baseado em [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
e [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.31.0] - 2021-02-11

### Added
- Implementado QR Code de PIX para pagamento de os e venda em imprimirOs e imprimirVenda. [@Pr3d4dor](https://github.com/Pr3d4dor)

### Changed
- Melhorado imprimir os e venda. [@Flexotron20](https://github.com/Flexotron20)

### Fixed
- Colocado "*" para mostrar que campos ao criar lançamento financeiro são obrigatórios. [@cleytonasa](https://github.com/cleytonasa)
- Adicionado método de pagamento "PIX" nos lugares faltantes. [@Pr3d4dor](https://github.com/Pr3d4dor)

## [4.30.3] - 2021-02-07

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

![MapOS](https://raw.githubusercontent.com/RamonSilva20/mapos/master/assets/img/logo.png)

![version](https://img.shields.io/badge/version-4.30.3-blue.svg?longCache=true&style=flat-square)
![version](https://img.shields.io/badge/version-4.31.0-blue.svg?longCache=true&style=flat-square)
![license](https://img.shields.io/badge/license-MIT-green.svg?longCache=true&style=flat-square)
![theme](https://img.shields.io/badge/theme-Matrix--Admin-lightgrey.svg?longCache=true&style=flat-square)
![issues](https://img.shields.io/github/issues/RamonSilva20/mapos.svg?longCache=true&style=flat-square)
Expand Down
2 changes: 1 addition & 1 deletion application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* App current version
*/
$config['app_version'] = '4.30.3';
$config['app_version'] = '4.31.0';

/**
* Nome do sistema
Expand Down
4 changes: 4 additions & 0 deletions application/controllers/Mapos.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ public function configurar()
$this->form_validation->set_rules('control_baixa', 'Controle de Baixa', 'required|trim');
$this->form_validation->set_rules('control_editos', 'Controle de Edição de OS', 'required|trim');
$this->form_validation->set_rules('control_datatable', 'Controle de Visualização em DataTables', 'required|trim');
$this->form_validation->set_rules('pix_key', 'Chave Pix', 'trim|valid_pix_key', [
'valid_pix_key' => 'Chave Pix inválida!',
]);

if ($this->form_validation->run() == false) {
$this->data['custom_error'] = (validation_errors() ? '<div class="alert">' . validation_errors() . '</div>' : false);
Expand All @@ -359,6 +362,7 @@ public function configurar()
'control_baixa' => $this->input->post('control_baixa'),
'control_editos' => $this->input->post('control_editos'),
'control_datatable' => $this->input->post('control_datatable'),
'pix_key' => $this->input->post('pix_key'),
];
if ($this->mapos_model->saveConfiguracao($data) == true) {
$this->session->set_flashdata('success', 'Configurações do sistema atualizadas com sucesso!');
Expand Down
7 changes: 6 additions & 1 deletion application/controllers/Os.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ public function imprimir()
$this->data['produtos'] = $this->os_model->getProdutos($this->uri->segment(3));
$this->data['servicos'] = $this->os_model->getServicos($this->uri->segment(3));
$this->data['emitente'] = $this->mapos_model->getEmitente();
$this->data['qrCode'] = $this->os_model->getQrCode(
$this->uri->segment(3),
$this->data['configuration']['pix_key'],
$this->data['emitente'][0]
);

$this->load->view('os/imprimirOs', $this->data);
}
Expand Down Expand Up @@ -440,7 +445,7 @@ public function enviar_email()
redirect(site_url('os/visualizar/').$this->uri->segment(3));
}
}

$enviouEmail = $this->enviarOsPorEmail($idOs, $remetentes, 'Ordem de Serviço');

if ($enviouEmail) {
Expand Down
5 changes: 5 additions & 0 deletions application/controllers/Vendas.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ public function imprimir()
$this->data['result'] = $this->vendas_model->getById($this->uri->segment(3));
$this->data['produtos'] = $this->vendas_model->getProdutos($this->uri->segment(3));
$this->data['emitente'] = $this->mapos_model->getEmitente();
$this->data['qrCode'] = $this->vendas_model->getQrCode(
$this->uri->segment(3),
$this->data['configuration']['pix_key'],
$this->data['emitente'][0]
);

$this->load->view('vendas/imprimirVenda', $this->data);
}
Expand Down
1 change: 1 addition & 0 deletions application/core/MY_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MY_Controller extends CI_Controller
'control_baixa' => '0',
'control_editos' => '1',
'control_datatable' => '1',
'pix_key' => '',
],
];

Expand Down
15 changes: 15 additions & 0 deletions application/database/migrations/20210125173738_add_pix_key.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class Migration_add_pix_key extends CI_Migration
{
public function up()
{
$sql = "INSERT INTO `configuracoes` (`idConfig`, `config`, `valor`) VALUES (11, 'pix_key', '')";
$this->db->query($sql);
}

public function down()
{
$this->db->query("DELETE FROM `configuracoes` WHERE `configuracoes`.`idConfig` = 11");
}
}
5 changes: 5 additions & 0 deletions application/database/seeds/Configuracoes.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public function run()
'config' => 'control_datatable',
'valor' => '1',
],
[
'idConfig' => 11,
'config' => 'pix_key',
'valor' => '',
],
];

foreach ($configs as $config) {
Expand Down
25 changes: 25 additions & 0 deletions application/helpers/general_helper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Piggly\Pix\Parser;

if (!function_exists('convertUrlToUploadsPath')) {
function convertUrlToUploadsPath($url)
{
Expand Down Expand Up @@ -43,3 +45,26 @@ function getCobrancaTransactionStatus($paymentGatewaysConfig, $paymentGateway, $
return $paymentGatewaysConfig[$paymentGateway]['transaction_status'][$status];
}
}

if (!function_exists('getPixKeyType')) {
function getPixKeyType($value)
{
if (Parser::validateDocument($value)) {
return Parser::KEY_TYPE_DOCUMENT;
}

if (Parser::validateEmail($value)) {
return Parser::KEY_TYPE_EMAIL;
}

if (Parser::validatePhone($value)) {
return Parser::KEY_TYPE_PHONE;
}

if (Parser::validateRandom($value)) {
return Parser::KEY_TYPE_RANDOM;
}

return null;
}
}
25 changes: 25 additions & 0 deletions application/helpers/validation_helper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Piggly\Pix\Parser;

if (!function_exists('multiplica_cnpj')) {
function multiplica_cnpj($cnpj, $posicao = 5)
{
Expand Down Expand Up @@ -133,3 +135,26 @@ function unique($value, $params)
}
}
}

if (!function_exists('valid_pix_key')) {
function valid_pix_key($value)
{
if (Parser::validateDocument($value)) {
return true;
}

if (Parser::validateEmail($value)) {
return true;
}

if (Parser::validatePhone($value)) {
return true;
}

if (Parser::validateRandom($value)) {
return true;
}

return false;
}
}
8 changes: 3 additions & 5 deletions application/libraries/Gateways/BasePaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public function findEntity($id, $tipo)
}
}

public function errosCadastro($entity = null)
public function errosCadastro($entity = null)
{
if($entity == null) {

if ($entity == null) {
return null;
}
$error_list = "Por favor preencher os seguintes dados do(a) seu(ua) cliente!\n\n";
Expand All @@ -52,8 +51,7 @@ public function errosCadastro($entity = null)
}
}
}
if(!$check) {

if (!$check) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions application/libraries/Gateways/GerencianetSdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function ($total, $item) {
throw new \Exception('OS ou venda com valor negativo ou zero!');
}

if($err = $this->errosCadastro($entity)) {
if ($err = $this->errosCadastro($entity)) {
throw new \Exception($err);
}

Expand Down Expand Up @@ -301,7 +301,7 @@ function ($total, $item) {
throw new \Exception('OS ou venda com valor negativo ou zero!');
}

if($err = $this->errosCadastro($entity)) {
if ($err = $this->errosCadastro($entity)) {
throw new \Exception($err);
}

Expand Down
2 changes: 1 addition & 1 deletion application/libraries/Gateways/MercadoPago.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function ($total, $item) {
throw new \Exception('OS ou venda com valor negativo ou zero!');
}

if($err = $this->errosCadastro($entity)) {
if ($err = $this->errosCadastro($entity)) {
throw new \Exception($err);
}

Expand Down
30 changes: 30 additions & 0 deletions application/models/Os_model.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Piggly\Pix\Payload;

class Os_model extends CI_Model
{

Expand Down Expand Up @@ -343,4 +345,32 @@ public function isEditable($id = null)
}
return true;
}

public function getQrCode($id, $pixKey, $emitente)
{
if (empty($id) || empty($pixKey) || empty($emitente)) {
return;
}

$result = $this->valorTotalOS($id);
$amount = round(floatval($result['totalServico'] + $result['totalProdutos']), 2);

if ($amount <= 0) {
return;
}

$pix = (new Payload())
->applyValidCharacters()
->applyUppercase()
->applyEmailWhitespace()
->setPixKey(getPixKeyType($pixKey), $pixKey)
->setMerchantName($emitente->nome)
->setMerchantCity($emitente->cidade)
->setAmount($amount)
->setTid($id)
->setDescription(sprintf("%s - Pagamento - OS %s", $emitente->nome, $id))
->setAsReusable(false);

return $pix->getQRCode();
}
}
Loading

0 comments on commit e4c766b

Please sign in to comment.