Skip to content

Instantly share code, notes, and snippets.

View dodopok's full-sized avatar

Douglas Araujo dodopok

View GitHub Profile
@dodopok
dodopok / gist:5968754
Created July 10, 2013 18:20
Filtros - CakePHP
public function pesquisacheques(){
$this->LancamentoConta->Cheque->recursive = 2;
$this->request->data = $this->request->query;
unset($this->request->data['submit']);
$arraycerta = array();
$pi = false;
foreach($this->request->data as $key => $value){
if($key == 'valor_de' || $key == 'valor_ate'){
if(!$pi){
if(!empty($value)){
@dodopok
dodopok / gist:5884581
Created June 28, 2013 13:16
Diferença entre duas datas - PHP
<?php
function diff ($inicio, $fim, $tipo){
if (!$fim || $fim < $inicio) {
return "A data final deve ser maior que a inicial.";
} elseif ($inicio < "1970-01-01") {
return "A data final deve ser maior que 01/01/1970.";
} else {
if (strlen($inicio) > 10) {
$time_inicio = mktime(substr($inicio,-8,2),substr($inicio,-5,2),substr($inicio,-2), substr($inicio,5,2), substr($inicio,8,2), substr($inicio,0,4));
} else {
@dodopok
dodopok / gist:5859107
Created June 25, 2013 14:54
Formatar aaaa-mm-dd H:i:s para dd/mm/aaaa H:i:s - Javascript
datahora = '2013-01-02 15:12:20';
datahora = datahora.split(' ');
data = datahora[0]
hora = datahora[1]
data = data.split('-').reverse().join('/');
datahora = data+' '+hora;
@dodopok
dodopok / gist:5825259
Created June 20, 2013 18:23
Debug MySQL no controller - CakePHP
<?php
$log = $this->Model->getDataSource()->getLog(false, false);
debug($log);
?>
@dodopok
dodopok / gist:5765094
Created June 12, 2013 13:09
Salvar - CakePHP
<?php
public function add() {
if ($this->request->is('post')) {
$this->Tabela->create();
if ($this->Tabela->save($this->request->data)) {
$this->Session->setFlash(__('A Tabela foi cadastrada.'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('A Tabela não pôde ser cadastrada. Favor tentar novamente.'));
}
@dodopok
dodopok / gist:5764967
Created June 12, 2013 12:50
Find and Replace - Linux
find . -name *.* -type f | xargs sed -i s/"extends ppController"/"extends VendasAppController"/ *
@dodopok
dodopok / gist:5757226
Created June 11, 2013 14:20
Valores decimais MySQL
You need DECIMAL(4, 2) by the looks of things. DECIMAL(2, 2) only allows a range of -0.99 to 0.99
@dodopok
dodopok / gist:5722985
Created June 6, 2013 16:45
FormHelper - CakePHP
<?php echo $this->Form->create('Veiculo'); ?>
<fieldset>
<legend><?php echo __('Novo Veículo'); ?></legend>
<?php
echo $this->Form->input('user_id', array('type' => 'hidden', 'value' => $this->Session->read('Auth.User.id')));
echo $this->Form->input('group_id', array('type' => 'hidden', 'value' => $this->Session->read('choosed')));
echo $this->Form->input('veiculo', array('size' => '150', 'label' => 'Veículo'));
echo $this->Form->input('placa');
echo $this->Form->input('rntc', array('size' => '20', 'label' => 'RNTC'));
echo $this->Form->input('antt', array('size' => '20', 'label' => 'Código ANTT'));
@dodopok
dodopok / gist:5721754
Created June 6, 2013 14:05
JSON - PHP/JQUERY
$.ajax({
// url para o arquivo json.php
url : "json.php",
// dataType json
dataType : "json",
// função para de sucesso
success : function(data){
// vamos gerar um html e guardar nesta variável
var html = "";
@dodopok
dodopok / gist:5510759
Created May 3, 2013 16:31
getEndereco()
function getEndereco(cep,i) {
if(cep !== ""){
$.getScript("https://www.nfservice.com.br/sistema/vendas/clientefornecedor/cep/"+cep, function(){
if (resultadoCEP["resultado"]) {
$("#Endereco"+i+"Logradouro").val(unescape(resultadoCEP["tipo_logradouro"]) + " " + unescape(resultadoCEP["logradouro"]));
$("#Endereco"+i+"Bairro").val(unescape(resultadoCEP["bairro"]));
$("#Endereco"+i+"Cidade").val(unescape(resultadoCEP["cidade"]));
var arg =unescape(resultadoCEP["uf"]);
$("#Endereco"+i+"Uf > option").each(function(){
if($(this).text()==arg) $(this).parent("select").val($(this).val())