Continuing the started topic
on the creation and development of self-written ERP system , I will describe the logistics outline.

Business
The company's business is built on the repair of computer equipment and in a simplified form looks quite simple:
- A customer brings his laptop to a service center;
- The laptop is inspected (there are a number of requirements from the vendor to start repairs), draw up documents and send it to the repair site of the service center;
- According to the filed requests, the department of managers determines the possibility of repairing, using warehouse stocks or the need to order components;
- After the necessary parts to complete the repair appear in stock, the manager transfers the application to the status “for execution”;
- A laptop and the necessary spare parts for repair come to the repair site;
- The engineer performs repairs, replacing broken parts with workers;
- The laptop returns to the service center, the customer is notified of the completion of the repair;
- Equipment is returned to the customer;
')
We will look at some of the work associated with inventory.
Stock
There is a central warehouse to which all parts arrive, for all service centers, after which they are distributed according to requests for repairs.
Some service centers are subsidiaries of the company, others are authorized and are independent organizations.
Warranty and paid repairs
With paid everything is quite simple, we “sell” to the client the spare part and the cost of work, or our partner does it.
In the case of warranty repair, we “redeem” the item from the vendor, perform the repair, return the broken part to the vendor, and then receive payment for the repair and the cost of the previously purchased part.
But ... the vendor establishes that period of time between the purchase of the part and the performance of the repair, as well as the return of the defective part. Did not meet - fine. So, the requirements for logistics are quite tough, up to several days between ordering the part and performing the repair.
Of course, it is still more confusing, since not all items need to be returned. It is not always the part that is needed, in some cases there is a “component repair”. There are requirements for the mandatory availability of "running" parts in the warehouse.
Firstly
Since initially it was not clear what, our group got up from the chairs and walked with legs through all the departments of the company.
The result is a small A3 diagram of all, almost, internal and external processes.
Core logistics
At the heart of the warehouse management system is a small set of logic:
- you need to keep a list of parts, a list of all service centers, a list of movements of parts;
- implement the execution of repetitive movement actions;

Four operations are enough:
- “Coming” (+ Qty);
- “Expense” (-Qty);
- “Debt creation” (Qty-);
- "Return" (Qty +).
The first two operations are quite logical, we “come” to the warehouse and place it on the shelves. When the item is sent to the service center, we make out the "expense".
The remaining two operations are necessary, because after sending the part to the service center, we expect them to return the broken equipment. It is quite logical that we will repay the debt of the service center as soon as the broken part comes to us.
Magic numbers
Consider the most interesting part of the core of the work of logistics - moving parts.
Any part in the system has a unique identifier SPI (Spare
P art Information)
Income and expense simple operation. Everything that enters the warehouse increases the number of parts, everything that leaves decreases.
All you need is a QtyRest field.It is not bad to know how many details came to me, for reports. In addition, for the formation of warehouse balances for the period you need to know the time of the operations performed.
Qty, EventDate fields appear
This scheme lacks “speed” because in most cases we are interested in actual data. And with operations that have
QtyRest = 0 , there is also no point in working.
Replace the EventDate field with IsOpen, OpenDate, CloseDate (IS NULL)
The logic of the two operations can be written as:



Coming adds a new entry, which indicates how many details have come (
Qty ) and how many are left (
QtyRest = Qty ). The operation is "open", because has a non-zero balance (
IsOpen = true )
Expense also adds a new entry that indicates how much detail is leaving (
-Qty ). Remains for the negative operation can not be (
QtyRest = 0 ). Expense operation reduces the number (
QtyRest ) in the ward.
If the operation
QtyRest = 0 , then it is “closed”
IsOpen = false ,
CloseDate = GETDATE () .
It is also impossible to leave a negative balance (
QtyRest <0 ), this is not logical and is used in the system for other purposes.
What you should pay special attention to:
- Any operation is a new entry (INSERT). This is important because it allows you to build fairly complex reports based on dates;
- we work only with operations IsOpen = true (there are relatively few of them, compared with the general history), which allows the use of partitioning;
- the expense operation can be performed only in the case of a sufficient number of parts in open receipt operations;
To be continued.
We will look at two other “debt creation” and “return” operations, the concept of “types of warehouses” and the actions “moving between warehouses”