From ea921a95b65ffaae5b008f864494553d73289612 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Tue, 24 Jul 2012 15:03:41 +0200 Subject: [PATCH] Prvni pokus o osamostatneni carovych kodu, bohuzel to rozbilo asistenty a razeni ORDER BY --- assistants/migrations.inc.php | 7 +++++++ dump_sql.php | 2 +- index.php | 21 ++++++++++++--------- install.sql | 28 +++++++++++++++++++--------- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/assistants/migrations.inc.php b/assistants/migrations.inc.php index c492ecb..c00b8e3 100644 --- a/assistants/migrations.inc.php +++ b/assistants/migrations.inc.php @@ -1,4 +1,11 @@
+

-- populate barcode table

db->safe_query_fetch('SELECT model_id as id, model_barcode as bar FROM model;'); +//print_r($data); +echo("UPDATE item SET barcode_id=model_id;\n"); +echo("INSERT INTO barcode (barcode_id,model_id,barcode_name) VALUES\n"); +foreach($data as $line) echo("('".$line['id']."','".$line['id']."','".$line['bar']."'),\n"); +?>

-- populate columns item_date_bought and item_date_sold

db->safe_query_fetch('SELECT item_id,MIN(item_valid_from) AS min,MAX(item_valid_from) AS max FROM item GROUP BY item_id;'); //print_r($data); diff --git a/dump_sql.php b/dump_sql.php index 5f10290..d0346f6 100755 --- a/dump_sql.php +++ b/dump_sql.php @@ -1,7 +1,7 @@ #!/usr/bin/php img_link($this->internal_url("barcode/$barcode"),$this->internal_url("barcode/$barcode"),$barcode,false,false,$opts); + return $this->img_link($this->internal_url("barcodeimg/$barcode"),$this->internal_url("barcodeimg/$barcode"),$barcode,false,false,$opts); } function table_add_barcodes(&$table) { - $image = array('model_barcode', 'item_serial'); + $image = array('barcode_name', 'model_barcode', 'item_serial'); foreach($table as $id => $row) { foreach($image as $column) if(isset($table[$id][$column])) { $table[$id][$column]=$this->render_barcode($table[$id][$column]); @@ -361,6 +361,7 @@ EOF; 'model' => array( 'model_id' => array(array('item',$where_url),array('edit','model/%v/edit/')), 'model_barcode' => array(array('store','assistant/%d?barcode=%v')), + 'barcode_name' => array(array('store','assistant/%d?barcode=%v')), 'model_name' => array(array('google','http://google.com/search?q=%v')) //TODO: add manufacturer to google query ), 'item' => array( @@ -451,7 +452,7 @@ EOF; function table_hide_columns(&$table, $class) { //TODO: Move to build_query_select() !!! :-))) $fields_hide = array( - 'item' => array('model_descript','model_price_in','model_price_out','model_barcode','model_countable','model_reserve','model_eshop_hide','room_descript','room_author','producer_name','producer_note','vendor_note','location_author','location_gps','location_description') + 'item' => array('model_descript','model_price_in','model_price_out','barcode_name','model_barcode','model_countable','model_reserve','model_eshop_hide','room_descript','room_author','producer_name','producer_note','vendor_note','location_author','location_gps','location_description') ); //print_r($table); die(); if(isset($fields_hide[$class])) foreach($table as $id => $row) { @@ -618,12 +619,13 @@ class Sklad_DB extends PDO { function build_query_select($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false, $order=false, $suffix_id='_id') { //Configuration $join = array( - 'item' => array('model', 'category', 'producer', 'vendor', 'room', 'location', 'status'), + 'barcode' => array('model', 'category', 'producer'), + 'item' => array('barcode', 'model', 'category', 'producer', 'vendor', 'room', 'location', 'status'), 'model' => array('category', 'producer') ); //TODO Autodetect using foreign keys? $fields_search = array( - 'item' => array('item_id','item_serial','model_name','model_barcode','model_descript','producer_name','vendor_name'), - 'model' => array('model_id','model_name','model_barcode','model_descript','producer_name') + 'item' => array('item_id','item_serial','model_name','barcode_name','model_barcode','model_descript','producer_name','vendor_name'), + 'model' => array('model_id','model_name','barcode_name','model_barcode','model_descript','producer_name') ); //TODO Autodetect //Init @@ -650,7 +652,7 @@ class Sklad_DB extends PDO { //ORDER if(!$order) $order = $class.$suffix_id.' DESC'; if($this->contains_history($class)) $order .= ",${class}_valid_from DESC"; - $sql .= "ORDER BY $order\n"; + //$sql .= "ORDER BY $order\n"; //TODO: fixnout az budou opraveny vicenasobny carovy kody //LIMIT/OFFSET if($limit) { $limit = $this->escape((int)$limit); @@ -976,6 +978,7 @@ class Sklad_UI { function check_input_validity($field, $value='', $ruleset=0) { $rules = array(0 => array( 'model_barcode' => '/./', + 'barcode_name' => '/./', 'item_serial' => '/./', 'vendor_id' => '/^[0-9]*$/' )); @@ -1061,7 +1064,7 @@ class Sklad_UI { $PATH_CHUNKS = preg_split('/\//', $PATH_INFO); //Sephirot: if(!isset($PATH_CHUNKS[1])) $PATH_CHUNKS[1]=''; - if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcode' && $PATH_CHUNKS[1]!='api') //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost... + if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcodeimg' && $PATH_CHUNKS[1]!='api') //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost... echo $this->html->header($PATH_INFO,$this->db->auth->get_user()); switch($PATH_CHUNKS[1]) { //TODO: Move some branches to plugins if possible case 'test': //test @@ -1079,7 +1082,7 @@ class Sklad_UI { $assistant_vars['ASSISTANT'] = $PATH_CHUNKS[2]; echo $this->safe_include($incdirs[$PATH_CHUNKS[1]],$PATH_CHUNKS[2],$assistant_vars); break; - case 'barcode': //barcode + case 'barcodeimg': //barcode Barcode::download_barcode(implode('/',array_slice($PATH_CHUNKS, 2))); break; default: //? diff --git a/install.sql b/install.sql index 9efd44a..8c238cc 100644 --- a/install.sql +++ b/install.sql @@ -1,8 +1,8 @@ --- MySQL dump 10.13 Distrib 5.1.49, for debian-linux-gnu (x86_64) +-- MySQL dump 10.13 Distrib 5.1.61, for debian-linux-gnu (x86_64) -- -- Host: localhost Database: sklad -- ------------------------------------------------------ --- Server version 5.1.49-3 +-- Server version 5.1.61-0+squeeze1 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -80,7 +80,7 @@ CREATE TABLE `location` ( PRIMARY KEY (`location_id`), UNIQUE KEY `location_name` (`location_name`), KEY `location_author` (`location_author`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -89,7 +89,7 @@ CREATE TABLE `location` ( LOCK TABLES `location` WRITE; /*!40000 ALTER TABLE `location` DISABLE KEYS */; -INSERT INTO `location` VALUES (0,'UNIVERSE',14,'Tady je všechno co nikde neni :-)'); +INSERT INTO `location` VALUES (0,'UNIVERSE',14,'Tady je všechno co nikde neni :-)'),(4,'aaatest',0,''); /*!40000 ALTER TABLE `location` ENABLE KEYS */; UNLOCK TABLES; @@ -230,7 +230,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2012-04-11 19:25:14 +-- Dump completed on 2012-07-24 15:03:20 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -247,7 +247,7 @@ DROP TABLE IF EXISTS `item`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `item` ( `item_id` int(11) NOT NULL AUTO_INCREMENT, - `model_id` int(11) NOT NULL, + `barcode_id` int(11) NOT NULL, `vendor_id` int(11) NOT NULL, `item_serial` varchar(128) COLLATE utf8_czech_ci NOT NULL, `item_quantity` int(11) NOT NULL DEFAULT '1', @@ -266,16 +266,14 @@ CREATE TABLE `item` ( PRIMARY KEY (`item_id`,`item_valid_till`), UNIQUE KEY `item_serial_item_valid_till` (`item_serial`,`item_valid_till`), KEY `vendor_id` (`vendor_id`), - KEY `model_id` (`model_id`), KEY `status_id` (`status_id`), KEY `room_id` (`room_id`), KEY `location_id` (`location_id`), CONSTRAINT `item_ibfk_10` FOREIGN KEY (`location_id`) REFERENCES `location` (`location_id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `item_ibfk_6` FOREIGN KEY (`vendor_id`) REFERENCES `vendor` (`vendor_id`), - CONSTRAINT `item_ibfk_7` FOREIGN KEY (`model_id`) REFERENCES `model` (`model_id`), CONSTRAINT `item_ibfk_8` FOREIGN KEY (`status_id`) REFERENCES `status` (`status_id`), CONSTRAINT `item_ibfk_9` FOREIGN KEY (`room_id`) REFERENCES `room` (`room_id`) -) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; +) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; /*!40101 SET character_set_client = @saved_cs_client */; DROP TABLE IF EXISTS `model`; /*!40101 SET @saved_cs_client = @@character_set_client */; @@ -300,6 +298,18 @@ CREATE TABLE `model` ( CONSTRAINT `model_ibfk_2` FOREIGN KEY (`producer_id`) REFERENCES `producer` (`producer_id`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; /*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS `barcode`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `barcode` ( + `barcode_id` int(11) NOT NULL AUTO_INCREMENT, + `model_id` int(11) NOT NULL, + `barcode_name` varchar(128) COLLATE utf8_czech_ci NOT NULL, + PRIMARY KEY (`barcode_id`), + KEY `model_id` (`model_id`), + CONSTRAINT `barcode_ibfk_1` FOREIGN KEY (`model_id`) REFERENCES `model` (`model_id`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; +/*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -- 2.30.2