Root/
| 1 | /* |
| 2 | * db.h - Parts database |
| 3 | * |
| 4 | * Copyright 2012 by Werner Almesberger |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | #ifndef DB_H |
| 14 | #define DB_H |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | |
| 18 | |
| 19 | struct exchange { |
| 20 | const struct currency *dst; |
| 21 | double rate; /* dst = rate*src */ |
| 22 | struct exchange *next; |
| 23 | }; |
| 24 | |
| 25 | struct currency { |
| 26 | const char *name; |
| 27 | struct exchange *exchange; |
| 28 | struct currency *next; |
| 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * If quantity increases, next entry is next higher discount. |
| 33 | * If quantity decreases, next entries are prices after reaching the large |
| 34 | * quantity. |
| 35 | * |
| 36 | * Examples: |
| 37 | * |
| 38 | * An order of 12 units with the prices below |
| 39 | * |
| 40 | * a) 1 0.5 10 4.0 100 30.0 |
| 41 | * b) 1 0.5 10 4.0 1 0.4 100 30.0 |
| 42 | * |
| 43 | * would cost |
| 44 | * |
| 45 | * a) 1*4.0+2*0.5 = 5.0 |
| 46 | * b) 1*4.0+2*0.4 = 4.8 |
| 47 | */ |
| 48 | |
| 49 | struct price { |
| 50 | int qty; /* order quantity */ |
| 51 | double value; /* per quantity cost */ |
| 52 | struct price *next; /* next qty */ |
| 53 | }; |
| 54 | |
| 55 | struct provider { |
| 56 | const char *name; |
| 57 | const struct currency *curr; |
| 58 | double shipping; /* S&H cost */ |
| 59 | double minimum; /* value of minimum order, before S&H */ |
| 60 | struct provider *next; |
| 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * Handling of multiple forms of packaging: |
| 65 | * |
| 66 | * - category is a keyword that identifies the packaging type, e.g., |
| 67 | * T for tape/tray, MAN for manual feeding, etc. |
| 68 | * - a query can be constrained to a set of categories |
| 69 | * - conversion options (e.g., "Digi-Reel") can be expressed as additional |
| 70 | * entries |
| 71 | * |
| 72 | * @@@ To do: shared availability |
| 73 | */ |
| 74 | |
| 75 | struct stock { |
| 76 | const struct provider *provider; |
| 77 | const char *cat; /* category */ |
| 78 | int avail; /* items in stock */ |
| 79 | int package; /* "natural" quantity (reel, tray, bag, etc.) */ |
| 80 | const struct currency *curr; |
| 81 | double add; /* additive element of cost */ |
| 82 | struct price *price; |
| 83 | } stock; |
| 84 | |
| 85 | struct part { |
| 86 | const char *domain; |
| 87 | const char *name; |
| 88 | struct param *param; /* NULL if @@@ */ |
| 89 | struct stock *stock; /* NULL if vendor part */ |
| 90 | struct part *next; /* alias loop (cyclic) */ |
| 91 | struct part *prev; |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | struct part *part_lookup(const char *domain, const char *name); |
| 96 | struct part *part_add(const char *domain, const char *name); |
| 97 | void part_alias(struct part *a, struct part *b); |
| 98 | void part_finalize(struct part *part, const struct action *act); |
| 99 | void part_add_stock(struct part *part, struct stock *s); |
| 100 | void part_dump(FILE *file, const struct part *part); |
| 101 | void parts_dump(FILE *file); |
| 102 | |
| 103 | const struct currency *currency_lookup(const char *name); |
| 104 | double currency_convert(const struct currency *from, const struct currency *to, |
| 105 | double value); |
| 106 | struct currency *currency_add(const char *name); |
| 107 | void currency_exchange(struct currency *from, const struct currency *to, |
| 108 | double rate); |
| 109 | |
| 110 | struct provider *provider_lookup(const char *name); |
| 111 | struct provider *provider_add(const char *name); |
| 112 | |
| 113 | const struct part **select_parametric(struct param *vars, |
| 114 | const struct action *act); |
| 115 | |
| 116 | #endif /* !DB_H */ |
| 117 |
Branches:
master
