-2

My question is i want generete a auto increment number for my purchase order for every creation of a PO such as,

PO_000001 , PO_000002 ... etc

Please let me how to generate above way my auto increment number ,

Thank you

Prajwal
  • 3,403
  • 3
  • 20
  • 43

3 Answers3

0

You can store the latest value in ur db. Ex: 1

When u are creating a new Purchase order just do it as 'PO_0000 + (db_value + 1)'

Gvs Akhil
  • 1,494
  • 1
  • 11
  • 24
  • Here I think we need to think about it. According to the question this `PO_` should be a string. rest of should be integer. So we will have to do more things. what happen if `db_value` is 100. then it will give you `PO_0000101` right ?. I think we should increase zeros in `PO_0000` Let me know if i wrong. Thanks – Darshana Pathum Dec 30 '19 at 06:37
  • Yes sorry what u said is correct @DarshanaPathum. I didnt notice that – Gvs Akhil Dec 30 '19 at 07:37
  • If you are updating the PO in db, please keep the entire thing in DB. You can use auto-increment feature available in most of the DB in a field and the same can be used for it. – Prajwal Dec 30 '19 at 08:20
0

I think what you can do is first of all make a auto increment field on your table. So when we need to add your purchase_ID you can get the maximum value of that auto increment fields. like

SELECT field_name FROM table ORDER BY id DESC LIMIT 1;

using above you can get the latest value of the table. then using that you can make your purchase_ID depend on that.

let latest_auto_increment_value = "" + db_value; // make integer to string
let def_val = "0000";
let purchase_ID = 'PO_' + def_val.substring(0, def_val.length - latest_auto_increment_value.length) + latest_auto_increment_value;
Darshana Pathum
  • 544
  • 4
  • 12
0

Generally, This kind of operation is sensitive and secure for any domain, this should be stored in the backend like API or in table whenever you manage. from the frontend Angular, you have to manage a new purchase order every success order that will increment by its number should manage from backend like we know the primary key concept and auto-increment concept. For Ref.

CREATE TABLE contacts
( contact_id INT(11) NOT NULL AUTO_INCREMENT,
  last_name VARCHAR(30) NOT NULL,
  first_name VARCHAR(25),
  birthday DATE,
  CONSTRAINT contacts_pk PRIMARY KEY (contact_id)
);
umang naik
  • 121
  • 1
  • 9