msSQLとVB2008にあった納品書付請求書システムをPHP+MySQLに移植しており、お客様への請求書作成時以外は全て終了しました。
私はこれらのテーブルを使用しています:
表 1 に各納品書を追加します
CREATE TABLE IF NOT EXISTS `delivery_note` (
`id_delivery_note` int(11) NOT NULL AUTO_INCREMENT,
`number_delivery_note` int(11) DEFAULT NULL,
`id_product` int(11) NOT NULL,
`qty_delivered` int(11) NOT NULL,
`qty_received` int(11) DEFAULT NULL,
`date` date DEFAULT NULL,
`client_code` varchar(50) DEFAULT NULL,
`active` int(1) DEFAULT NULL,
`id_invoice` int(11) DEFAULT NULL,
`invoiced` int(1) DEFAULT NULL,
PRIMARY KEY (`id_delivery_note`)
) TYPE=MyISAM ROW_FORMAT=DYNAMIC AUTO_INCREMENT=6 ;
INSERT INTO `delivery_note` (`id_delivery_note`, `number_delivery_note`, `id_product`, `qty_delivered`, `qty_received`, `date`, `client_code`, `active`, `id_invoice`, `invoiced`) VALUES
(2, 2, 13, 1, NULL, '2012-04-25', '1', 1, NULL, 0),
(3, 3, 24, 1, NULL, '2012-04-25', '1', 1, NULL, 0),
(5, 1, 13, 2, NULL, '2012-04-24', '2', 1, NULL, 0);
表2は、各顧客の各アイテムの価格を保持する場所です(すべての顧客の価格は異なります)
CREATE TABLE IF NOT EXISTS `product_price` (
`id_product_price` int(11) NOT NULL AUTO_INCREMENT,
`client_code` int(11) DEFAULT NULL,
`id_product` int(11) DEFAULT NULL,
`price` decimal(15,2) DEFAULT NULL,
PRIMARY KEY (`id_product_price`)
) TYPE=MyISAM ROW_FORMAT=FIXED AUTO_INCREMENT=6 ;
INSERT INTO `product_price` (`id_product_price`, `client_code`, `id_product`, `price`) VALUES
(1, 1, 13, 1.51),
(2, 1, 24, 43.11),
(3, 1, 24, 11.00),
(4, 2, 13, 1.52),
(5, 2, 24, 43.12);
そして、私が使用してきたクエリは次のとおりです。
SELECT number_delivery_note, delivery_note.id_product, qty_delivered, date, product_price.price
FROM delivery_note, product_price
WHERE(delivery_note.client_code = 1) AND (delivery_note.invoiced = 0)
そして、私にこれをすべて与えます:
http://s14.postimage.org/rghvfmo9t/Sin_t_tulo_1.gif
このデータだけが必要な場合: