# Help in writing a stock management code

**URL:** <https://discourse.processing.org/t/help-in-writing-a-stock-management-code/27875>\
**Category:** Beginners\
**Created:** [February 17, 2021, 4:21am UTC](https://discourse.processing.org/t/help-in-writing-a-stock-management-code/27875 "2021-02-17T04:21:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zvodca](https://avatars.discourse-cdn.com/v4/letter/z/85e7bf/32.png) [@zvodca](https://discourse.processing.org/u/zvodca)\
**Post date:** [February 17, 2021, 4:21am UTC](https://discourse.processing.org/t/help-in-writing-a-stock-management-code/27875/1 "2021-02-17T04:21:11Z")

</div>

Is it possible to write a code for stock managing in processing? If so can i get a code for that purpose?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 17, 2021, 8:01am UTC](https://discourse.processing.org/t/help-in-writing-a-stock-management-code/27875/2 "2021-02-17T08:01:07Z")

</div>

You can write a stock management Sketch that tells you how many books (for example) (and which books) you have in stock / store.

**But I urge you** to buy a professional program / software and customize it to your needs.

A stock management system is a huge project.

- professional systems are connected to the cash Desk and register which book is sold and register in the stock -1 book.

- You can use a bar code scanner to register incoming books. So in the stock you have +1.

- You can make the system tell you when you need to order a book (e.g. when only 3 books are left).

All this is hard to integrate with processing.

Warm regards,

Chrisir

---

<div class="post-metadata">

**Author:** ![zvodca](https://avatars.discourse-cdn.com/v4/letter/z/85e7bf/32.png) [@zvodca](https://discourse.processing.org/u/zvodca)\
**Post date:** [February 17, 2021, 10:11am UTC](https://discourse.processing.org/t/help-in-writing-a-stock-management-code/27875/3 "2021-02-17T10:11:25Z")

</div>

I actually want a small version of stock management which updates the stock when a sales is made and to let know when it is in re order level. It is not for usr in a commercial use. Just for a project i am working on.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 17, 2021, 2:05pm UTC](https://discourse.processing.org/t/help-in-writing-a-stock-management-code/27875/4 "2021-02-17T14:05:52Z")

</div>

Yes, you can do this with processing

```auto

int itemNumber=3;  
Table itemTable = null; 

void setup() {
  size(500, 500);

  itemTable = loadTable("stockitems.csv", "header");

  // File found? 
  if (itemTable == null) {
    // No
    itemTable = new Table();

    itemTable.addColumn("id");
    itemTable.addColumn("itemCount");

    TableRow newRow = itemTable.addRow();
    newRow.setInt("id", 0);
    newRow.setInt("itemCount", itemNumber);

    saveTable(itemTable, "data/stockitems.csv", "csv");
    println("made new table ");
  } else {
    // Yes 
    println("loaded");
    TableRow myRow = itemTable.getRow(itemTable.lastRowIndex());

    itemNumber= myRow.getInt("itemCount");
  }//else
}

void draw() {
  background(10);
  fill(255); 
  text("Inventory Management System", 200, height/2-150);
  text(itemNumber, width/2, height/2);

  if (itemNumber<3) {
    text("Please order ! ", width/2, height/2+111);
  }
}

void keyPressed() {
  if (key=='+') {
    itemNumber++;
  } else if (key=='-') {
    itemNumber--;
  } else if (key==ESC) {
    key=0;
    return;
  } else {
    return;
  }

  // save 
  TableRow myRow = itemTable.getRow(itemTable.lastRowIndex());
  myRow.setInt("itemCount", itemNumber);
  saveTable(itemTable, "data/stockitems.csv", "csv");

  //
}//func

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 17, 2021, 6:44pm UTC](https://discourse.processing.org/t/help-in-writing-a-stock-management-code/27875/5 "2021-02-17T18:44:41Z")

</div>

The Sketch has only ONE item in stock

- it searches a csv first and loads it (and reads the number of items in your stock) OR
- when it doesn’t find it it creates the csv

change the number of items in your stock with + and -

It saves every time you change the number of items in your stock

But I recommend to use a free stock management: [Top 7 Free Inventory Management Systems | Business.org](https://www.business.org/finance/inventory-management/best-free-inventory-management-software/)

Warm regards,

Chrisir
