2012-03-18 18:24:12 +02:00
|
|
|
/*
|
|
|
|
* db.h - Parts database
|
|
|
|
*
|
|
|
|
* Copyright 2012 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef DB_H
|
|
|
|
#define DB_H
|
|
|
|
|
2012-04-29 05:26:22 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
struct exchange {
|
|
|
|
const struct currency *dst;
|
2012-05-01 04:49:33 +03:00
|
|
|
double rate; /* dst = rate*src */
|
2012-03-18 18:24:12 +02:00
|
|
|
struct exchange *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct currency {
|
|
|
|
const char *name;
|
|
|
|
struct exchange *exchange;
|
|
|
|
struct currency *next;
|
|
|
|
};
|
|
|
|
|
2012-05-01 02:03:10 +03:00
|
|
|
/*
|
|
|
|
* If quantity increases, next entry is next higher discount.
|
|
|
|
* If quantity decreases, next entries are prices after reaching the large
|
|
|
|
* quantity.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
*
|
|
|
|
* An order of 12 units with the prices below
|
|
|
|
*
|
|
|
|
* a) 1 0.5 10 4.0 100 30.0
|
|
|
|
* b) 1 0.5 10 4.0 1 0.4 100 30.0
|
|
|
|
*
|
|
|
|
* would cost
|
|
|
|
*
|
|
|
|
* a) 1*4.0+2*0.5 = 5.0
|
|
|
|
* b) 1*4.0+2*0.4 = 4.8
|
|
|
|
*/
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
struct price {
|
|
|
|
int qty; /* order quantity */
|
|
|
|
double value; /* per quantity cost */
|
2012-05-01 02:03:10 +03:00
|
|
|
struct price *next; /* next qty */
|
2012-03-18 18:24:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct provider {
|
|
|
|
const char *name;
|
2012-05-01 20:57:12 +03:00
|
|
|
const struct currency *curr;
|
2012-03-18 18:24:12 +02:00
|
|
|
double shipping; /* S&H cost */
|
2012-05-01 02:03:10 +03:00
|
|
|
double minimum; /* value of minimum order, before S&H */
|
2012-03-18 18:24:12 +02:00
|
|
|
struct provider *next;
|
|
|
|
};
|
|
|
|
|
2012-05-01 02:03:10 +03:00
|
|
|
/*
|
|
|
|
* Handling of multiple forms of packaging:
|
|
|
|
*
|
|
|
|
* - category is a keyword that identifies the packaging type, e.g.,
|
|
|
|
* T for tape/tray, MAN for manual feeding, etc.
|
|
|
|
* - a query can be constrained to a set of categories
|
|
|
|
* - conversion options (e.g., "Digi-Reel") can be expressed as additional
|
|
|
|
* entries
|
|
|
|
*
|
|
|
|
* @@@ To do: shared availability
|
|
|
|
*/
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
struct stock {
|
2012-05-01 21:21:32 +03:00
|
|
|
const struct provider *provider;
|
2012-05-01 02:03:10 +03:00
|
|
|
const char *cat; /* category */
|
2012-03-18 18:24:12 +02:00
|
|
|
int avail; /* items in stock */
|
|
|
|
int package; /* "natural" quantity (reel, tray, bag, etc.) */
|
2012-05-01 02:03:10 +03:00
|
|
|
const struct currency *curr;
|
|
|
|
double add; /* additive element of cost */
|
|
|
|
struct price *price;
|
2012-03-18 18:24:12 +02:00
|
|
|
} stock;
|
|
|
|
|
|
|
|
struct part {
|
|
|
|
const char *domain;
|
|
|
|
const char *name;
|
|
|
|
struct param *param; /* NULL if @@@ */
|
|
|
|
struct stock *stock; /* NULL if vendor part */
|
|
|
|
struct part *next; /* alias loop (cyclic) */
|
|
|
|
struct part *prev;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct part *part_lookup(const char *domain, const char *name);
|
|
|
|
struct part *part_add(const char *domain, const char *name);
|
|
|
|
void part_alias(struct part *a, struct part *b);
|
2012-04-29 05:30:50 +03:00
|
|
|
void part_finalize(struct part *part, const struct action *act);
|
2012-05-01 02:03:10 +03:00
|
|
|
void part_add_stock(struct part *part, struct stock *stock);
|
2012-04-29 05:26:22 +03:00
|
|
|
void part_dump(FILE *file, const struct part *part);
|
2012-03-18 18:24:12 +02:00
|
|
|
|
2012-05-01 04:49:33 +03:00
|
|
|
const struct currency *currency_lookup(const char *name);
|
|
|
|
double currency_convert(const struct currency *from, const struct currency *to,
|
|
|
|
double value);
|
|
|
|
struct currency *currency_add(const char *name);
|
|
|
|
void currency_exchange(struct currency *from, const struct currency *to,
|
|
|
|
double rate);
|
|
|
|
|
2012-05-01 20:57:12 +03:00
|
|
|
struct provider *provider_lookup(const char *name);
|
|
|
|
struct provider *provider_add(const char *name);
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
#endif /* !DB_H */
|