Compare commits
7
Commits
5db402c7cf
..
0.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
defa951e51 | ||
|
|
c088caf03e | ||
|
|
8cd79da5eb | ||
|
|
8b5b690435 | ||
|
|
c6543cc583 | ||
|
|
05237cc7f1 | ||
|
|
176c2d8be5 |
No files matched your search
@@ -3,9 +3,10 @@ Un gestore di inventario e vendite minimale
|
||||
|
||||
## Scaricarlo
|
||||
Disponibile solo per linux.
|
||||
Scarica l'ultima versione da [qui](https://git.lug.uniroma2.it/rexeref/productManager/releases)!
|
||||
Scarica l'ultima versione dalla pagina delle releases!
|
||||
Avvia l'eseguibile da un terminale.
|
||||
Se non si avvia rendilo prima un eseguibile con chmod +x
|
||||
|
||||
|
||||
***questo codice molto probabilmente NON è sicuro, utilizzarlo a propria indiscrezione***
|
||||
|
||||
## Troubleshooting
|
||||
wip
|
||||
@@ -7,5 +7,6 @@
|
||||
|
||||
extern char productPricesFileLocation[64]; // Dichiarazione extern
|
||||
extern char countFileLocation[64];
|
||||
extern char configFileLocation[64];
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef JSONFILE_H
|
||||
#define JSONFILE_H
|
||||
|
||||
#include <json-c/json.h>
|
||||
|
||||
int existsFile(const char *fname);
|
||||
int createFile(const char *fname);
|
||||
int renameDataFile(const char *oldName, const char *newName);
|
||||
|
||||
json_object *loadJsonArray(const char *fname);
|
||||
int saveJsonArray(const char *fname, json_object *arr);
|
||||
|
||||
json_object *findItemByName(json_object *arr, const char *name);
|
||||
int removeItemByName(json_object *arr, const char *name);
|
||||
int renameItemByName(json_object *arr, const char *oldName, const char *newName);
|
||||
|
||||
#endif
|
||||
+21
-6
@@ -6,7 +6,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ncurses.h>
|
||||
#include <json-c/json.h>
|
||||
#include "jsonFile.h"
|
||||
|
||||
#define PRODUCT_STOCK_UNLIMITED (-1)
|
||||
|
||||
struct product {
|
||||
float cost;
|
||||
@@ -14,23 +16,36 @@ struct product {
|
||||
char name;
|
||||
};
|
||||
|
||||
/* File */
|
||||
int existsFile(const char *fname);
|
||||
int createFile(const char *fname);
|
||||
int renameDataFile(const char *oldName, const char *newName);
|
||||
|
||||
/* Prodotti */
|
||||
json_object *getProducts(const char *fname);
|
||||
void listProducts(const char *fname);
|
||||
int addProduct(const char *fname, const char *name, double price);
|
||||
int addProductWithInventory(const char *fname, const char *name, double price, int stock);
|
||||
int addBundleProduct(const char *fname, const char *name, double price, json_object *components);
|
||||
double getPrice(const char *fname, const char *name);
|
||||
int updateProduct(const char *productsFile, const char *soldFile, const char *oldName, const char *newName, double price);
|
||||
int updateProductWithInventory(const char *productsFile, const char *soldFile, const char *oldName, const char *newName, double price, int stock);
|
||||
int getProductInventory(const char *fname, const char *name, int *stock, int *tracked);
|
||||
int setProductInventory(const char *fname, const char *name, int stock, int tracked);
|
||||
int consumeProductInventory(const char *fname, const char *name, int qty);
|
||||
|
||||
/* Copie vendute */
|
||||
int getCount(const char *fname, const char *name);
|
||||
void listSold(const char *fname);
|
||||
int addSold(const char *fname, const char *name, int qty);
|
||||
int deleteSold(const char *productsFile, const char *soldFile, const char *name);
|
||||
int updateSold(const char *productsFile, const char *soldFile, const char *name, int qty);
|
||||
int recordSale(const char *productsFile, const char *soldFile, const char *name, int qty);
|
||||
|
||||
/* Entrate */
|
||||
double getTotalRevenue(const char *productsFile, const char *soldFile);
|
||||
|
||||
/* Export */
|
||||
int exportSalesToCsv(const char *productsFile, const char *soldFile, const char *outFile);
|
||||
|
||||
/* Config */
|
||||
int ensureAppConfig(const char *fname);
|
||||
int loadAppConfig(const char *fname);
|
||||
int saveAppConfig(const char *fname);
|
||||
|
||||
#endif
|
||||
@@ -9,10 +9,12 @@
|
||||
int runMainMenu();
|
||||
void runOptionsMenu();
|
||||
void runSellWindow();
|
||||
void runCreateBundleWindow();
|
||||
void runAboutWindow();
|
||||
void runViewSalesWindow();
|
||||
void runViewProductsWindow();
|
||||
void runAddProductWindow();
|
||||
void runExportCsvWindow();
|
||||
void example_window();
|
||||
|
||||
#endif
|
||||
@@ -31,7 +31,9 @@ bundle: $(OBJECTS)
|
||||
$(CC) $^ -o dist/$(EXEC) $(BUNDLE_LDFLAGS) $(LDLIBS)
|
||||
@cp -L $$( $(PKG_CONFIG) --variable=libdir json-c )/libjson-c.so* dist/lib/
|
||||
@cp -L $$( $(PKG_CONFIG) --variable=libdir ncurses )/libncurses*.so* dist/lib/
|
||||
@echo "=== Pacchetto portabile creato con successo in ./dist ==="
|
||||
@tar czf productManager.tar.gz --directory dist/ .
|
||||
@echo "=== Pacchetto portabile creato con successo in productManager.tar.gz ==="
|
||||
@rm -fr dist/
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR) $(EXEC) dist *.json
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
|
||||
char productPricesFileLocation[64]="./pm-item-price-default.json";
|
||||
char countFileLocation[64]="./pm-item-sold-count-default.json";
|
||||
char configFileLocation[64]=".fpm";
|
||||
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <json-c/json.h>
|
||||
|
||||
#include "../include/jsonFile.h"
|
||||
|
||||
int existsFile(const char *fname) {
|
||||
FILE *file = fopen(fname, "r");
|
||||
if (file) {
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int createFile(const char *fname) {
|
||||
json_object *arr = json_object_new_array();
|
||||
if (!arr)
|
||||
return -1;
|
||||
|
||||
int res = json_object_to_file_ext(fname, arr, JSON_C_TO_STRING_PRETTY);
|
||||
json_object_put(arr);
|
||||
return (res == 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
int renameDataFile(const char *oldName, const char *newName) {
|
||||
return (rename(oldName, newName) == 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
static json_object *loadRawArray(const char *fname) {
|
||||
if (!existsFile(fname) && createFile(fname) != 0)
|
||||
return NULL;
|
||||
|
||||
FILE *f = fopen(fname, "r");
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
int empty = (fgetc(f) == EOF);
|
||||
fclose(f);
|
||||
if (empty)
|
||||
return json_object_new_array();
|
||||
|
||||
json_object *arr = json_object_from_file(fname);
|
||||
if (!arr)
|
||||
return NULL;
|
||||
|
||||
if (!json_object_is_type(arr, json_type_array)) {
|
||||
json_object_put(arr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
json_object *loadJsonArray(const char *fname) {
|
||||
return loadRawArray(fname);
|
||||
}
|
||||
|
||||
int saveJsonArray(const char *fname, json_object *arr) {
|
||||
if (!arr)
|
||||
return -1;
|
||||
return (json_object_to_file_ext(fname, arr, JSON_C_TO_STRING_PRETTY) == 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
json_object *findItemByName(json_object *arr, const char *name) {
|
||||
if (!arr || !name)
|
||||
return NULL;
|
||||
|
||||
size_t n = json_object_array_length(arr);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
json_object *item = json_object_array_get_idx(arr, i);
|
||||
json_object *jname = NULL;
|
||||
|
||||
if (json_object_object_get_ex(item, "name", &jname) &&
|
||||
strcmp(json_object_get_string(jname), name) == 0)
|
||||
return item;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int removeItemByName(json_object *arr, const char *name) {
|
||||
if (!arr || !name)
|
||||
return -1;
|
||||
|
||||
size_t n = json_object_array_length(arr);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
json_object *item = json_object_array_get_idx(arr, i);
|
||||
json_object *jname = NULL;
|
||||
|
||||
if (json_object_object_get_ex(item, "name", &jname) &&
|
||||
strcmp(json_object_get_string(jname), name) == 0) {
|
||||
json_object_array_del_idx(arr, (int)i, 1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int renameItemByName(json_object *arr, const char *oldName, const char *newName) {
|
||||
if (!arr || !oldName || !newName)
|
||||
return -1;
|
||||
|
||||
json_object *item = findItemByName(arr, oldName);
|
||||
if (!item)
|
||||
return 1;
|
||||
|
||||
json_object_object_add(item, "name", json_object_new_string(newName));
|
||||
return 0;
|
||||
}
|
||||
+805
-97
File diff suppressed because it is too large.
Load diff
+4
-24
@@ -22,6 +22,7 @@
|
||||
#include "../include/windowsDeclaration.h"
|
||||
#include "../include/windowsBack.h"
|
||||
#include "../include/logic.h"
|
||||
#include "../include/globals.h"
|
||||
|
||||
void printLogoBG();
|
||||
|
||||
@@ -43,36 +44,15 @@ int main(){
|
||||
noecho();
|
||||
curs_set(0);
|
||||
raw();
|
||||
if (loadAppConfig(configFileLocation) != 0)
|
||||
warningf("Impossibile caricare la config '%s', uso i valori di default.", configFileLocation);
|
||||
printLogoBG();
|
||||
statusf(" ");
|
||||
refresh();
|
||||
|
||||
|
||||
int running = 0;
|
||||
while(running != 6){
|
||||
while (runMainMenu()) {
|
||||
printLogoBG();
|
||||
refresh();
|
||||
running = runMainMenu();
|
||||
switch(running) {
|
||||
case 1:
|
||||
runSellWindow();
|
||||
break;
|
||||
case 2:
|
||||
runViewSalesWindow();
|
||||
break;
|
||||
case 3:
|
||||
runViewProductsWindow();
|
||||
break;
|
||||
case 4:
|
||||
runAddProductWindow();
|
||||
break;
|
||||
case 5:
|
||||
runAboutWindow();
|
||||
// runOptionsMenu();
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
endwin();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#include "../include/windowsBack.h"
|
||||
|
||||
+819
-114
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user