-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.pl
79 lines (71 loc) · 2.42 KB
/
control.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*********************
* Control Instrument Stock
**********************
* 1º-If the Quantity for a product is below 5 we need to make the factory produce new Instruments.
* 2º-If it's above 5 we cool.
**********************/
control_Instrument_Stock(Frame,Nome,Ref,Data_Fab,Preco,Pecas,Quantidade):-
(Quantidade <= 5 ->
produce_Instrument(Nome),
get_date(D),
genmsg(Nome+'Instrumento em pouca quantidade, fábrica a produzir',Quantidade,D);
write('Produzido com sucesso!');
Quantidade >5 -> !.
);
/**********************
* Mechanism to produce an instrument.
***********************
* 1º-Checks how many Instruments we can produce in a factory and displays that number.
* 2º-Asks how many we want to produce.
* 3º-Checks if it's possible to cover that request.
* 4º-Makes the necessery steps to make that product
***********************/
produce_Instrument(Nome):-
get_Possible_stock(Nome,Stock),
Stock =:= 0,
(write('Possível produzir '),write(Stock),write(Nome),nl,
write('Quanto deseja produzir? '),
read(Produce),
(Produce <= Stock ->
get_values(Nome,pecas,Piece),
process_needed_Pieces(Piece,Produce),
get_date(NDate),
new_value(Nome,data_fabrico, NDate),
get_value(fabrica,total_produtos_stock, TS),
NS is TS + Produce,
new_value(fabrica,total_produtos_stock,NS),
get_value(Nome,quantidade, Q),
Q1 is Q+Produce,
new_value(Nome,quantidade,Q1);
Produce >Stock -> write('Não é possivel produzir!');
Produce =:= 0 -> write('Nada Produzido.')
);
);
write('Não é possivel produzir nada').
/******************
*Updates the stock for each piece.
*******************/
process_needed_Pieces([(Piece_Name,Piece_Quantity)|T], Produce):-
Needed_Quantity is Produce * Piece_Quantity,
decrease_Stock(Piece_Name,Needed_Quantity),
process_needed_Pieces(T, Produce).
/****************
*Mechanism to control the Stock limit on the factory.
*****************
* 1º-Emmit an alarm
****************/
control_Factory_Stock(F,Nome,_,Cap,Actual_Stock):-
Difer is Cap - Actual_Stock,
get_date(D),
genmsg('A chegar ao limite de capacidade da fábrica', Difer, D).
/****************
*Mechanism to control the stock values of every piece.
*****************
* generates a message qhen a piece is running low, under 10
*****************/
control_piece_stock(F,Nome,Ref,Stock):-
(Stock <=10 ->
get_date(D),
genmsg('Stock menor que 10.', Nome,D);
Stock > 10 -> !
).