Help with business map - rslemer - 09-26-2019
I created a function for use in business map
But I don't know how I get the recordID for edition for my SQL commands
In my research I think I need get a array $entity and in this there many fields, include the recordID
But how I ask a coreBOS to pass this variable for my routine?
RE: Help with business map - joebordes - 09-28-2019
I would recommend you create a github account, fork the project, create a branch and upload your code there, that way we will be able to see what you are doing and help
RE: Help with business map - rslemer - 09-28-2019
PHP Code:
<?php
/************************************************************************************************* * Copyright 2017 JPL TSolucio, S.L. -- This file is a part of TSOLUCIO coreBOS Customizations. * Licensed under the vtiger CRM Public License Version 1.1 (the "License"); you may not use this * file except in compliance with the License. You can redistribute it and/or modify it * under the terms of the License. JPL TSolucio, S.L. reserves all rights not expressly * granted by the License. coreBOS distributed by JPL TSolucio S.L. is distributed in * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Unless required by * applicable law or agreed to in writing, software distributed under the License is * distributed on an "AS IS" BASIS, WITHOUT ANY WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing * permissions and limitations under the License. You may obtain a copy of the License * at <http://corebos.org/documentation/doku.php?id=en:devel:vpl11> *************************************************************************************************/ function validaCPF($field, $cpf = null, $entity ) {
global $adb,$log;
$log->debug("valida_CPF $field - $cpf"); $contato_id = $entity['recordid'];
$log->debug("valida_CPF entity = $entity"); $log->debug("valida_CPF contato_id = $contato_id");
// Verifica se um número foi informado if (empty($cpf)) { return false; }
// Elimina possivel mascara $cpf = preg_replace('/[^0-9]/', '', $cpf); $cpf = str_pad($cpf, 11, '0', STR_PAD_LEFT);
// Verifica se o numero de digitos informados é igual a 11 if (strlen($cpf) != 11) { return false; } elseif ($cpf == '00000000000' || $cpf == '11111111111' || $cpf == '22222222222' || $cpf == '33333333333' || $cpf == '44444444444' || $cpf == '55555555555' || $cpf == '66666666666' || $cpf == '77777777777' || $cpf == '88888888888' || $cpf == '99999999999') { // Verifica se nenhuma das sequências invalidas abaixo // foi digitada. Caso afirmativo, retorna falso return false; // Calcula os digitos verificadores para verificar se o // CPF é válido } else { for ($t = 9; $t < 11; $t ++) { for ($d = 0, $c = 0; $c < $t; $c ++) { $d += $cpf {$c} * (($t + 1) - $c); } $d = ((10 * $d) % 11) % 10; if ($cpf {$c} != $d) { return false; } } // Inclui maskara $mask = "###.###.###-##";
$cpf = str_replace(" ","",$cpf);
for($i=0;$i<strlen($cpf);$i++){ $mask[strpos($mask,"#")] = $cpf[$i]; } $cpf = $mask;
$cpf="064.783.558-45"; $log->debug("valida_CPF O CPF e Valido - $cpf"); $adb->pquery("UPDATE vtiger_contactscf SET $field =? WHERE contactid=?",array($cpf,$contato_id)); return true; } }
function validaCNPJ($field, $cnpj) { $cnpj = preg_replace('/[^0-9]/', '', (string) $cnpj); // Valida tamanho if (strlen($cnpj) != 14) { // CNPJ incorrect length return false; } // Valida primeiro dígito verificador for ($i = 0, $j = 5, $soma = 0; $i < 12; $i++) { $soma += $cnpj{$i} * $j; $j = ($j == 2) ? 9 : $j - 1; } $resto = $soma % 11; if ($cnpj{12} != ($resto < 2 ? 0 : 11 - $resto)) { // CNPJ incorrect char 12 return false; } // Valida segundo dígito verificador for ($i = 0, $j = 6, $soma = 0; $i < 13; $i++) { $soma += $cnpj{$i} * $j; $j = ($j == 2) ? 9 : $j - 1; } $resto = $soma % 11; return $cnpj{13} == ($resto < 2 ? 0 : 11 - $resto); }
function validaCNPJ2($field, $cnpj) { $c = preg_replace('/\D/', '', $cnpj); if (strlen($c) != 14 || preg_match("/^{$c[0]}{14}$/", $c)) { // CNPJ2 incorrect length return false; } $b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; for ($i = 0, $n = 0; $i < 12; $n += $c[$i] * $b[++$i]) { } if ($c[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { // CNPJ2 incorrect char 12 return false; } for ($i = 0, $n = 0; $i <= 12; $n += $c[$i] * $b[$i++]) { } if ($c[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { // CNPJ2 incorrect char 13 return false; } return true; }
I copy some parts of code from this example
https://discussions.corebos.org/showthread.php?tid=1432
But how I ask a coreBOS to pass the same parameters to my function?
RE: Help with business map - joebordes - 09-28-2019
a quick look at the other existing validation functions leads me to believe that the parameters are "just there", the one you are looking for is not a workflow entity object, I'd say it is just an array of fields, like this:
field triggering the validation, value to be validated, array with the other parameters in map, array of all the other fields
but to make sure log them to the log file:
function validaCPF($field, $cpf, $params, $fields) {
global $log;
$log->fatal($field);
$log->fatal($cpf);
$log->fatal($params);
$log->fatal($fields);
...
RE: Help with business map - rslemer - 09-29-2019
But I think I need inform a cioreBOS to pass new parameter "entity" or "recordid" in my bussiness map? right
how I did that? I don't now this explanation in documentation
Today my bussiness map is
<map>
<originmodule>
<originname>Contacts</originname>
</originmodule>
<fields>
<field>
<fieldname>cf_1159</fieldname>
</field>
<validations>
<validation>
<rule>custom</rule>
<restrictions>
<restriction>include/validation/validateCPFCNPJ.php</restriction>
<restriction>testcpf</restriction>
<restriction>validaCPF</restriction>
<restriction>Número do CPF/CNPJ inválido</restriction>
</restrictions>
</validation>
</validations>
</fields>
</map>
Variables
$field returned a cf_1159
$cpf returns a value input in cf_1159
But recorid returned a blank field
RE: Help with business map - joebordes - 09-29-2019
I don't think you have to do anything: put all four variables and dump them to see what you get, you will probably see the id field in the forth parameter
function validaCPF($field, $cpf, $params, $fields) {
global $log;
$log->fatal($field);
$log->fatal($cpf);
$log->fatal($params);
$log->fatal($fields);
...
RE: Help with business map - rslemer - 09-29-2019
index is $entity['recordid'] ?
because in log returned blank for me ...
I tried user a log to printed all index in this array, but not is possible shows in screen. I think is because is a background process right?
But there are a way to printed that, in log?
RE: Help with business map - rslemer - 09-30-2019
Not working for me
my function only receives two fields, a cf_name and your contents
other two fields in log is blanked ( empty )
I don't know how I need changed a business map to receives another two fields ( I think that's is a problem ... )
RE: Help with business map - rslemer - 09-30-2019
Someone has a business map for use a checkAccountPIVA ?
I think is the same I need made for my function too
(09-29-2019, 03:52 PM)rslemer Wrote: index is $entity['recordid'] ?
because in log returned blank for me ...
I tried user a log to printed all index in this array, but not is possible shows in screen. I think is because is a background process right?
But there are a way to printed that, in log?
correct is current_record_id ....
(09-29-2019, 03:52 PM)rslemer Wrote: index is $entity['recordid'] ?
because in log returned blank for me ...
I tried user a log to printed all index in this array, but not is possible shows in screen. I think is because is a background process right?
But there are a way to printed that, in log?
$name = 'arquivo.txt';
$text = var_export($_POST, true);
$file = fopen($name, 'a');
fwrite($file, $text);
fclose($file);
RE: Help with business map - rslemer - 09-30-2019
PHP Code:
<?php /************************************************************************************************* * Copyright 2017 JPL TSolucio, S.L. -- This file is a part of TSOLUCIO coreBOS Customizations. * Licensed under the vtiger CRM Public License Version 1.1 (the "License"); you may not use this * file except in compliance with the License. You can redistribute it and/or modify it * under the terms of the License. JPL TSolucio, S.L. reserves all rights not expressly * granted by the License. coreBOS distributed by JPL TSolucio S.L. is distributed in * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Unless required by * applicable law or agreed to in writing, software distributed under the License is * distributed on an "AS IS" BASIS, WITHOUT ANY WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing * permissions and limitations under the License. You may obtain a copy of the License * at <http://corebos.org/documentation/doku.php?id=en:devel:vpl11> *************************************************************************************************/ function validaCPF($field, $cpf, $params, $entity) { // Verifica se um número foi informado if (empty($cpf)) { return false; }
global $db, $adb, $log;
$contato_id = $entity['current_record_id'];
$log->debug(" validaCPF - contato_id $contato_id"); /* $log->debug(" validaCPF - params $params"); $log->debug(" validaCPF - cpf $cpf"); $name = 'arquivo.txt'; $text = var_export($entity, true); $file = fopen($name, 'a'); fwrite($file, $text); fclose($file); */ // Elimina possivel mascara $cpf = preg_replace('/[^0-9]/', '', $cpf); $cpf = str_pad($cpf, 11, '0', STR_PAD_LEFT);
// Verifica se o numero de digitos informados é igual a 11 if (strlen($cpf) != 11) { return false; } elseif ($cpf == '00000000000' || $cpf == '11111111111' || $cpf == '22222222222' || $cpf == '33333333333' || $cpf == '44444444444' || $cpf == '55555555555' || $cpf == '66666666666' || $cpf == '77777777777' || $cpf == '88888888888' || $cpf == '99999999999') { // Verifica se nenhuma das sequências invalidas abaixo // foi digitada. Caso afirmativo, retorna falso return false; // Calcula os digitos verificadores para verificar se o // CPF é válido } else { for ($t = 9; $t < 11; $t ++) { for ($d = 0, $c = 0; $c < $t; $c ++) { $d += $cpf {$c} * (($t + 1) - $c); } $d = ((10 * $d) % 11) % 10; if ($cpf {$c} != $d) { return false; } } $mask = "###.###.###-##";
$cpf = str_replace(" ","",$cpf);
for($i=0;$i<strlen($cpf);$i++){ $mask[strpos($mask,"#")] = $cpf[$i]; } $cpf = $mask;
$log->debug(" validaCPF - cpf com mascara $cpf"); $adb->pquery("update vtiger_contactscf set $field =? where contactid=?",array($cpf,$contato_id)); return true; } }
function validaCNPJ($field, $cnpj) { $cnpj = preg_replace('/[^0-9]/', '', (string) $cnpj); // Valida tamanho if (strlen($cnpj) != 14) { // CNPJ incorrect length return false; } // Valida primeiro dígito verificador for ($i = 0, $j = 5, $soma = 0; $i < 12; $i++) { $soma += $cnpj{$i} * $j; $j = ($j == 2) ? 9 : $j - 1; } $resto = $soma % 11; if ($cnpj{12} != ($resto < 2 ? 0 : 11 - $resto)) { // CNPJ incorrect char 12 return false; } // Valida segundo dígito verificador for ($i = 0, $j = 6, $soma = 0; $i < 13; $i++) { $soma += $cnpj{$i} * $j; $j = ($j == 2) ? 9 : $j - 1; } $resto = $soma % 11; return $cnpj{13} == ($resto < 2 ? 0 : 11 - $resto); }
function validaCNPJ2($field, $cnpj) { $c = preg_replace('/\D/', '', $cnpj); if (strlen($c) != 14 || preg_match("/^{$c[0]}{14}$/", $c)) { // CNPJ2 incorrect length return false; } $b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; for ($i = 0, $n = 0; $i < 12; $n += $c[$i] * $b[++$i]) { } if ($c[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { // CNPJ2 incorrect char 12 return false; } for ($i = 0, $n = 0; $i <= 12; $n += $c[$i] * $b[$i++]) { } if ($c[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { // CNPJ2 incorrect char 13 return false; } return true; }
New code is
but not working, yet ...
$adb->pquery("update vtiger_contactscf set $field =? where contactid=?",array($cpf,$contato_id));
Is necessary any other command ?
=(
|