]> git.nbdom.net Git - nb.git/commitdiff
dbq2
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 15 Jun 2016 00:22:02 +0000 (01:22 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 15 Jun 2016 00:22:02 +0000 (01:22 +0100)
etc/dbs/rent.php

index ce33706cf4224972abd9f32cb201ceeecccbb970..09ff677da2f66c5fe7ea0da85d3f8c692b8abe96 100644 (file)
@@ -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] = '<a href="template/?id='.$t[0].'&amp;idplace=:idplace&amp;idtenant=:idtenant&amp;start=:start">'.preg_replace('/\.\w+$/','',$t[0]).'</a>';
+            $templates[$k] = '<a class="small" href="template/?id='.$t[0].'&amp;idplace=:idplace&amp;idtenant=:idtenant&amp;start=:start">'.preg_replace('/\.\w+$/','',$t[0]).'</a>';
           }
         }
 
@@ -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('<a href="%s" class="small">%s</a> ',"$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('<a href="%s" class="small">%s</a> ',"$url/$p",preg_replace('@^.*?([^/\.]+).*?$@','\1',$p));
-        }
-      }
-    },
+    'row_parse_post' => 'tennant_doc',
   );
 }