v.2.27
Fixed reports
This commit is contained in:
73
models/Base.php
Normal file
73
models/Base.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Component\Models;
|
||||
|
||||
class Base
|
||||
{
|
||||
public static function tofloat($num) {
|
||||
$dotPos = strrpos($num, '.');
|
||||
$commaPos = strrpos($num, ',');
|
||||
$sep = (($dotPos > $commaPos) && $dotPos) ? $dotPos :
|
||||
((($commaPos > $dotPos) && $commaPos) ? $commaPos : false);
|
||||
|
||||
if (!$sep) {
|
||||
return floatval(preg_replace("/[^0-9]/", "", $num));
|
||||
}
|
||||
|
||||
return floatval(
|
||||
preg_replace("/[^0-9]/", "", substr($num, 0, $sep)) . '.' .
|
||||
preg_replace("/[^0-9]/", "", substr($num, $sep+1, strlen($num)))
|
||||
);
|
||||
}
|
||||
|
||||
public static function validate_json($string)
|
||||
{
|
||||
// decode the JSON data
|
||||
$result = json_decode(utf8_encode($string), true, JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
|
||||
// switch and check possible JSON errors
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
$error = ''; // JSON is valid // No error has occurred
|
||||
break;
|
||||
case JSON_ERROR_DEPTH:
|
||||
$error = 'The maximum stack depth has been exceeded.';
|
||||
break;
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
$error = 'Invalid or malformed JSON.';
|
||||
break;
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
$error = 'Control character error, possibly incorrectly encoded.';
|
||||
break;
|
||||
case JSON_ERROR_SYNTAX:
|
||||
$error = 'Syntax error, malformed JSON.';
|
||||
break;
|
||||
// PHP >= 5.3.3
|
||||
case JSON_ERROR_UTF8:
|
||||
$error = 'Malformed UTF-8 characters, possibly incorrectly encoded.';
|
||||
break;
|
||||
// PHP >= 5.5.0
|
||||
case JSON_ERROR_RECURSION:
|
||||
$error = 'One or more recursive references in the value to be encoded.';
|
||||
break;
|
||||
// PHP >= 5.5.0
|
||||
case JSON_ERROR_INF_OR_NAN:
|
||||
$error = 'One or more NAN or INF values in the value to be encoded.';
|
||||
break;
|
||||
case JSON_ERROR_UNSUPPORTED_TYPE:
|
||||
$error = 'A value of a type that cannot be encoded was given.';
|
||||
break;
|
||||
default:
|
||||
$error = 'Unknown JSON error occured.';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($error !== '') {
|
||||
// throw the Exception or exit // or whatever :)
|
||||
return false;
|
||||
}
|
||||
|
||||
// everything is OK
|
||||
return true;
|
||||
}
|
||||
}
|
||||
104
models/Cache.php
Normal file
104
models/Cache.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Component\Models;
|
||||
|
||||
class Cache
|
||||
{
|
||||
public static function get($code, $plugin, $input)
|
||||
{
|
||||
unset($input['ip']);
|
||||
unset($input['token']);
|
||||
unset($input['admin_user_id']);
|
||||
unset($input['host']);
|
||||
$method = $input['method_name'];
|
||||
unset($input['method_name']);
|
||||
$dirname = CORE_PATH . '/../../Cache/' . $code . '/' . $plugin . '/';
|
||||
if (!is_dir($dirname)) {
|
||||
mkdir($dirname, 0777);
|
||||
}
|
||||
$filename = $method . ".tmp";
|
||||
if (file_exists($dirname . $filename)) {
|
||||
$caches = json_decode(file_get_contents($dirname . $filename), true);
|
||||
foreach ($caches as $key => $cache) {
|
||||
if ($cache['input'] == $input) {
|
||||
return $cache['result'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function store($code, $plugin, $input, $result)
|
||||
{
|
||||
unset($input['ip']);
|
||||
unset($input['token']);
|
||||
unset($input['admin_user_id']);
|
||||
unset($input['host']);
|
||||
$method = $input['method_name'];
|
||||
unset($input['method_name']);
|
||||
$data = [];
|
||||
$info = array('input' => $input, 'result' => $result);
|
||||
array_push($data, $info);
|
||||
$dirname = CORE_PATH . '/../../Cache/' . $code . '/' . $plugin . '/';
|
||||
if (!is_dir($dirname)) {
|
||||
mkdir($dirname, 0777);
|
||||
}
|
||||
$filename = $method . ".tmp";
|
||||
if (!file_exists($dirname . $filename)) {
|
||||
$handle = fopen($dirname . $filename, 'w');
|
||||
fputs($handle, json_encode($data));
|
||||
fclose($handle);
|
||||
return $result;
|
||||
} else {
|
||||
$handle = fopen($dirname . $filename, 'r');
|
||||
$caches = fgets($handle);
|
||||
fclose($handle);
|
||||
$caches = json_decode($caches, true);
|
||||
foreach ($caches as $key => $cache) {
|
||||
if ($cache == $info) {
|
||||
return $info['result'];
|
||||
} else {
|
||||
array_push($caches, $info);
|
||||
$handle = fopen($dirname . $filename, 'w');
|
||||
fputs($handle, json_encode($caches));
|
||||
fclose($handle);
|
||||
return $info['result'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function clear($code, $plugin, $input, $type)
|
||||
{
|
||||
$dirname = CORE_PATH . '/../../Cache/' . $code . '/' . $plugin . '/';
|
||||
if ($type == 'single') {
|
||||
$method = $input['method_name'];
|
||||
if (is_dir($dirname)) {
|
||||
$filename = $method . ".tmp";
|
||||
if (file_exists($dirname . $filename)) {
|
||||
unlink($dirname . $filename);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($type == 'full') {
|
||||
$files = glob($dirname."/*");
|
||||
if (count($files) > 0) {
|
||||
foreach ($files as $file) {
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,20 @@ namespace App\Component\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Client extends Model {
|
||||
protected $table = 'clients';
|
||||
class Client extends Model
|
||||
{
|
||||
protected $table = 'clients';
|
||||
|
||||
/**
|
||||
* Get clients phone.
|
||||
*/
|
||||
public function clientPhone() {
|
||||
return $this->belongsTo('App\Component\Models\ClientsPhone', 'user_code', 'client_guid');
|
||||
}
|
||||
/**
|
||||
* Get clients phone.
|
||||
*/
|
||||
public function clientPhone()
|
||||
{
|
||||
return $this->belongsTo('App\Component\Models\ClientsPhone', 'user_code', 'client_guid');
|
||||
}
|
||||
|
||||
public static function getPhone($guid) {
|
||||
public static function getPhone($guid)
|
||||
{
|
||||
$phone = ClientsPhone::where('client_guid', $guid)->first();
|
||||
if (isset($phone)) {
|
||||
$phone = $phone['phone'];
|
||||
@@ -24,7 +27,8 @@ class Client extends Model {
|
||||
return $phone;
|
||||
}
|
||||
|
||||
public static function getEmail($guid) {
|
||||
public static function getEmail($guid)
|
||||
{
|
||||
$email = ClientsEmail::where('client_guid', $guid)->first();
|
||||
if (isset($email)) {
|
||||
$email = $email['email'];
|
||||
@@ -34,7 +38,8 @@ class Client extends Model {
|
||||
return $email;
|
||||
}
|
||||
|
||||
public static function getAddress($guid) {
|
||||
public static function getAddress($guid)
|
||||
{
|
||||
$address = ClientsAddress::where('client_guid', $guid)->first();
|
||||
if (isset($address)) {
|
||||
$address = $address['address'];
|
||||
@@ -44,17 +49,19 @@ class Client extends Model {
|
||||
return $address;
|
||||
}
|
||||
|
||||
public static function getBarcode($guid) {
|
||||
$barcode = ClientsBarcode::where('client_guid', $guid)->first();
|
||||
public static function getBarcode($guid)
|
||||
{
|
||||
$barcode = Client::where('user_code', $guid)->first();
|
||||
if (isset($barcode)) {
|
||||
$barcode = $barcode['value'];
|
||||
$barcode = $barcode['barcode_start'];
|
||||
} else {
|
||||
$barcode = '';
|
||||
}
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
public static function getID($guid) {
|
||||
public static function getID($guid)
|
||||
{
|
||||
$id = Client::where('client_guid', $guid)->first();
|
||||
if (isset($id)) {
|
||||
$id = $id['id'];
|
||||
@@ -64,4 +71,16 @@ class Client extends Model {
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function getName($guid)
|
||||
{
|
||||
$client_name = Client::where('user_code', $guid)
|
||||
->first();
|
||||
if (isset($client_name)) {
|
||||
$client_name = $client_name['name'];
|
||||
} else {
|
||||
$client_name = 'Связанный персонал не найден';
|
||||
}
|
||||
return $client_name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,4 +6,14 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ClientsGroup extends Model {
|
||||
protected $table = 'client_groups';
|
||||
|
||||
public static function getID($guid) {
|
||||
$id = ClientsGroup::where('code', $guid)->first();
|
||||
if (isset($id)) {
|
||||
$id = $id['id'];
|
||||
} else {
|
||||
$id = 0;
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
@@ -46,20 +46,44 @@ class ClientsPresale extends Model
|
||||
/**
|
||||
* Presale log.
|
||||
*/
|
||||
public static function presaleLog($guid, $value, $time, $staff_id)
|
||||
public static function presaleLog($guid, $value, $time, $staff_id, $type, $order_id)
|
||||
{
|
||||
if ($value > 0) {
|
||||
$action_name = 'Внесение аванса';
|
||||
} else {
|
||||
$action_name = 'Зачет аванса';
|
||||
$action_type = $type;
|
||||
if ($action_type == 21) {
|
||||
$action_name = 'Поступил предварительный платеж через скидку в размере ' . $value . ' BYN через заказ №' . $order_id;
|
||||
}
|
||||
if ($action_type == 11) {
|
||||
$action_name = 'Поступил предварительный платеж наличными в размере ' . $value . ' BYN';
|
||||
}
|
||||
if ($action_type == 13) {
|
||||
$action_name = 'Поступил предварительный платеж безналичными в размере ' . $value . ' BYN';
|
||||
}
|
||||
if ($action_type == 12) {
|
||||
$action_name = 'Поступил предварительный платеж кредитной картой в размере ' . $value . ' BYN';
|
||||
}
|
||||
if ($action_type == 14) {
|
||||
$action_name = 'Возврат предварительного платежа наличными в размере ' . $value . ' BYN';
|
||||
}
|
||||
if ($action_type == 16) {
|
||||
$action_name = 'Возврат предварительного платежа безналичными в размере ' . $value . ' BYN';
|
||||
}
|
||||
if ($action_type == 15) {
|
||||
$action_name = 'Возврат предварительного платежа кредитной картой в размере ' . $value . ' BYN';
|
||||
}
|
||||
if ($action_type == 2) {
|
||||
$action_name = 'Зачтен предварительный платеж в размере ' . $value . ' BYN через заказ №' . $order_id;
|
||||
}
|
||||
|
||||
|
||||
$action = new ClientsActions();
|
||||
$action->action = $action_name;
|
||||
$action->created = Carbon::createFromTimestampUTC($time)->timezone('Europe/Minsk');
|
||||
$action->user_id = $guid;
|
||||
$action->action_value = abs($value);
|
||||
$action->action_type = 2;
|
||||
$action->action_type = $action_type;
|
||||
$action->order_id = $order_id;
|
||||
$action->who = $staff_id;
|
||||
$action->save();
|
||||
return $action_name;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,19 @@ class Dishes extends Model {
|
||||
$dish_name = 'Связанный товар удален';
|
||||
}
|
||||
}
|
||||
if ($dish_name == 'Связанный товар удален') {
|
||||
$dish_name = Dishes::where('legacy_code', $data)->where('is_history', 0)->first();
|
||||
if ($dish_name) {
|
||||
$dish_name = $dish_name['name'];
|
||||
} else {
|
||||
$dish_name = Dishes::where('legacy_code', $data)->where('is_history', 1)->first();
|
||||
if ($dish_name) {
|
||||
$dish_name = $dish_name['name'];
|
||||
} else {
|
||||
$dish_name = 'Связанный товар удален';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $dish_name;
|
||||
}
|
||||
|
||||
@@ -59,4 +72,19 @@ class Dishes extends Model {
|
||||
}
|
||||
return $isServing;
|
||||
}
|
||||
|
||||
public static function GetPrinterCode($data) {
|
||||
$dish = Dishes::where('legacy_code', $data)->where('is_history', 0)->first();
|
||||
if ($dish) {
|
||||
$printer_code = $dish['printer_code'];
|
||||
} else {
|
||||
$dish = Dishes::where('legacy_code', $data)->where('is_history', 1)->first();
|
||||
if ($dish) {
|
||||
$printer_code = $dish['printer_code'];
|
||||
} else {
|
||||
$printer_code = 0;
|
||||
}
|
||||
}
|
||||
return $printer_code;
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ExchangeActions extends Model {
|
||||
protected $table = 'exchange_actions';
|
||||
|
||||
|
||||
}
|
||||
@@ -6,4 +6,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ExchangeDeleted extends Model {
|
||||
protected $table = 'exchange_deleted';
|
||||
|
||||
public function deletedActions() {
|
||||
return $this->hasMany('App\Component\Models\ExchangeActions', 'order_position', 'item_id')
|
||||
->where('exchange_actions.action_type', '=', 5);
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class ExchangeOrders extends Model
|
||||
'cof' => $item['cof'],
|
||||
'unit' => Units::getName($item['units_id']),
|
||||
'amount' => round($item['sale_price'] * $item['count'], 2),
|
||||
'discount' => round($discount, 2)
|
||||
'discount' => round($discount)
|
||||
);
|
||||
$amount += round($item['sale_price'] * $item['count'], 2);
|
||||
$full_price += round($realPrice,2);
|
||||
|
||||
36
models/Filesystem.php
Normal file
36
models/Filesystem.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Component\Models;
|
||||
|
||||
|
||||
class Filesystem
|
||||
{
|
||||
public static function GetCode($token)
|
||||
{
|
||||
$code = json_decode(base64_decode(urldecode($token)), true);
|
||||
$unn = $code['unn'];
|
||||
if ($code == '') {
|
||||
$session_file = __DIR__ . "\\..\\..\\..\\Sessions\\" . $token . ".ini";
|
||||
$session_data = parse_ini_file($session_file);
|
||||
$unn = intval($session_data['unn']);
|
||||
}
|
||||
return $unn;
|
||||
}
|
||||
|
||||
public static function ClearFolder($dir)
|
||||
{
|
||||
$d = opendir($dir);
|
||||
while (($entry = readdir($d)) !== false) {
|
||||
if ($entry != "." && $entry != "..") {
|
||||
if (is_dir($dir . "/" . $entry)) {
|
||||
self::ClearFolder($dir . "/" . $entry);
|
||||
} else {
|
||||
unlink($dir . "/" . $entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($d);
|
||||
rmdir($dir);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,5 @@ namespace App\Component\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrderBot extends Model {
|
||||
protected $table = 'orderbot_storage';
|
||||
protected $table = 'order_bot';
|
||||
}
|
||||
9
models/OrderBotStorage.php
Normal file
9
models/OrderBotStorage.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Component\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrderBotStorage extends Model {
|
||||
protected $table = 'orderbot_storage';
|
||||
}
|
||||
@@ -12,4 +12,19 @@ class Printer extends Model {
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
public static function getName($data) {
|
||||
$printer_name = Printer::where('code', $data)->where('is_history', 0)->first();
|
||||
if ($printer_name) {
|
||||
$printer_name = $printer_name['name'];
|
||||
} else {
|
||||
$printer_name = Printer::where('code', $data)->where('is_history', 1)->first();
|
||||
if ($printer_name) {
|
||||
$printer_name = $printer_name['name'];
|
||||
} else {
|
||||
$printer_name = 'Связанный принтер удален';
|
||||
}
|
||||
}
|
||||
return $printer_name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class ShiftOnlineOrders extends Model
|
||||
'cof' => $item['cof'],
|
||||
'unit' => Units::getName($item['units_id']),
|
||||
'amount' => round($item['sale_price'] * $item['count'], 2),
|
||||
'discount' => round($discount, 0)
|
||||
'discount' => round($discount)
|
||||
);
|
||||
$amount += round($item['sale_price'] * $item['count'], 2);
|
||||
$full_price += round($realPrice,2);
|
||||
|
||||
Reference in New Issue
Block a user