SuiteCRM invoice and ticket number - suitecrm

how can I make an unique number for invoice and ticketing system, something like
for tickets: ST-{yymm}-0000001
for Invoice: IN-{yymm}-0000001
Thank you

I recomend you create first a field that will be use to generate the code.
Once you have the field you have different options.
1- Assign that column in the database directly as autonumeric
2- Use a Logic Hook before_save that will be calculating the code in each save. For example:
<?php
//prevents directly accessing this file from a web browser
if(!defined('sugarEntry') ||!sugarEntry) die('Not A Valid Entry Point');
class CrearCodigoAutonumerico
{
public function CrearCodigoAutonumerico(&$bean, $event, $arguments)
{
// Si el campo está vacío...
if(empty($bean->codigo_c)) {
// Obtener el último código asignado
$db = DBManagerFactory::getInstance();
$query = "SELECT codigo_c
FROM <table_module>
ORDER BY codigo_c DESC LIMIT 1";
$result = $db->getOne($query, true);
$ultimo_codigo = $result;
// Calcular y asignar el nuevo código
$bean->codigo_c = $ultimo_codigo + 1;
}
}
}
Once you have this, you can create one more Logic Hook before save that constructs the name as you need it.

Related

How to disable inference in hermiT

I am using OWL-Api and hermiT reasoner, while trying to retrieve the partOf subClasses using hermiT, it give back the right result, so the partOf subclasses, but it also give back the inferenced subclasses (which i don't need).
This is the function used to retrieve the partOf subClasses:
//ricerca delle classi che hanno come parti quella attuale
System.out.println("Questa classe è parte di: ");
OWLClassExpression domain = df.getOWLObjectIntersectionOf((Stream<? extends OWLClassExpression>) ontologia.objectPropertyDomainAxioms(partOf));
NodeSet<OWLClass> subClassesInDomain = hermit.getSubClasses(domain, false);
if(subClassesInDomain.isEmpty()) {
System.out.println("\tQuesta classe non è parte di nessun'altra");
}
else {
for(Node<OWLClass> parteDi : subClassesInDomain) {
OWLClass classe2 = parteDi.getRepresentativeElement();
System.out.println("\t"+ classe2.getIRI().getFragment());;
}
}
In this image, it is provided the actual result of the operation.
given result
In this, it is shown the result i need.
wanted result
Is there a way to disable hermiT inference engine only for this operation?
hermit.getSubClasses(domain, false);
Change this to
hermit.getSubClasses(domain, true);
To retrieve only direct subclasses.

POWERSHELL tooltip on mousehover listbox item

I do a Powershell GUI, i want to use a tooltip on a listbox,
but i'm not familiar with events and event handlers, i don't find help for powershell/winform event on Microsoft.com
Below my listbox is $listbox_groupe_import
#Infobulle au survol pour voir les tables d'un groupe de table
$obj_infobulle = New-Object System.Windows.Forms.ToolTip
$obj_infobulle.InitialDelay = 100
$obj_infobulle.ReshowDelay = 100
#Sélectionne tous les groupes de tables dans la base de données et les met dans une liste déroulante
$listbox_groupe_import = Get-ListboxGroup
#Création d'une info bulle pour la Listbox.
$obj_infobulle.SetToolTip($listBox_groupe_import, "tooltip sur listbox")
I want to set the tooltip on mousehover
I found this but i don't know how to execute it :
$listboxGroupe_MouseMove = [System.Windows.Forms.MouseEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.MouseEventArgs]
#TODO: Place custom script here
#index vaut ce qu'on pointe avec la souris au dessus de listbox1
$index = $listBox_groupe.IndexFromPoint($_.Location) #$_ => this (listbox.location) je crois
##"index ="+$index
##$tooltip1.SetToolTip($listBox_groupe, "index ="+$index)
if ($index -ne -1){
#Tooltype sur listbox1 = valeur de l'item pointé
$tooltip1.SetToolTip($listBox_groupe, $listBox_groupe.Items[$index].ToString())
}
else{
#on n'est pas au dessus de listBox_groupe
$tooltip1.SetToolTip($listBox_groupe, "")
}
}
Can you tell me how to execute this code by mousehover on my listbox?
Or another way to display tooltip with different text for each item of my listbox ?
Thank you
Can you tell me how to execute this code by mousehover on my listbox?
To find the mouse location in hover event, first you can use Control.MousePosition to find the mouse screen location and then using ListBox.PointToClient, convert it to mouse position on the control. Then the rest of logic is similar to what you already have:
$point = $listBox.PointToClient([System.Windows.Forms.Control]::MousePosition)
$index = $listBox.IndexFromPoint($point)
if($index -ge 0) {
$toolTip.SetToolTip($listBox, $listBox.GetItemText($listBox.Items[$index]))
}
else {
$toolTip.SetToolTip($listBox, "")
}
Just to make it a bit better, I used ListBox.GetItemText method which is better than ToString method of items. In case that you set a complex object as data source of the list box and set display member property, it extracts the item text based on the display name, otherwise it returns ToString of the item.
Also don't forget, to handle MouseHover event, you need to use Add_MouseHover.
Solution :
#Au survol
$listBox_groupe.add_MouseEnter({
#récupérer la position de la souris
$point = $listBox_groupe.PointToClient([System.Windows.Forms.Control]::MousePosition)
#récupérer l'indice de l'item sur lequel on pointe
$index = $listBox_groupe.IndexFromPoint($point)
if($index -ge 0) {
#l'infobulle est au dessus de listBox_groupe et elle a pour texte le texte de l'item
$tooltip1.SetToolTip($listBox_groupe, $listBox_groupe.GetItemText($listBox_groupe.Items[$index]))
}
})
Here's the documentation. Particularly, look at the events at the bottom. There is a MouseHover event that you'll want to add:
$MyListBox.add_MouseHover({
# display your tooltip here
})
$MyListBox.add_MouseLeave({
# remove the tooltip now that user moved away
})
PowerShell GUIs and event handlers aren't very well documented since you usually want to handle this sort of thing in C#.

Can not access object in laravel and has "0" indexes when appliying toArray()

I have these tables
clientes
id
nombre_rz
ced_rif
telefono
id_usuario
solicitantes
id
nombre
email
telefono
id_cliente
cliente->hasMany('solicitante')<br>
solicitante->belongsTo('cliente')<br>
^ This is well written in the models, just trying not to make a wall of text.
After Authenticating, when i do
$cliente = Cliente::where('usuario_id','=',Auth::id())->with('solicitante')->get();
dd($cliente);
or
$cliente = Cliente::where('usuario_id','=',Auth::id())->with(array('solicitante' => function($query)
{
$query->where('cliente_id', '=', '35');
}))->get();
dd($cliente);
i get this obect
Object from query
And using toArray() i get this
Array from object
And if access index 0 of that array like
$array = $cliente->toArray(); dd($array['0']);
i get
[Index 0 of array][3]
As far as i can see the queries are correct, and the data i need is there, but i don't know why i can't access the object like
$cliente->id; $cliente->telefono, $cliente->solicitante->nombre, $cliente->solicitante->email
It always throws
Undefined property: Illuminate\Database\Eloquent\Collection::$telefono
Can't Understand this behavior.
You are returning an array of objects, because you asked Laravel for a group. You can either do
foreach ($cliente as $client)
{
echo $client->telefono;
foreach ($client->solicitante as $solicitante)
{
$solicitante->nombre;
}
}
OR you can specify that you only want one result
$cliente = Cliente::where('usuario_id','=',Auth::id())->with('solicitante')->first();
echo $cliente->telefono;
foreach ($client->solicitante as $solicitante)
{
$solicitante->nombre;
}

how to insert data into the db in cakephp

Hi I have a for that has one field (url) and I want to insert the URL typed in the form to the DB
My function add in my controller looks like this:
public function add(){
if($this->request->is('post')){
// debug($this->Link->find('all'));//this works
$link = $this->Link->findByUrl($this->request->data['link']['url']);
if(empty($link)){
//I will create the link
$this->Link->create($this->request->data, true);//true = ignoring the ID
$this->Link->save(null, true, array('url'));
//null = because I ready wrote "$this->request->data" in create
//true = I want to use VALIDATION
//array = I choose to SAVE this field only
echo "I've created the link";
die($this->Link->id);
}else {
debug($link);
die("The link is already in the database");
//je dois récupérer le lien
}
}
How can I insert into the DB the links entered?
Not sure which version of Cake you're using, but the way this would normally work is:
create() new reference
set() new data
save() reference
Example:
$this->Link->create();
$this->Link->set($this->request->data['link']);
$save = $this->Link->save();
echo $save ? "I've created the link" : "Error creating link!";
die($this->Link->id);

CakePHP, GET Parameters and routing

I am fairly new to cakephp but I have a question relating to urls and parameters. I would like to be able to have a url that looks like a standard url e.g:
http://www.mysite.com/controller/myaction?arg=value&arg2=val
I would like that url to map to an action in my controller as follows:
function myaction($arg = null, $arg2 = null)
{
// do work
}
I realize that cakephp has routing as described here, however, honestly this seems over engineered and results in a url string that is nonstandard.
In my current situation the url is being generated and invoked by an external (billing) system that knows nothing about cake and doesn't support the cake url format.
You can have your URL in any form. It's just CakePHP allows you to retrieve the variable passed through GET from the variable $this->params['url']
function myaction()
{
if(isset($this->params['url']['arg']))
$arg = $this->params['url']['arg'];
if(isset($this->params['url']['arg2']))
$arg2 = $this->params['url']['arg2'];
}
Solution in AppController for CakePHP 2.x
class AppController extends Controller {
....
/***
* Recupera los Named envias por URL
* si es null $key emtraga el array completo de named
*
* #param String $key
*
* #return mixed
*/
protected function getNamed($key=null){
// Is null..?
if(is_string($key)==true){
// get key in array
return Hash::get($this->request->param('named'), $key);
}else{
// all key in array
return $this->request->param('named');
}
}
...
}
I have a similar problem. Not because I have an external system, but because I don't like to put all parameters into the URL-path. In my example, I have some search queries that are assembled and passed to the controller. IMHO, these queries should be GET parameters and not part of the URL-path.
One advantage of using GET parameters is that the order of the given parameters is not important, in contrast to passing params via the URL path.
To solve this problem in a generic way, I'm replacing all method arguments with the value of the GET-param, if one with the same name is given:
class MyController extends AppController
{
function test($var1 = null, $var2 = "content2")
{
foreach (get_defined_vars() as $key => $value) {
if (isset($this->params['url'][$key])) {
$getvalue = $this->params['url'][$key];
$$key = $getvalue;
CakeLog::write("debug", "Setting:$key to $getvalue");
}
}
CakeLog::write("debug", print_r(get_defined_vars(), true));
}
}
Now I can access this controller method and pass parameters via GET like this:
http://myapp/mycontroller/test?var1=foo&var2=bar

Resources