hbenavides
(hbenavides)
1
Hi, I’m new programming and using yii2.
I have a model like this:
I’d(int),
Consecutive(varchar),
Description (varchar).
For the first time my client handle one type of consecutive(99-9999). But now he wants handle another 2 type of consecutive (99-M-999,99-L-999).
I need your help. I have no idea how to handle 3 different consecutive types. Do I need to use a new model for each new correlative ?. Help me
hyde82
2
Hi,
the problem is not clear.
hbenavides
(hbenavides)
3
I mean, for now I have this:
Id. Correlative. description
-
19-0001. Something
-
19-0002. Something
Can I do this?
Id. Correlative. Description
-
19-0001. Something
-
19-0002. Something
-
19-M-0001. Something
-
19-M-0002. Something
-
19-L-001. Something
I don’t now how to increment every correlative in the same model, I think I must create a model for every different correlative
hyde82
4
You dont need to create a new model.
You should implement some logic to solve the problem. For example you could:
-
Get last record from DB;
-
Explode all the “-” in the value fetched;
-
Get the index of the exploded string(es.for string NN-S-NNN );
-
for every index use increment function(+) to count string /character and number.
Es.
$s = “A”;
$s++; ($s is B now)
//The same is for number;
-
rebuild your string as your initial pattern (NN-S-NNN)
-
save the record;
That is a minimal logic example to solve you problem.
Try to code the flow!
Good luck