| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- require_once("DataBase/database.php");
- require_once("DataBase/Customer.php");
- require_once("DataBase/Bill.php");
- require_once("DataBase/Product.php");
- require_once("DataBase/Price.php");
- require_once("DataBase/Tax.php");
- class Bill_Product_Import
- {
- function Bill_Product_Import()
- {
- $this->db = new Database();
- }
- function create($value)
- {
- $query = "INSERT INTO ".$this->db->bill_product_import_table." VALUES(''";
- for($i = 0; $i < count($value); $i++)
- $query .= ", '".$value[$i]."'";
- $query .= ")";
- $this->db->query($query);
- }
- function delete($bill_product_id)
- {
- $query = "DELETE FROM ".$this->db->bill_product_import_table." WHERE bill_product_id='$bill_product_id'";
- $this->db->query($query);
- }
- function get($bill_product_id = "", $row_names = array(), $search = "")
- {
- if($bill_product_id == "")
- {
- if(count($row_names) == 0)
- $query = "SELECT * FROM ".$this->db->bill_product_import_table;
- else
- {
- $query = "SELECT ".$row_names[0];
- for($i = 1; $i < count($row_names); $i++)
- $query .= ", ".$row_names[$i];
- $query .= " FROM ".$this->db->bill_product_import_table;
- }
- if($search != "")
- $query .= " WHERE ".$search;
- $query .= " ORDER BY product_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->bill_product_import_table." WHERE bill_product_id='".$bill_product_id."'";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function getByBillId($bill_id)
- {
- $query = "SELECT * FROM ".$this->db->bill_product_import_table." WHERE bill_id='".$bill_id."'";
- $query .= " ORDER BY product_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- function clearTable()
- {
- $query = "TRUNCATE TABLE ".$this->db->bill_product_import_table;
- $this->db->query($query);
- }
- function hasTimestampProductPair($timestamp, $product_id)
- {
- $query = "SELECT * FROM ".$this->db->bill_product_import_table." WHERE timestamp='".$timestamp."' and product_id='".$product_id."'";
- if(count($this->db->fetchRows($this->db->query($query))) > 0)
- return True;
- else
- return False;
- }
- function import($path)
- {
- $file_access_ok = true;
- $file_open = false;
- $file_handle = false;
- $data = "";
- clearstatcache();
- try
- {
- if (!$file_handle = @fopen($path, "r"))
- return -1;
- if($file_handle)
- {
- while( $zeile = fgets($file_handle, 1024))
- {
- $values = explode("|", $zeile);
- for($i = 0; $i < count($values); $i++)
- $values[$i] = trim($values[$i]);
- if(!$this->hasTimestampProductPair($values[8], $values[2]))
- $this->create(array( $values[1],
- $values[2],
- $values[3],
- $values[4],
- $values[5],
- $values[6],
- $values[7],
- $values[8]));
- }
- fclose($file_handle);
- }
- return 0;
- }
- catch (Exception $e)
- {
- return -1;
- }
- }
- }
- ?>
|