From fa69800a3b2c04442d38cb065c3fb6c6d49a204d Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 15 Jun 2016 01:22:02 +0100 Subject: [PATCH] dbq2 --- etc/dbs/rent.php | 72 ++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/etc/dbs/rent.php b/etc/dbs/rent.php index ce33706c..09ff677d 100644 --- a/etc/dbs/rent.php +++ b/etc/dbs/rent.php @@ -25,19 +25,14 @@ $CONF['_rent'] = array( ), 'row_parse_pre' => function(&$r) { - #extra: "rent * (1 + ( strftime('%m',end)+12*strftime('%Y',end) ) - ( strftime('%m',start)+12*strftime('%Y',start) ))" - #$r['rent_year'] = $r['rent'] * (1 + ( date('m',strtotime($r['end']))+12 - $r['Total'] = $r['rent'] + $r['charge']; -# NB 16.05.16 if (1) $r['rent_year'] = sprintf('%.2f',$r['rent'] * (1 + -# NB 16.05.16 ( date('m',strtotime($r['end'])) + 12 * date('Y',strtotime($r['end'])) ) -# NB 16.05.16 - -# NB 16.05.16 ( date('m',strtotime($r['start'])) + 12 * date('Y',strtotime($r['start'])) ) -# NB 16.05.16 )); + $r['month'] = $r['rent'] + $r['charge']; + $start_month = date('m',strtotime($r['start'])); $end_month = date('m',strtotime($r['end'])); if (date('Y',strtotime($r['end'])) > date('Y',strtotime($r['start']))) $end_month = 12; - $r['rent_year'] = sprintf('%.2f',$r['rent'] * (1 + $end_month - $start_month)); - $r['months_year'] = (1 + $end_month - $start_month); + $r['months'] = (1 + $end_month - $start_month); + + $r['total'] = sprintf('%d',$r['rent'] * $r['months']); }, 'row_parse_post' => ((empty($GLOBALS['Db']) or Db::php_cli()) ? null : function(&$r) { @@ -45,7 +40,7 @@ $CONF['_rent'] = array( if (!isset($templates)) { $templates = $GLOBALS['Db']->rows("SELECT id FROM template",PDO::FETCH_NUM); foreach ($templates as $k=>$t) { - $templates[$k] = ''.preg_replace('/\.\w+$/','',$t[0]).''; + $templates[$k] = ''.preg_replace('/\.\w+$/','',$t[0]).''; } } @@ -54,6 +49,7 @@ $CONF['_rent'] = array( $r['revision'] .= preg_replace_callback('/:(\w+)/',function($m) use(&$r) {return $r[$m[1]];},$t).' '; } $r['revision'] = trim($r['revision']); + tennant_doc($r); }), ), @@ -69,28 +65,44 @@ function untilde($path) { },$path); } +function tennant_doc(&$r) { + $url = ''; + foreach (['idtenant','id'] as $k) { + if (isset($r[$k])) $url = '/data/tenant/'.$r[$k]; + } + if (!$url) return; + + if (!isset($r['doc'])) $r['doc'] = ''; +#debug($_SERVER['DOCUMENT_ROOT'].$url); + if ( + + # Web url + ( + empty($r['doc']) and file_exists( $dir = $_SERVER['DOCUMENT_ROOT'].$url ) + ) + + # Absolute path + or ( + ( $dir = untilde($r['doc']) ) + and file_exists($dir) and is_dir($dir) + and ($url='' or 1) + ) + + ) { + + foreach (ls_dir($dir,true) as $p) { + #$r['doc'] .= '/data/tenant/'.$p; + $r['doc'] .= sprintf('%s ',"$url/$p",preg_replace('@^.*?([^/\.]+).*?$@','\1',$p)); + } + + } + +} + #die(untilde('~/.gitconfig')); if (!empty($_SERVER['DOCUMENT_ROOT'])) { $CONF['_rent']['tables']['tenant'] = array( - 'row_parse_post' => function(&$r) { - $url = '/data/tenant/'.$r['id']; - - if ( - ( - (!$doc=$r['doc']) and file_exists( $dir = $_SERVER['DOCUMENT_ROOT'].$url ) - ) or ( - ( $dir = untilde($r['doc']) ) - and file_exists($dir) and is_dir($dir) - and ($url='' or 1) - ) - ) { - #debug($_SERVER['DOCUMENT_ROOT'].'/data/tenant/'); - foreach (ls_dir($dir,true) as $p) { - #$r['doc'] .= '/data/tenant/'.$p; - $r['doc'] .= sprintf('%s ',"$url/$p",preg_replace('@^.*?([^/\.]+).*?$@','\1',$p)); - } - } - }, + 'row_parse_post' => 'tennant_doc', ); } -- 2.47.3