Skip to content

Commit

Permalink
#33 , #32, #30
Browse files Browse the repository at this point in the history
  • Loading branch information
pihel committed May 6, 2015
1 parent 9fb27be commit ae4d460
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 67 deletions.
62 changes: 27 additions & 35 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
<?
/*
Проблемы:
1. Всегда видеть итоговую строку ???? не понятно как
2. формат для денежных полей (право, разделители, запятая) http://workblog.neteos.eu/270/javascript/extjs/extjs-numberfield-accepts-comma-and-keeps-precision-on-display
3. текст в прелоадерах (убрать стандартный)
13. проблема с подгрузкой скриптов в IE
14. сохранение настроек главного грида (баг - не сохранются настройки видимости, не сохраняется позиция actioncolumn)
*/
require_once('lib/init.php');
?>
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title><?=$settings['site_name'];?></title>
<link rel="shortcut icon" href="<?=$settings['static'];?>/favicon.png" />
<link href="<?=$settings['static'];?>/style.css?<?=$settings['version'];?>" media="all" rel="stylesheet" type="text/css" />
<link href="<?=$settings['extjs'];?>/resources/css/ext-all.css" media="all" rel="stylesheet" type="text/css" />
<link href="<?=$settings['extjs']?>/examples/ux/grid/css/GridFilters.css" rel="stylesheet" type="text/css" />
<link href="<?=$settings['extjs']?>/examples/ux/grid/css/RangeMenu.css" rel="stylesheet" type="text/css" />
<script src="<?=$settings['extjs'];?>/ext-all.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script language="javascript">
var settings = <? unset($settings['ocr']); echo json_encode($settings);?>;
var translate = <?=json_encode($lng->get(null));?>;
</script>
<script src="<?=$settings['static'];?>/js/script.js?<?=$settings['version'];?>" charset="UTF-8" type="text/javascript"></script>
<script src="<?=$settings['extjs'];?>/locale/ext-lang-<? if( $lng->slang == "us" ) echo "en"; else echo $lng->slang; ?>.js" charset="UTF-8" type="text/javascript"></script>
</head>
<body>
<div id="logout"></div>
<div id="main"></div>
<?=$settings['add'];?>
</body>
<?
require_once('lib/init.php');
?>
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title><?=$settings['site_name'];?></title>
<link rel="shortcut icon" href="<?=$settings['static'];?>/favicon.png" />
<link href="<?=$settings['static'];?>/style.css?<?=$settings['version'];?>" media="all" rel="stylesheet" type="text/css" />
<link href="<?=$settings['extjs'];?>/resources/css/ext-all.css" media="all" rel="stylesheet" type="text/css" />
<link href="<?=$settings['extjs']?>/examples/ux/grid/css/GridFilters.css" rel="stylesheet" type="text/css" />
<link href="<?=$settings['extjs']?>/examples/ux/grid/css/RangeMenu.css" rel="stylesheet" type="text/css" />
<script src="<?=$settings['extjs'];?>/ext-all.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script language="javascript">
var settings = <? unset($settings['ocr']); echo json_encode($settings);?>;
var translate = <?=json_encode($lng->get(null));?>;
</script>
<script src="<?=$settings['static'];?>/js/script.js?<?=$settings['version'];?>" charset="UTF-8" type="text/javascript"></script>
<script src="<?=$settings['extjs'];?>/locale/ext-lang-<? if( $lng->slang == "us" ) echo "en"; else echo $lng->slang; ?>.js" charset="UTF-8" type="text/javascript"></script>
</head>
<body>
<div id="logout"></div>
<div id="main"></div>
<?=$settings['add'];?>
</body>
</html>
3 changes: 2 additions & 1 deletion lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ class LangEn extends iLang {
224 => "Choose language",
225 => "Delete",
226 => "Access key to the recognition of checks",
227 => "Purchase map"
227 => "Purchase map",
228 => "Another"
);

}
3 changes: 2 additions & 1 deletion lang/ru.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class LangRu extends iLang {
224 => "Выберите язык",
225 => "Удалить",
226 => "Ключ доступа к распознаванию чеков",
227 => "Карта покупок"
227 => "Карта покупок",
228 => "Другое"
);

}
67 changes: 45 additions & 22 deletions lib/analiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ public function __construct($_db, $_usr, $_lng) {
global $settings;
$this->def_cur = $settings['sign'];
}

protected function reduce($arr, $col_amnt, $col_name) {
global $settings;
$proc = floatval( $settings['proc_analiz'] );
$ret = array();
$sum = 0;
foreach($arr as $k=>$v) {
$sum += $v[$col_amnt];
}
if($sum == 0) return $arr;

$stop_k = 0;
foreach($arr as $k=>$v) {
//if($k < $cnt) {
if( ($v[$col_amnt] / $sum) >= $proc ) {
$ret[] = $v;
$stop_k = $k;
} else {
$v[$col_name] = $this->lng->get(228);
$v[$col_amnt] += $ret[$stop_k+1][$col_amnt];
$ret[$stop_k+1] = $v;
}
}
return $ret;
} //reduce

public function getCommon($from, $to, $uid = 0) {
if(!$this->usr->canAnaliz()) return array();
Expand Down Expand Up @@ -108,7 +133,8 @@ public function getGroups($from, $to, $in = 0, $uid = 0) {
out_amount DESC";

$this->db->escape_res = true;
return $this->db->select($sql, $this->usr->db_id, intval($in), $from, $to, $uid, $uid);
//return $this->db->select($sql, $this->usr->db_id, intval($in), $from, $to, $uid, $uid);
return $this->reduce( $this->db->select($sql, $this->usr->db_id, intval($in), $from, $to, $uid, $uid), "out_amount", "tname" );
}

public function getGroupsDyn($from, $to, $gr = 0, $uid = 0) {
Expand All @@ -118,24 +144,14 @@ public function getGroupsDyn($from, $to, $gr = 0, $uid = 0) {
if(empty($to)) $to = date("Y-m-d");
$uid = intval($uid);

$sql =
"SELECT
replace(g.name, '.', ' ') name
FROM
`cashes_group` g
WHERE
EXISTS( SELECT
1
FROM
`cashes` c
WHERE
g.id = c.`group`
AND c.visible = 1 AND c.bd_id = ? AND c.type = 0
AND c.date BETWEEN ? AND ?
AND ( c.uid = ? OR 0 = ? )
) ";
$this->db->escape_res = true;
$grps = $this->db->select($sql, $this->usr->db_id, $from, $to, $uid, $uid);
//отсечем малозначащие группы
$grps = array();
$grps_v = array();
$grps_ = $this->getGroups($from, $to, 0, $uid);
foreach($grps_ as $g) {
$grps[]['name'] = $g['tname'];
$grps_v[] = $g['tname'];
}

$grps_key = $grps;
if($gr == 1) {
Expand Down Expand Up @@ -172,6 +188,8 @@ public function getGroupsDyn($from, $to, $gr = 0, $uid = 0) {
$i = -1;
$this->db->escape_res = true;
$data = $this->db->select($sql, $this->usr->db_id, $from, $to, $uid, $uid);

$other = $this->lng->get(228);
foreach($data as $d) {
if(empty($d['mname'])) continue;
if($m <> $d['mname']) {
Expand All @@ -181,9 +199,14 @@ public function getGroupsDyn($from, $to, $gr = 0, $uid = 0) {
$ret[$i]['name'] = $m;

}
$ret[$i][$d['tname']] = $d['out_amount'];
if(in_array($d['tname'], $grps_v)) {
$ret[$i][$d['tname']] += $d['out_amount'];
} else {
$ret[$i][$other] += $d['out_amount'];
}
} //foreach


return $ret;
}

Expand Down Expand Up @@ -221,7 +244,7 @@ public function getOrgs($from, $to, $gr = 0, $uid = 0) {
out_amount DESC";

$this->db->escape_res = true;
return $this->db->select($sql, $this->usr->db_id, $from, $to, $uid, $uid, $gr);
return $this->reduce( $this->db->select($sql, $this->usr->db_id, $from, $to, $uid, $uid, $gr), "out_amount", "tname" );
}

public function getPurs($from, $to, $in = 0, $uid = 0) {
Expand Down Expand Up @@ -380,7 +403,7 @@ public function getAvgInOut($uid = 0) {
SUM(c.price * c.qnt) as amount
FROM cashes c
WHERE
c.`date` >= DATETIME('now', '-11 month', 'start of month')
c.`date` >= DATETIME('now', '-6 month', 'start of month')
AND c.bd_id = ?
AND c.visible = 1
AND ( c.uid = ? OR 0 = ? )
Expand Down
17 changes: 11 additions & 6 deletions lib/cash.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,18 @@ public function del($id) {

protected function add_refbook($name, $ref) {
if(!$this->usr->canWrite()) return NULL;

if(intval($name) > 0) return $name;
$ref_id = 0;
$name = trim($name);
if(empty($name)) return 0;

$ref_id = 0;
$ref_id = $this->db->element("SELECT MAX(id) id from ".$ref." WHERE UPPER_UTF8(name) = UPPER_UTF8(?)", $name );

if(is_numeric($name) && intval($name) > 0) {
//число или название?
$ref_id = $this->db->element("SELECT MAX(id) id from ".$ref." WHERE ID = ?", $name );
} else {
//название
$ref_id = $this->db->element("SELECT MAX(id) id from ".$ref." WHERE UPPER_UTF8(name) = UPPER_UTF8(?)", $name );
}
$ref_id = intval($ref_id);

if($ref_id == 0) {
Expand Down Expand Up @@ -395,7 +400,7 @@ protected function refbook_check($data, $files = array() ) {

$ret['cash_item_note'] = $data['cash_item_note'];
$ret['cash_item_geo'] = $data['cash_item_geo'];

return $ret;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ function csrf_protect() {
session_start();

$csrftoken = "";
$uri = pathinfo( $_SERVER['REQUEST_URI'], PATHINFO_FILENAME );
$uri = pathinfo(array_pop(explode("/", $_SERVER['REQUEST_URI'])), PATHINFO_FILENAME);

if( in_array($uri, array("", "index", "pda", "demo")) ) {
if( empty($_SESSION['csrftoken']) ) {
$csrftoken = md5( $_SERVER['SERVER_NAME'].rand(1, 10000000).$_SERVER['HTTP_HOST'] );
Expand Down
2 changes: 1 addition & 1 deletion lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$extjs = 'extjs';

/* App version */
$version = "1.053";
$version = "1.054";
//$version = rand(); //for reset cache

/* Path to imgs and js */
Expand Down

0 comments on commit ae4d460

Please sign in to comment.