1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-23 00:59:42 +02:00
eda-tools/b2/db.h

117 lines
2.9 KiB
C

/*
* 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
#include <stdio.h>
struct exchange {
const struct currency *dst;
double rate; /* dst = rate*src */
struct exchange *next;
};
struct currency {
const char *name;
struct exchange *exchange;
struct currency *next;
};
/*
* 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
*/
struct price {
int qty; /* order quantity */
double value; /* per quantity cost */
struct price *next; /* next qty */
};
struct provider {
const char *name;
const struct currency *curr;
double shipping; /* S&H cost */
double minimum; /* value of minimum order, before S&H */
struct provider *next;
};
/*
* 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
*/
struct stock {
const struct provider *provider;
const char *cat; /* category */
int avail; /* items in stock */
int package; /* "natural" quantity (reel, tray, bag, etc.) */
const struct currency *curr;
double add; /* additive element of cost */
struct price *price;
} 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);
void part_finalize(struct part *part, const struct action *act);
void part_add_stock(struct part *part, struct stock *s);
void part_dump(FILE *file, const struct part *part);
void parts_dump(FILE *file);
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);
struct provider *provider_lookup(const char *name);
struct provider *provider_add(const char *name);
const struct part **select_parametric(struct param *vars,
const struct action *act);
#endif /* !DB_H */