Add php files

This commit is contained in:
2025-05-12 15:44:39 +00:00
parent c951760058
commit 82d5804ac4
9534 changed files with 2638137 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<?php
class FileHandler{
public $target_dir='upload/';
public $input_name='fileToUpload';
public $target_file;
public $orginal_file;
public $file_id;
public $file_date;
public function __construct(){
$this->file_id=create_guid();
$this->target_file=$this->target_dir.basename($this->file_id.'.xls');
$this->orginal_file=$_FILES[$this->input_name]["name"];
}
public function uploadFile(){
if (move_uploaded_file($_FILES[$this->input_name]["tmp_name"], $this->target_file)) {
$this->file_date= date ("Y-m-d H:i:s", filemtime($this->target_file));
return true;
} else {
return false;
}
}
}
?>

View File

@@ -0,0 +1,60 @@
<?php
class Order{
public $id;
public $product_id;
public $parent_id;
public $purchase_price;
public $sell_price;
public $sell_quantity;
public $buy_quantity;
public $date;
public $file_id;
public $file_name;
public $file_date;
public $user_id;
public function __construct(){
global $current_user;
$this->id = create_guid();
$this->user_id=$current_user->id;
}
public function setProductId($string){
$product_name = explode(" ",$string);
$product = new EcmProduct();
$product->retrieve_by_string_fields(['code'=>$product_name[1]]);
$this->product_id=$product->id;
$this->purchase_price=$product->price_msh;
}
public function getPrice(){
$query="select c.price_brutto from ecminvoiceoutitems c
inner join ecminvoiceouts i on i.id=c.ecminvoiceout_id
inner join accounts a on a.id= i.parent_id
where c.ecmproduct_id='".$this->product_id."' and a.parent_id=1249 and i.deleted=0 and i.canceled=0 order by i.date_entered desc limit 1";
$res=$GLOBALS['db']->query($query);
$files = [];
$dane=$GLOBALS['db']->fetchByAssoc($res);
$this->sell_price=$dane['price_brutto'];
}
public function setParentId($string){
$parent = explode(" ",$string);
$account = new Account();
$account->retrieve_by_string_fields(['shop_number'=>substr($parent[0],0,4)]);
$this->parent_id=$account->id;
}
}
?>

View File

@@ -0,0 +1,105 @@
<?php
class ProductFactory{
public $rows;
public $purchase_price;
public $sell_price;
public $product_name;
public $date;
public $fileHandler;
static private $_objectCount=0;
public function __construct($rows,$date,FileHandler $fileHandler){
$this->rows=$rows;
$this->date;
$this->fileHandler=$fileHandler;
}
public function createProducts(){
foreach ($this->rows as $row){
$data =substr($row[1],0,10);
if($data=='Sprzedaz: '){
$this->date=date("Y-m-d 00:00:01",strtotime(substr($row[1],9,12)));
}
if($row[1]=='Artykul')continue;
if($row[2]=='Suma:')continue;
if($row[1]!="" && $row[2]=="" && $row[3]=="" && $row[4]==""){
continue;
}
if($row[1]!="" && $row[2]!="" && $row[3]!="" && $row[4]!=""){
$this->product_name=$row[1];
$this->purchase_price=$row[5];
$this->sell_price=$row[6];
}
$order = new Order();
$order->setProductId($this->product_name);
$order->setParentId($row[2]);
$order->sell_quantity=$row[3];
$order->buy_quantity=$row[4];
$order->getPrice();
$order->date=$this->date;
$order->file_id=$this->fileHandler->file_id;
$order->file_name=$this->fileHandler->orginal_file;
$order->file_date=$this->fileHandler->file_date;
$this->saveProduct($order);
self::$_objectCount++;
}
}
static public function getObjectCount()
{
return self::$_objectCount;
}
public function saveProduct($product){
$fields=[];
$values=[];
$types=[];
$type='s';
$types="";
foreach ($product as $key=>$value){
$fields[]= $key;
$values[]=$value;
$types.=$type;
}
$this->insert($types,'orders',$fields,$values);
}
public function SqlArrayReferenceValues(&$rawArray){
$refArray = array();
foreach($rawArray as $key => $value)
{
$refArray[$key] = &$rawArray[$key];
}
return $refArray;
}
public function insert($setType, $setTable, $setRow, $setValues) {
$change = function($values) {
return "?";
};
$row = join(",", $setRow);
$done = join(",", array_map($change, $setValues));
$insert = $GLOBALS['db']->database->prepare("INSERT INTO $setTable ($row) VALUES ($done)");
$params = $setValues;
$ww = array_merge(array($setType), $params);
call_user_func_array(array($insert, "bind_param"), $this->SqlArrayReferenceValues($ww));
$insert->execute();
$insert->close();
return $insert;
}
}
?>

View File

@@ -0,0 +1,24 @@
<?php
require_once ('include/spreadsheet-reader-master/php-excel-reader/excel_reader2.php');
require_once ('include/spreadsheet-reader-master/SpreadsheetReader.php');
class XlsReader {
public $reader;
public function __construct($file) {
$this->reader = new SpreadsheetReader ( $file );
$this->reader-> ChangeSheet(1);
}
public function getArray(){
$rows = [];
foreach ( $this->reader as $row ) {
$rows[]=$row;
}
return $rows;
}
}
?>