question

Paúl Alejandro R avatar image
0 Likes"
Paúl Alejandro R asked Paúl Alejandro R commented

How to register input from sink in database phpAdmin?

I used this tutorial: https://answers.flexsim.com/articles/19407/sql-tutorial-step-by-step-model-construction-29.html, which helped me (with some modifications) to register the label of my product and their arrival time in my database. However, I also need to register their quantity. I need a new record every time the label or the arrival time changes and each record should have the product quantity. It should work similarly to the dashboard in the attached model, but a new record every time the arrival time changes.

13703-db-prueba5.fsm

Example:

Etiqueta(Label) Tiempo(arrival time in seconds) Cantidad(Quantity)
2904
5.11 1
2904 6 5
40405 6 5
40405 7 1

Right now my database is registering new records every time a product arrives, so I have several records like this:

Etiqueta(Label) Tiempo (arrival time in seconds) Cantidad (Quantity)
2904 6 1
2904 6 1
2904 6 1
2904 6 1

Instead of just one: 2904, 6, 4.

I really need to solve this. Thanks in advance!

FlexSim 18.1.2
FlexSim 18.1.1
sqldatabasequantity
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Jacob Gillespie avatar image
1 Like"
Jacob Gillespie answered Paúl Alejandro R commented

I'm not sure if the update query is formatted quite correctly but this should increase the Cantidad when more than one product comes in with the same arrival time. Use this code in the On Entry trigger.

/**Custom Code*/
treenode current = ownerobject(c);
treenode item = param(1);
int port = param(2);

string Tiempo = numtostring(time(),2, 3);  
string Etiqueta = getlabel(item,"WIP");
current.labels.assert("Tiempo", "");

if(Tiempo != current.Tiempo) {
	current.Tiempo = Tiempo;
	current.Etiquetas = [];
	current.Cantidades = [];
}

current.labels.assert("Etiquetas", []);
current.labels.assert("Cantidades", []);
int indice = current.Etiquetas.indexOf(Etiqueta);
 
if(indice == -1) {
	current.Etiquetas.push(Etiqueta);
	current.Cantidades.push(1);
	indice = current.Cantidades.length;
}
else
	current.Cantidades[indice] += 1;

string Cantidad = string.fromNum(current.Cantidades[indice]);
string query;

if(Cantidad == "1") {
	query = concat("insert into `flexsimdata`.`outtimes2` (`Etiqueta`,`Tiempo`,`Cantidad`)values ('", Etiqueta, "','", Tiempo, "','", Cantidad, "');");
}
else {
	query = concat("update `flexsimdata`.`outtimes2` set Cantidad = '", Cantidad, "' where Etiqueta = '", Etiqueta, "' and Tiempo = '", Tiempo, "';");
}

dbopen("flexsimdata", "select * from outtimes2", 0); 
dbsqlquery(query);  
dbclose();

If you try to use pallets like you were trying to do before then you will have to modify the code to look at the product in the pallets.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Paúl Alejandro R avatar image Paúl Alejandro R commented ·

@Jacob Gillespie This is exactly what I needed! Thank you so much!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.