Skip to content

Commit

Permalink
Merge pull request #320 from leon-mbs/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
leon-mbs authored Jun 11, 2022
2 parents c41a488 + edabc59 commit 3c2ea03
Show file tree
Hide file tree
Showing 68 changed files with 918 additions and 367 deletions.
1 change: 0 additions & 1 deletion db/update/archive/temp.sql

This file was deleted.

137 changes: 64 additions & 73 deletions db/db.sql → mysqldb/db.sql

Large diffs are not rendered by default.

File renamed without changes.
Empty file added mysqldb/update/archive/temp.sql
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
73 changes: 73 additions & 0 deletions mysqldb/update/update610to620.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@


ALTER TABLE `item_set` ADD `service_id` INT NULL , ADD `cost` DECIMAL(10,2) NULL ;


DROP VIEW item_set_view ;

CREATE

VIEW item_set_view
AS
SELECT
`item_set`.`set_id` AS `set_id`,
`item_set`.`item_id` AS `item_id`,
`item_set`.`pitem_id` AS `pitem_id`,
`item_set`.`qty` AS `qty`,
`item_set`.`service_id` AS `service_id`,
`item_set`.`cost` AS `cost`,
`items`.`itemname` AS `itemname`,
`items`.`item_code` AS `item_code`,
`services`.`service_name` AS `service_name`
FROM ((`item_set`
LEFT JOIN `items`
ON (((`item_set`.`item_id` = `items`.`item_id`)
AND (`items`.`disabled` <> 1))))
LEFT JOIN `services`
ON (((`item_set`.`service_id` = `services`.`service_id`)
AND (`services`.`disabled` <> 1))));


ALTER TABLE `documents` ADD `lastupdate` DATETIME NULL;

DROP VIEW documents_view ;
CREATE VIEW documents_view
AS
SELECT
`d`.`document_id` AS `document_id`,
`d`.`document_number` AS `document_number`,
`d`.`document_date` AS `document_date`,
`d`.`user_id` AS `user_id`,
`d`.`content` AS `content`,
`d`.`amount` AS `amount`,
`d`.`meta_id` AS `meta_id`,
`u`.`username` AS `username`,
`c`.`customer_id` AS `customer_id`,
`c`.`customer_name` AS `customer_name`,
`d`.`state` AS `state`,
`d`.`notes` AS `notes`,
`d`.`payamount` AS `payamount`,
`d`.`payed` AS `payed`,
`d`.`parent_id` AS `parent_id`,
`d`.`branch_id` AS `branch_id`,
`b`.`branch_name` AS `branch_name`,
`d`.`firm_id` AS `firm_id`,
`d`.`priority` AS `priority`,
`f`.`firm_name` AS `firm_name`,
`d`.`lastupdate` AS `lastupdate`,
`metadata`.`meta_name` AS `meta_name`,
`metadata`.`description` AS `meta_desc`
FROM (((((`documents` `d`
LEFT JOIN `users_view` `u`
ON ((`d`.`user_id` = `u`.`user_id`)))
LEFT JOIN `customers` `c`
ON ((`d`.`customer_id` = `c`.`customer_id`)))
JOIN `metadata`
ON ((`metadata`.`meta_id` = `d`.`meta_id`)))
LEFT JOIN `branches` `b`
ON ((`d`.`branch_id` = `b`.`branch_id`)))
LEFT JOIN `firms` `f`
ON ((`d`.`firm_id` = `f`.`firm_id`)));


ALTER TABLE `ppo_zformstat` ADD `fiscnumber` VARCHAR(255) NULL ;
28 changes: 21 additions & 7 deletions pgsqldb/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ CREATE TABLE documents (
branch_id INTEGER DEFAULT '0',
parent_id INTEGER DEFAULT '0',
firm_id INTEGER DEFAULT NULL,
lastupdate TIMESTAMP DEFAULT NULL,
priority SMALLINT DEFAULT '100',
CONSTRAINT PK_documents PRIMARY KEY (document_id),
CONSTRAINT documents_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (user_id)
Expand Down Expand Up @@ -439,9 +440,11 @@ CREATE TABLE item_cat (

CREATE TABLE item_set (
set_id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
item_id INT DEFAULT 0,
pitem_id INT DEFAULT 0,
qty DECIMAL(11, 3) DEFAULT 0.000,
item_id INT DEFAULT NULL,
service_id INT DEFAULT NULL,
pitem_id INT NOT NULL,
qty DECIMAL(11, 3) DEFAULT NULL,
cost DECIMAL(10, 2) DEFAULT NULL,
CONSTRAINT PK_item_set PRIMARY KEY (set_id)
);

Expand Down Expand Up @@ -869,6 +872,7 @@ SELECT
d.payed AS payed,
d.parent_id AS parent_id,
d.branch_id AS branch_id,
d.lastupdate AS lastupdate,
b.branch_name AS branch_name,
d.firm_id AS firm_id,
d.priority AS priority,
Expand Down Expand Up @@ -1162,18 +1166,28 @@ FROM (items

CREATE

VIEW item_set_view
AS
CREATE
VIEW item_set_view
AS
SELECT
item_set.set_id AS set_id,
item_set.item_id AS item_id,
item_set.pitem_id AS pitem_id,
item_set.qty AS qty,
item_set.service_id AS service_id,
item_set.cost AS cost,
items.itemname AS itemname,
items.item_code AS item_code
FROM (item_set
JOIN items
ON ((item_set.item_id = items.item_id)));
items.item_code AS item_code,
services.service_name AS service_name
FROM ((item_set
LEFT JOIN items
ON (((item_set.item_id = items.item_id)
AND (items.disabled <> 1))))
LEFT JOIN services
ON (((item_set.service_id = services.service_id)
AND (services.disabled <> 1))));

CREATE

Expand Down
1 change: 0 additions & 1 deletion pgsqldb/update/temp.sql

This file was deleted.

71 changes: 71 additions & 0 deletions pgsqldb/update/update610to620.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ALTER TABLE ppo_zformstat ADD fiscnumber CHARACTER VARYING(255) NULL ;
ALTER TABLE item_set ADD service_id INTEGER DEFAULT NULL ;
ALTER TABLE item_set ADD cost DECIMAL(10, 2) DEFAULT NULL ;




ALTER
VIEW item_set_view
AS
SELECT
item_set.set_id AS set_id,
item_set.item_id AS item_id,
item_set.pitem_id AS pitem_id,
item_set.qty AS qty,
item_set.service_id AS service_id,
item_set.cost AS cost,
items.itemname AS itemname,
items.item_code AS item_code,
services.service_name AS service_name
FROM ((item_set
LEFT JOIN items
ON (((item_set.item_id = items.item_id)
AND (items.disabled <> 1))))
LEFT JOIN services
ON (((item_set.service_id = services.service_id)
AND (services.disabled <> 1))));


ALTER TABLE documents ADD lastupdate TIMESTAMP NULL;




ALTER VIEW documents_view
AS
SELECT
d.document_id AS document_id,
d.document_number AS document_number,
d.document_date AS document_date,
d.user_id AS user_id,
d.content AS content,
d.amount AS amount,
d.meta_id AS meta_id,
u.username AS username,
c.customer_id AS customer_id,
c.customer_name AS customer_name,
d.state AS state,
d.notes AS notes,
d.payamount AS payamount,
d.payed AS payed,
d.parent_id AS parent_id,
d.branch_id AS branch_id,
b.branch_name AS branch_name,
d.firm_id AS firm_id,
d.priority AS priority,
d.lastupdate AS lastupdate,
f.firm_name AS firm_name,
metadata.meta_name AS meta_name,
metadata.description AS meta_desc
FROM (((((documents d
LEFT JOIN users_view u
ON ((d.user_id = u.user_id)))
LEFT JOIN customers c
ON ((d.customer_id = c.customer_id)))
JOIN metadata
ON ((metadata.meta_id = d.meta_id)))
LEFT JOIN branches b
ON ((d.branch_id = b.branch_id)))
LEFT JOIN firms f
ON ((d.firm_id = f.firm_id)));
156 changes: 88 additions & 68 deletions www/app/api/base/restful.php
Original file line number Diff line number Diff line change
@@ -1,93 +1,113 @@
<?php

namespace App\API\Base;
namespace App\API;

/**
* Base class for RESTFul
*/
abstract class RestFul
{

/**
*
*
* @param array $params
*/
public function Execute($params) {

if ($_SERVER["REQUEST_METHOD"] == "GET") {
$this->get($params);
};
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->post($params);
};
if ($_SERVER["REQUEST_METHOD"] == "DELETE") {
$this->delete($params);
};
if ($_SERVER["REQUEST_METHOD"] == "PUT") {
$this->put($params);
};
}

/**
* @param array $params
*/
public function get($params) {
$this->FailAnswer();
}

/**
* @param array $params
*/
public function post($params) {
$this->FailAnswer();
}

/**
* @param array $params
*/
public function put($params) {
$this->FailAnswer();
}

/**
* @param array $params
*/
public function delete($params) {
$this->FailAnswer();
}



protected function JsonAnswer($json) {
header("Content-type: application/json");
$this->headers();
header("Content-type: application/json");
http_response_code(200);
echo $json;
die;
}

protected function XMLAnswer($xml) {
header("Content-type: text/xml");
echo $xml;
http_response_code(200);
}

protected function CSVAnswer($csv) {
header("Content-type: text/csv");
http_response_code(200);
echo $csv;
}


protected function TextAnswer($text) {
header("Content-type: text/plain");
$this->headers();
header("Content-type: text/plain");
http_response_code(200);
echo $text;
die;
}


protected function OKAnswer() {
http_response_code(200);
$this->headers();

http_response_code(200);
die;
}

protected function FailAnswer() {
http_response_code(400);
protected function FailAnswer($error="") {
$this->headers(400);

echo $error;
die;
}

protected function code401() {
$this->headers(401);

die;
}

protected function code403() {
$this->headers(403);

die;
}
private function headers($code=200){
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
http_response_code(200);
else
http_response_code($code);


}
protected function checkAcess() {


$jwt = "";
$headers = apache_request_headers();
foreach ($headers as $header => $value) {


if ( strtolower($header) == "authorization") {
$jwt = str_replace("Bearer ", "", $value);
$jwt = trim($jwt);
break;
}
}

$key = "defkey";
try{
$decoded = \Firebase\JWT\JWT::decode($jwt, $key, array('HS256'));
} catch(\Exception $e) {
$this->FailAnswer($e->getMessage());
}


if($decoded->user_id >0) {

//$user = \App\Entity\User::load($decoded->user_id);
// if($user== null) $this->code401();
return $decoded->user_id;
} else {
$this->code401();

}

}


protected function parsePost($post){
if($post==null) $this->FailAnswer("Must be POST request") ;

$post = json_decode($post) ;

if($post==null) $this->FailAnswer("Invalid JSON") ;

return $post;

}
}
Loading

0 comments on commit 3c2ea03

Please sign in to comment.