-
Notifications
You must be signed in to change notification settings - Fork 3
/
stock.h
94 lines (76 loc) · 1.74 KB
/
stock.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright 2006-2013, Clemens Zeidler, [email protected]
* Distributed under the terms of the MIT License.
*/
#ifndef STOCK_H
#define STOCK_H
#include <String.h>
#include <List.h>
#include <Locker.h>
#include <Messenger.h>
#include "SQLConnection.h"
const uint TRADE_STATE_NONE = 0;
const uint TRADE_STATE_ADD = 1;
const uint TRADE_STATE_UPDATE = 2;
const uint TRADE_STATE_REMOVE = 3;
typedef struct product_f
{
product_f();
void Archive(BMessage *archive);
void Instantiate(BMessage *archive);
int32 id;
BString name;
BString barcode;
BString comment;
float prize;
int32 supplies;
bool valid; //set to false when product is removed
time_t insertdate;
};
typedef struct trade_f
{
int32 id;
int32 productid;
float prize;
time_t date;
uint32 number; //number of sells
};
typedef struct basket_f
{
basket_f(time_t date);
~basket_f();
time_t date;
BList trades;
float sum;
bool saved;
};
typedef struct trade_info
{
trade_info();
trade_f *trade;
product_f *product;
basket_f *basket;
uint8 state;
int32 oldnumber;
};
class Stock
{
public:
Stock(BString filename);
~Stock();
//! If product is already in the list the product will be updated.
int32 AddProduct(product_f &product);
//! If trade is already in the list the trade will be updated.
int32 AddTrade(trade_f &trade);
void UpdateTrade(uint id, trade_f &trade);
void UpdateProduct(uint id, product_f &product);
void RemoveTrade(uint id);
status_t GetProducts(BList* list);
status_t GetTrades(BList* list);
//! Sets the product count to zero for all products (inventory).
status_t ResetProductsCount();
private:
SQLiteConnection* fDatabase;
BLocker fLock;
};
#endif