fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [14567] rental: formatting code


From: Sigurd Nes
Subject: [Fmsystem-commits] [14567] rental: formatting code
Date: Thu, 10 Dec 2015 14:57:05 +0000

Revision: 14567
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=14567
Author:   sigurdne
Date:     2015-12-10 14:57:03 +0000 (Thu, 10 Dec 2015)
Log Message:
-----------
rental: formatting code

Modified Paths:
--------------
    branches/dev-syncromind/rental/inc/SnappyMedia.php
    branches/dev-syncromind/rental/inc/SnappyPdf.php
    branches/dev-syncromind/rental/inc/class.bofellesdata.inc.php
    branches/dev-syncromind/rental/inc/class.hook_helper.inc.php
    branches/dev-syncromind/rental/inc/class.menu.inc.php
    branches/dev-syncromind/rental/inc/class.soadjustment.inc.php
    branches/dev-syncromind/rental/inc/class.sobilling.inc.php
    branches/dev-syncromind/rental/inc/class.sobilling_info.inc.php
    branches/dev-syncromind/rental/inc/class.socommon.inc.php
    branches/dev-syncromind/rental/inc/class.socomposite.inc.php
    branches/dev-syncromind/rental/inc/class.socontract.inc.php
    branches/dev-syncromind/rental/inc/class.socontract_price_item.inc.php
    branches/dev-syncromind/rental/inc/class.sodocument.inc.php
    branches/dev-syncromind/rental/inc/class.soinvoice.inc.php
    branches/dev-syncromind/rental/inc/class.soinvoice_price_item.inc.php
    branches/dev-syncromind/rental/inc/class.sonotification.inc.php
    branches/dev-syncromind/rental/inc/class.soparty.inc.php
    branches/dev-syncromind/rental/inc/class.soprice_item.inc.php
    branches/dev-syncromind/rental/inc/class.sounit.inc.php
    branches/dev-syncromind/rental/inc/class.soworkbench_notification.inc.php
    branches/dev-syncromind/rental/inc/class.uiadjustment.inc.php
    branches/dev-syncromind/rental/inc/class.uibilling.inc.php
    branches/dev-syncromind/rental/inc/class.uicommon.inc.php
    branches/dev-syncromind/rental/inc/class.uicomposite.inc.php
    branches/dev-syncromind/rental/inc/class.uicontract.inc.php
    branches/dev-syncromind/rental/inc/class.uidelegate.inc.php
    branches/dev-syncromind/rental/inc/class.uidocument.inc.php
    branches/dev-syncromind/rental/inc/class.uifrontpage.inc.php
    branches/dev-syncromind/rental/inc/class.uiimport.inc.php
    branches/dev-syncromind/rental/inc/class.uiinvoice_price_item.inc.php
    branches/dev-syncromind/rental/inc/class.uimakepdf.inc.php
    branches/dev-syncromind/rental/inc/class.uinotification.inc.php
    branches/dev-syncromind/rental/inc/class.uiparty.inc.php
    branches/dev-syncromind/rental/inc/class.uiprice_item.inc.php
    branches/dev-syncromind/rental/inc/class.uiproperty_location.inc.php
    branches/dev-syncromind/rental/inc/class.uiresultunit.inc.php
    branches/dev-syncromind/rental/inc/class.uiunit.inc.php
    
branches/dev-syncromind/rental/inc/custom/default/NLSH_add_contract_from_composite.php
    branches/dev-syncromind/rental/inc/export/default/customer.php
    branches/dev-syncromind/rental/inc/export/nordlandssykehuset/customer.php
    branches/dev-syncromind/rental/inc/hook_config.inc.php
    branches/dev-syncromind/rental/inc/hook_settings.inc.php
    branches/dev-syncromind/rental/inc/locations/class.city_counsil_dep.inc.php
    
branches/dev-syncromind/rental/inc/locations/class.location_hierarchy.inc.php
    
branches/dev-syncromind/rental/inc/locations/class.organisational_location.inc.php
    branches/dev-syncromind/rental/inc/locations/class.result_unit.inc.php
    branches/dev-syncromind/rental/inc/model/class.adjustment.inc.php
    branches/dev-syncromind/rental/inc/model/class.agresso_cs15.inc.php
    branches/dev-syncromind/rental/inc/model/class.agresso_gl07.inc.php
    branches/dev-syncromind/rental/inc/model/class.agresso_lg04.inc.php
    branches/dev-syncromind/rental/inc/model/class.billing.inc.php
    branches/dev-syncromind/rental/inc/model/class.billing_info.inc.php
    branches/dev-syncromind/rental/inc/model/class.composite.inc.php
    branches/dev-syncromind/rental/inc/model/class.contract.inc.php
    branches/dev-syncromind/rental/inc/model/class.contract_date.inc.php
    branches/dev-syncromind/rental/inc/model/class.contract_price_item.inc.php
    branches/dev-syncromind/rental/inc/model/class.default_export.inc.php
    branches/dev-syncromind/rental/inc/model/class.document.inc.php
    branches/dev-syncromind/rental/inc/model/class.exportable.inc.php
    branches/dev-syncromind/rental/inc/model/class.invoice.inc.php
    branches/dev-syncromind/rental/inc/model/class.invoice_price_item.inc.php
    branches/dev-syncromind/rental/inc/model/class.model.inc.php
    branches/dev-syncromind/rental/inc/model/class.notification.inc.php
    branches/dev-syncromind/rental/inc/model/class.party.inc.php
    branches/dev-syncromind/rental/inc/model/class.price_item.inc.php
    branches/dev-syncromind/rental/inc/model/class.property_location.inc.php
    branches/dev-syncromind/rental/inc/model/class.unit.inc.php
    branches/dev-syncromind/rental/inc/model/class.validator.inc.php
    branches/dev-syncromind/rental/inc/plugins/fellesdata/party.edit.php
    branches/dev-syncromind/rental/index.php
    branches/dev-syncromind/rental/js/rental/adjustment.index.js
    branches/dev-syncromind/rental/js/rental/billing.add.js
    branches/dev-syncromind/rental/js/rental/billing.index.js
    branches/dev-syncromind/rental/js/rental/common.js
    branches/dev-syncromind/rental/js/rental/composite.edit.js
    branches/dev-syncromind/rental/js/rental/composite.view.js
    branches/dev-syncromind/rental/js/rental/contract.edit.js
    branches/dev-syncromind/rental/js/rental/contract.index.js
    branches/dev-syncromind/rental/js/rental/contract.view.js
    branches/dev-syncromind/rental/js/rental/frontpage.index.js
    branches/dev-syncromind/rental/js/rental/party.edit.js
    branches/dev-syncromind/rental/js/rental/party.sync.js
    branches/dev-syncromind/rental/js/rental/price_item.adjust_price.js
    branches/dev-syncromind/rental/js/rental/price_item.index.js
    branches/dev-syncromind/rental/js/rental/resultunit.edit.js
    branches/dev-syncromind/rental/templates/base/adjustment.xsl
    branches/dev-syncromind/rental/templates/base/billing.xsl
    branches/dev-syncromind/rental/templates/base/composite.xsl
    branches/dev-syncromind/rental/templates/base/config.tpl
    branches/dev-syncromind/rental/templates/base/contract.xsl
    branches/dev-syncromind/rental/templates/base/frontpage.xsl
    branches/dev-syncromind/rental/templates/base/party.xsl
    branches/dev-syncromind/rental/templates/base/price_item.xsl
    branches/dev-syncromind/rental/templates/base/resultunit.xsl

Modified: branches/dev-syncromind/rental/inc/SnappyMedia.php
===================================================================
--- branches/dev-syncromind/rental/inc/SnappyMedia.php  2015-12-10 14:38:47 UTC 
(rev 14566)
+++ branches/dev-syncromind/rental/inc/SnappyMedia.php  2015-12-10 14:57:03 UTC 
(rev 14567)
@@ -1,139 +1,151 @@
 <?php
 
-/**
-* https://github.com/knplabs/snappy
-* The MIT License
-*
-* Copyright (c) 2010 Matthieu Bontemps
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy
-* of this software and associated documentation files (the "Software"), to deal
-* in the Software without restriction, including without limitation the rights
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-* copies of the Software, and to permit persons to whom the Software is 
furnished
-* to do so, subject to the following conditions:
-* 
-* The above copyright notice and this permission notice shall be included in 
all
-* copies or substantial portions of the Software.
-* 
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-* THE SOFTWARE.
-* 
-*/
-abstract class SnappyMedia
-{
-    protected $executable;
-    protected $options = array();
-    protected $defaultExtension;
-    
-    /**
-     * Write the media to the standard output.
-     *
-     * @param string Url of the page
-     * @return void
-     */
-    public function output($url)
-    {
-      $file = tempnam(sys_get_temp_dir(), 'snappy') . '.' . 
$this->defaultExtension;
-      $ok = $this->save($url, $file);
-      readfile($file);
-      unlink($file);
-    }
-    
-    /**
-     * Save a url or file location to an image.
-     * Will create directories if needed.
-     *
-     * @param string Url of the page
-     * @param string Path of the future image
-     * @return boolean True if success
-     */
-    public function save($url, $path)
-    {
-        $command = $this->buildCommand($url, $path);
-        $basePath = dirname($path);
-        if(!is_dir($basePath)) {
-          mkdir($basePath, 0777, true);
-        }
-        if(file_exists($path)) {
-          unlink($path);
-        }
-        $ok = $this->exec($command);
-        return file_exists($path) && filesize($path);
-    }
-    
-    public function setExecutable($executable)
-    {
-        $this->executable = $executable;
-    }
-    
-    /**
-     * Set a wkhtmltoimage option. Be aware that option values are NOT 
validated
-     * and that it is your responsibility to validate user inputs.
-     * 
-     * @param string Option 
-     * @param string|array Value. Null to unset the option. 
-     * @return void
-     */
-    public function setOption($option, $value = null)
-    {
-        if(!array_key_exists($option, $this->options)) {
-            throw new Exception("Invalid option '$option'");
-        }
-        $this->options[$option] = $value;
-    }
-    
-    /**
-     * Merge wkhtmltoimage options (passed as an array) with current options
-     *
-     * @param array Array of options
-     * @return void
-     */
-    public function mergeOptions(array $options)
-    {
-        foreach($options as $key => $value) {
-            $this->setOption($key, $value);
-        }
-    }
-    
-    /**
-     * Return the command to wkhtmltoimage using the options attributes
-     *
-     * @param string Url or file location of the page to process
-     * @param string File location to the image-to-be
-     * @return string The command
-     */
-    protected function buildCommand($url, $path)
-    {
-        $command = $this->executable;
+       /**
+        * https://github.com/knplabs/snappy
+        * The MIT License
+        *
+        * Copyright (c) 2010 Matthieu Bontemps
+        *
+        * Permission is hereby granted, free of charge, to any person 
obtaining a copy
+        * of this software and associated documentation files (the 
"Software"), to deal
+        * in the Software without restriction, including without limitation 
the rights
+        * to use, copy, modify, merge, publish, distribute, sublicense, and/or 
sell
+        * copies of the Software, and to permit persons to whom the Software 
is furnished
+        * to do so, subject to the following conditions:
+        * 
+        * The above copyright notice and this permission notice shall be 
included in all
+        * copies or substantial portions of the Software.
+        * 
+        * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR
+        * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+        * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 
SHALL THE
+        * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
OTHER
+        * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
ARISING FROM,
+        * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
DEALINGS IN
+        * THE SOFTWARE.
+        * 
+        */
+       abstract class SnappyMedia
+       {
 
-        foreach($this->options as $key => $value) {
-            if(null !== $value && false !== $value) {
-                if(true === $value) {
-                    $command .= " --$key";
-                } elseif(is_array($value)) {
-                    foreach($value as $v) {
-                        $command .= " --$key $v";
-                    }
-                } else {
-                    $command .= " --$key $value";
-                }
-            }
-        }
-        
-        $command .= " \"$url\" \"$path\"";
-        
-        return $command;
-    }
-        
-    protected function exec($command)
-    {
-        return shell_exec($command);
-    }
-}
-?>
\ No newline at end of file
+               protected $executable;
+               protected $options = array();
+               protected $defaultExtension;
+
+               /**
+                * Write the media to the standard output.
+                *
+                * @param string Url of the page
+                * @return void
+                */
+               public function output($url)
+               {
+                       $file    = tempnam(sys_get_temp_dir(), 'snappy') . '.' 
. $this->defaultExtension;
+                       $ok              = $this->save($url, $file);
+                       readfile($file);
+                       unlink($file);
+               }
+
+               /**
+                * Save a url or file location to an image.
+                * Will create directories if needed.
+                *
+                * @param string Url of the page
+                * @param string Path of the future image
+                * @return boolean True if success
+                */
+               public function save($url, $path)
+               {
+                       $command         = $this->buildCommand($url, $path);
+                       $basePath        = dirname($path);
+                       if(!is_dir($basePath))
+                       {
+                               mkdir($basePath, 0777, true);
+                       }
+                       if(file_exists($path))
+                       {
+                               unlink($path);
+                       }
+                       $ok = $this->exec($command);
+                       return file_exists($path) && filesize($path);
+               }
+
+               public function setExecutable($executable)
+               {
+                       $this->executable = $executable;
+               }
+
+               /**
+                * Set a wkhtmltoimage option. Be aware that option values are 
NOT validated
+                * and that it is your responsibility to validate user inputs.
+                * 
+                * @param string Option 
+                * @param string|array Value. Null to unset the option. 
+                * @return void
+                */
+               public function setOption($option, $value = null)
+               {
+                       if(!array_key_exists($option, $this->options))
+                       {
+                               throw new Exception("Invalid option '$option'");
+                       }
+                       $this->options[$option] = $value;
+               }
+
+               /**
+                * Merge wkhtmltoimage options (passed as an array) with 
current options
+                *
+                * @param array Array of options
+                * @return void
+                */
+               public function mergeOptions(array $options)
+               {
+                       foreach($options as $key => $value)
+                       {
+                               $this->setOption($key, $value);
+                       }
+               }
+
+               /**
+                * Return the command to wkhtmltoimage using the options 
attributes
+                *
+                * @param string Url or file location of the page to process
+                * @param string File location to the image-to-be
+                * @return string The command
+                */
+               protected function buildCommand($url, $path)
+               {
+                       $command = $this->executable;
+
+                       foreach($this->options as $key => $value)
+                       {
+                               if(null !== $value && false !== $value)
+                               {
+                                       if(true === $value)
+                                       {
+                                               $command .= " --$key";
+                                       }
+                                       elseif(is_array($value))
+                                       {
+                                               foreach($value as $v)
+                                               {
+                                                       $command .= " --$key 
$v";
+                                               }
+                                       }
+                                       else
+                                       {
+                                               $command .= " --$key $value";
+                                       }
+                               }
+                       }
+
+                       $command .= " \"$url\" \"$path\"";
+
+                       return $command;
+               }
+
+               protected function exec($command)
+               {
+                       return shell_exec($command);
+               }
+       }
\ No newline at end of file

Modified: branches/dev-syncromind/rental/inc/SnappyPdf.php
===================================================================
--- branches/dev-syncromind/rental/inc/SnappyPdf.php    2015-12-10 14:38:47 UTC 
(rev 14566)
+++ branches/dev-syncromind/rental/inc/SnappyPdf.php    2015-12-10 14:57:03 UTC 
(rev 14567)
@@ -1,42 +1,43 @@
 <?php
-/**
- * Use this class to transform a html/a url to a pdf
- *
- * @package Snappy
- * @author Matthieu Bontemps<address@hidden>
- * https://github.com/knplabs/snappy
- * The MIT License
- *
- * Copyright (c) 2010 Matthieu Bontemps
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to 
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is 
furnished
- * to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in 
all
- * copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
 
-class SnappyPdf extends SnappyMedia
-{
-    protected $defaultExtension = 'pdf';
-    protected $options = array(
-        'ignore-load-errors' => null,                          // old v0.9
-        'lowquality' => true,
-        'username' => null,
-        'password' => null,
-        'minimum-font-size'    => 12,
-    );
-    
-}
\ No newline at end of file
+       /**
+        * Use this class to transform a html/a url to a pdf
+        *
+        * @package Snappy
+        * @author Matthieu Bontemps<address@hidden>
+        * https://github.com/knplabs/snappy
+        * The MIT License
+        *
+        * Copyright (c) 2010 Matthieu Bontemps
+        *
+        * Permission is hereby granted, free of charge, to any person 
obtaining a copy
+        * of this software and associated documentation files (the 
"Software"), to deal
+        * in the Software without restriction, including without limitation 
the rights
+        * to use, copy, modify, merge, publish, distribute, sublicense, and/or 
sell
+        * copies of the Software, and to permit persons to whom the Software 
is furnished
+        * to do so, subject to the following conditions:
+        *
+        * The above copyright notice and this permission notice shall be 
included in all
+        * copies or substantial portions of the Software.
+        *
+        * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR
+        * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+        * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 
SHALL THE
+        * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
OTHER
+        * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
ARISING FROM,
+        * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
DEALINGS IN
+        * THE SOFTWARE.
+        */
+       class SnappyPdf extends SnappyMedia
+       {
+
+               protected $defaultExtension      = 'pdf';
+               protected $options                       = array(
+                       'ignore-load-errors' => null, // old v0.9
+                       'lowquality'             => true,
+                       'username'                       => null,
+                       'password'                       => null,
+                       'minimum-font-size'      => 12,
+               );
+
+       }
\ No newline at end of file

Modified: branches/dev-syncromind/rental/inc/class.bofellesdata.inc.php
===================================================================
--- branches/dev-syncromind/rental/inc/class.bofellesdata.inc.php       
2015-12-10 14:38:47 UTC (rev 14566)
+++ branches/dev-syncromind/rental/inc/class.bofellesdata.inc.php       
2015-12-10 14:57:03 UTC (rev 14567)
@@ -28,10 +28,10 @@
 
                // Instance variable
                protected static $bo;
-               protected $connected = false;
+               protected $connected     = false;
                protected $status;
-               protected $db            = null;
-               protected $unit_ids      = array();
+               protected $db                    = null;
+               protected $unit_ids              = array();
                var $public_functions = array
                        (
                        'get_all_org_units_autocomplete' => true,
@@ -293,7 +293,7 @@
 
                public function get_all_org_units_autocomplete()
                {
-                       if(!$db          = $this->get_db())
+                       if(!$db = $this->get_db())
                        {
                                return;
                        }
@@ -601,9 +601,9 @@
                                                        }
                                                        if($count < 
(count($search_words) - 1))
                                                        {
-                                                               $selector       
 = $selector . " OR ";
+                                                               $selector = 
$selector . " OR ";
                                                        }
-                                                       $count           = 
($count + 1);
+                                                       $count = ($count + 1);
                                                }
                                                $selector = $selector . ")";
 
@@ -719,12 +719,12 @@
                        if($db->Type == "postgres")
                        {
                                $columns = "count(*) as cnt";
-                               $ret = 'cnt';
+                               $ret     = 'cnt';
                        }
                        else
                        {
                                $columns = "count(*) as CNT";
-                               $ret = 'CNT';
+                               $ret     = 'CNT';
                        }
                        $tables  = "V_ORG_ENHET";
                        $joins   = "LEFT JOIN V_ORG_PERSON_ENHET ON 
(V_ORG_ENHET.ORG_ENHET_ID = V_ORG_PERSON_ENHET.ORG_ENHET_ID AND 
V_ORG_PERSON_ENHET.prioritet = 1) " .
@@ -756,9 +756,9 @@
                                                        }
                                                        if($count < 
(count($search_words) - 1))
                                                        {
-                                                               $selector       
 = $selector . " OR ";
+                                                               $selector = 
$selector . " OR ";
                                                        }
-                                                       $count           = 
($count + 1);
+                                                       $count = ($count + 1);
                                                }
                                                $selector = $selector . ")";
 

Modified: branches/dev-syncromind/rental/inc/class.hook_helper.inc.php
===================================================================
--- branches/dev-syncromind/rental/inc/class.hook_helper.inc.php        
2015-12-10 14:38:47 UTC (rev 14566)
+++ branches/dev-syncromind/rental/inc/class.hook_helper.inc.php        
2015-12-10 14:57:03 UTC (rev 14567)
@@ -8,23 +8,21 @@
         * @package rental
         * @version $Id: class.hook_helper.inc.php 11076 2013-04-25 07:19:14Z 
sigurdne $
         */
-
        /*
-          This program is free software: you can redistribute it and/or modify
-          it under the terms of the GNU General Public License as published by
-          the Free Software Foundation, either version 2 of the License, or
-          (at your option) any later version.
+         This program is free software: you can redistribute it and/or modify
+         it under the terms of the GNU General Public License as published by
+         the Free Software Foundation, either version 2 of the License, or
+         (at your option) any later version.
 
-          This program is distributed in the hope that it will be useful,
-          but WITHOUT ANY WARRANTY; without even the implied warranty of
-          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-          GNU General Public License for more details.
+         This program is distributed in the hope that it will be useful,
+         but WITHOUT ANY WARRANTY; without even the implied warranty of
+         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+         GNU General Public License for more details.
 
-          You should have received a copy of the GNU General Public License
-          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+         You should have received a copy of the GNU General Public License
+         along with this program.  If not, see <http://www.gnu.org/licenses/>.
         */
 
-
        /**
         * Hook helper
         *
@@ -47,28 +45,28 @@
                        }
 
                        $criteria = array
-                       (
-                               'appname'               => 'rental',
-                               'location'              => 
$data['acl_location'],
-                               'pre_commit'    => true,
-                               'allrows'               => true
+                               (
+                               'appname'        => 'rental',
+                               'location'       => $data['acl_location'],
+                               'pre_commit' => true,
+                               'allrows'        => true
                        );
 
                        $custom_functions = 
$GLOBALS['phpgw']->custom_functions->find($criteria);
 
-                       foreach ( $custom_functions as $entry )
+                       foreach($custom_functions as $entry)
                        {
                                // prevent path traversal
-                               if ( preg_match('/\.\./', $entry['file_name']) )
+                               if(preg_match('/\.\./', $entry['file_name']))
                                {
                                        continue;
                                }
 
                                $file = PHPGW_SERVER_ROOT . 
"/rental/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
-                               if ( $entry['active'] && is_file($file)  && 
!$entry['client_side'])
+                               if($entry['active'] && is_file($file) && 
!$entry['client_side'])
                                {
                                        require $file;
                                }
                        }
                }
-       }
+       }
\ No newline at end of file

Modified: branches/dev-syncromind/rental/inc/class.menu.inc.php
===================================================================
--- branches/dev-syncromind/rental/inc/class.menu.inc.php       2015-12-10 
14:38:47 UTC (rev 14566)
+++ branches/dev-syncromind/rental/inc/class.menu.inc.php       2015-12-10 
14:57:03 UTC (rev 14567)
@@ -3,194 +3,213 @@
 
        class rental_menu
        {
+
                function get_menu()
                {
-                       $incoming_app = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $GLOBALS['phpgw_info']['flags']['currentapp'] = 
'rental';
-                       
-                       $config = CreateObject('phpgwapi.config','rental');
+                       $incoming_app                                           
                         = $GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $GLOBALS['phpgw_info']['flags']['currentapp']    = 
'rental';
+
+                       $config                  = 
CreateObject('phpgwapi.config', 'rental');
                        $config->read();
-                       $use_fellesdata = 
$config->config_data['use_fellesdata'];
+                       $use_fellesdata  = 
$config->config_data['use_fellesdata'];
 
                        $menus = array();
 
                        $menus['navbar'] = array
-                       (
+                               (
                                'rental' => array
-                               (
-                                       'text'  => lang('rental'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'rental.uifrontpage.index') ),
-                                       'image' => array('rental', 'user-home'),
-                                       'order' => 10,
-                                       'group' => 'office'
+                                       (
+                                       'text'   => lang('rental'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uifrontpage.index')),
+                                       'image'  => array('rental', 
'user-home'),
+                                       'order'  => 10,
+                                       'group'  => 'office'
                                )
                        );
-                       
-                       
+
+
                        if(
-                               
$GLOBALS['phpgw']->acl->check(rental_uicommon::LOCATION_IN,PHPGW_ACL_ADD,'rental')
 ||
-                               
$GLOBALS['phpgw']->acl->check(rental_uicommon::LOCATION_OUT,PHPGW_ACL_ADD,'rental')
     ||
-                               
$GLOBALS['phpgw']->acl->check(rental_uicommon::LOCATION_INTERNAL,PHPGW_ACL_ADD,'rental')
+                       
$GLOBALS['phpgw']->acl->check(rental_uicommon::LOCATION_IN, PHPGW_ACL_ADD, 
'rental') ||
+                       
$GLOBALS['phpgw']->acl->check(rental_uicommon::LOCATION_OUT, PHPGW_ACL_ADD, 
'rental') ||
+                       
$GLOBALS['phpgw']->acl->check(rental_uicommon::LOCATION_INTERNAL, 
PHPGW_ACL_ADD, 'rental')
                        )
                        {
-                               $billing = array (
-                                       'invoice' => array
-                                       (
-                                               'text'  => lang('invoice_menu'),
-                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uibilling.index', 'appname' => 'rental') ),
-                                               'image' => array('rental', 
'x-office-document')
+                               $billing = array(
+                                       'invoice'                        => 
array
+                                               (
+                                               'text'   => 
lang('invoice_menu'),
+                                               'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uibilling.index',
+                                                       'appname'        => 
'rental')),
+                                               'image'  => array('rental', 
'x-office-document')
                                        ),
-                                       'price_item_list'       => array
-                                       (
-                                               'text'  => lang('price_list'),
-                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiprice_item.index', 'appname' => 'rental') ),
-                                               'image' => array('rental', 
'x-office-spreadsheet'),
-                                               'children'      => array(
-                                                               
'manual_adjustment' => array
+                                       'price_item_list'        => array
+                                               (
+                                               'text'           => 
lang('price_list'),
+                                               'url'            => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiprice_item.index',
+                                                       'appname'        => 
'rental')),
+                                               'image'          => 
array('rental', 'x-office-spreadsheet'),
+                                               'children'       => array(
+                                                       'manual_adjustment' => 
array
                                                                (
-                                                                       'text'  
=> lang('manual_adjustment'),
-                                                                       'url'   
=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiprice_item.manual_adjustment', 'appname' => 'rental') ),
-                                                                       'image' 
=> array('rental', 'x-office-spreadsheet')
-                                                               )
+                                                               'text'   => 
lang('manual_adjustment'),
+                                                               'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiprice_item.manual_adjustment',
+                                                                       
'appname'        => 'rental')),
+                                                               'image'  => 
array('rental', 'x-office-spreadsheet')
                                                        )
+                                               )
                                        ),
-                                       'adjustment'    => array
-                                       (
-                                               'text'  => lang('adjustment'),
-                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiadjustment.index', 'appname' => 'rental') ),
-                                               'image' => array('rental', 
'x-office-spreadsheet')
+                                       'adjustment'             => array
+                                               (
+                                               'text'   => lang('adjustment'),
+                                               'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiadjustment.index',
+                                                       'appname'        => 
'rental')),
+                                               'image'  => array('rental', 
'x-office-spreadsheet')
                                        )
                                );
-                               
-                               $sync_choices = array (
-                                       'sync_org_unit' => array
-                                       (
-                                               'text'  => 
lang('sync_org_unit'),
-                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiparty.sync', 'sync' => 'org_unit', 'appname' => 'rental') ),
-                                               'image' => array('rental', 
'x-office-document')
+
+                               $sync_choices = array(
+                                       'sync_org_unit'                  => 
array
+                                               (
+                                               'text'   => 
lang('sync_org_unit'),
+                                               'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiparty.sync',
+                                                       'sync'           => 
'org_unit', 'appname'        => 'rental')),
+                                               'image'  => array('rental', 
'x-office-document')
                                        ),
-                                       'sync_resp_and_service' => array
-                                       (
-                                               'text'  => 
lang('sync_resp_and_service'),
-                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiparty.sync','sync' => 'resp_and_service', 'appname' => 'rental') ),
-                                               'image' => array('rental', 
'x-office-document')
+                                       'sync_resp_and_service'  => array
+                                               (
+                                               'text'   => 
lang('sync_resp_and_service'),
+                                               'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiparty.sync',
+                                                       'sync'           => 
'resp_and_service', 'appname'        => 'rental')),
+                                               'image'  => array('rental', 
'x-office-document')
                                        ),
-                                       'sync_res_units' => array
-                                       (
-                                               'text'  => 
lang('sync_res_units'),
-                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiparty.sync', 'sync' => 'res_unit_number', 'appname' => 'rental') ),
-                                               'image' => array('rental', 
'x-office-document')
+                                       'sync_res_units'                 => 
array
+                                               (
+                                               'text'   => 
lang('sync_res_units'),
+                                               'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiparty.sync',
+                                                       'sync'           => 
'res_unit_number', 'appname'         => 'rental')),
+                                               'image'  => array('rental', 
'x-office-document')
                                        ),
-                                       'sync_identifier' => array
-                                       (
-                                               'text'  => 
lang('sync_identifier'),
-                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiparty.sync', 'sync' => 'identifier','appname' => 'rental') ),
-                                               'image' => array('rental', 
'x-office-document')
+                                       'sync_identifier'                => 
array
+                                               (
+                                               'text'   => 
lang('sync_identifier'),
+                                               'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiparty.sync',
+                                                       'sync'           => 
'identifier', 'appname'      => 'rental')),
+                                               'image'  => array('rental', 
'x-office-document')
                                        )
                                );
 
                                $sub_parties = array(
-                                       'sync' => array 
-                                       (
-                                               'text'  => lang('sync_menu'),
-                                               'url'   => '',
-                                               'image' => array('rental', 
'x-office-document'),
-                                               'children' => $sync_choices
+                                       'sync'           => array
+                                               (
+                                               'text'           => 
lang('sync_menu'),
+                                               'url'            => '',
+                                               'image'          => 
array('rental', 'x-office-document'),
+                                               'children'       => 
$sync_choices
                                        ),
                                        'resultunit' => array
-                                       (
-                                               'text' => lang('delegates'),
-                                               'url' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiresultunit.index','appname' => 'rental') ),
-                                               'image' => array('rental', 
'system-users')
+                                               (
+                                               'text'   => lang('delegates'),
+                                               'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiresultunit.index',
+                                                       'appname'        => 
'rental')),
+                                               'image'  => array('rental', 
'system-users')
                                        )
                                );
                        }
-                       
-                       $menus['navigation'] =  array
-                       (
-                               'contracts' => array
+
+                       $menus['navigation'] = array
                                (
-                                       'text'  => lang('contracts'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'rental.uicontract.index') ),
-                                       'image' => array('rental', 
'text-x-generic'),
-                                       'children'      => $billing
+                               'contracts'      => array
+                                       (
+                                       'text'           => lang('contracts'),
+                                       'url'            => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uicontract.index')),
+                                       'image'          => array('rental', 
'text-x-generic'),
+                                       'children'       => $billing
                                ),
                                'composites' => array
-                               (
-                                       'text'  => lang('rc'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'rental.uicomposite.index') ),
-                                       'image' => array('rental', 'go-home')
+                                       (
+                                       'text'   => lang('rc'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uicomposite.index')),
+                                       'image'  => array('rental', 'go-home')
                                ),
-                               'parties' => array
-                               (
-                                       'text'  => lang('parties'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'rental.uiparty.index') ),
-                                       'image' => array('rental', 
'x-office-address-book')
+                               'parties'        => array
+                                       (
+                                       'text'   => lang('parties'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiparty.index')),
+                                       'image'  => array('rental', 
'x-office-address-book')
                                )
                        );
-                       
-                       if($use_fellesdata){
+
+                       if($use_fellesdata)
+                       {
                                $menus['navigation']['parties']['children'] = 
$sub_parties;
                        }
 
                        $menus['admin'] = array
-                       (
-                               'index' => array
                                (
-                                       'text'  => lang('Configuration'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiconfig.index', 'appname' => 'rental') )
+                               'index'                                  => 
array
+                                       (
+                                       'text'   => lang('Configuration'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiconfig.index',
+                                               'appname'        => 'rental'))
                                ),
-                               'acl'   => array
-                               (
-                                       'text'  => lang('Configure Access 
Permissions'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'preferences.uiadmin_acl.list_acl', 'acl_app' => 'rental') )
+                               'acl'                                    => 
array
+                                       (
+                                       'text'   => lang('Configure Access 
Permissions'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'preferences.uiadmin_acl.list_acl',
+                                               'acl_app'        => 'rental'))
                                ),
-                               'composite_standard'    => array
-                               (
-                                       'text'  => lang('composite standard'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'composite_standard', 'admin' => true) )
+                               'composite_standard'     => array
+                                       (
+                                       'text'   => lang('composite standard'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index',
+                                               'type'           => 
'composite_standard', 'admin'                => true))
                                ),
-                               'responsibility_unit'   => array
-                               (
-                                       'text'  => lang('responsibility'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'responsibility_unit', 'admin' => true) )
+                               'responsibility_unit'    => array
+                                       (
+                                       'text'   => lang('responsibility'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index',
+                                               'type'           => 
'responsibility_unit', 'admin'               => true))
                                ),
-                               'import'        => array
-                               (
-                                       'text'  => lang('facilit_import'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiimport.index', 'appname' => 'rental') ),
-                                       'image' => array('rental', 
'document-save')
+                               'import'                                 => 
array
+                                       (
+                                       'text'   => lang('facilit_import'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiimport.index',
+                                               'appname'        => 'rental')),
+                                       'image'  => array('rental', 
'document-save')
                                ),
-                               'import_adjustments'    => array
-                               (
-                                       'text'  => lang('import_adjustments'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiimport.import_regulations', 'appname' => 'rental') ),
-                                       'image' => array('rental', 
'document-save')
+                               'import_adjustments'     => array
+                                       (
+                                       'text'   => lang('import_adjustments'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'rental.uiimport.import_regulations',
+                                               'appname'        => 'rental')),
+                                       'image'  => array('rental', 
'document-save')
                                ),
-                               'custom_functions'      => array
-                               (
-                                       'text'  => lang('custom functions'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.ui_custom.list_custom_function','appname' => 'rental', 'location' => 
'.contract', 'menu_selection' => 'admin::rental::custom_functions') )
+                               'custom_functions'               => array
+                                       (
+                                       'text'   => lang('custom functions'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'     => 
'admin.ui_custom.list_custom_function',
+                                               'appname'                => 
'rental', 'location'                 => '.contract', 'menu_selection' => 
'admin::rental::custom_functions'))
                                ),
                        );
-                       
+
                        $menus['folders'] = 
phpgwapi_menu::get_categories('bergen');
-                       
-                       $menus['preferences'] = array
-                       (
+
+                       $menus['preferences']                                   
                 = array
+                               (
                                array
-                               (
-                                       'text'  => lang('Preferences'),
-                                       'url'   => 
$GLOBALS['phpgw']->link('/preferences/preferences.php', array('appname' => 
'rental', 'type'=> 'user') )
+                                       (
+                                       'text'   => lang('Preferences'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/preferences/preferences.php', array('appname'      => 
'rental',
+                                               'type'           => 'user'))
                                ),
                                array
-                               (
-                               'text'  => lang('Grant Access'),
-                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'preferences.uiadmin_acl.list_acl', 'acl_app'=> 'rental'))
+                                       (
+                                       'text'   => lang('Grant Access'),
+                                       'url'    => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'preferences.uiadmin_acl.list_acl',
+                                               'acl_app'        => 'rental'))
                                )
                        );
-                       $GLOBALS['phpgw_info']['flags']['currentapp'] = 
$incoming_app;
+                       $GLOBALS['phpgw_info']['flags']['currentapp']    = 
$incoming_app;
                        return $menus;
                }
-       }
-?>
+       }
\ No newline at end of file

Modified: branches/dev-syncromind/rental/inc/class.soadjustment.inc.php
===================================================================
--- branches/dev-syncromind/rental/inc/class.soadjustment.inc.php       
2015-12-10 14:38:47 UTC (rev 14566)
+++ branches/dev-syncromind/rental/inc/class.soadjustment.inc.php       
2015-12-10 14:57:03 UTC (rev 14567)
@@ -158,9 +158,9 @@
                                $adjustment->get_year()
                        );
 
-                       $values_insert = $this->db->validate_insert($values);
-                       $query   = "INSERT INTO rental_adjustment (" . 
join(',', $cols) . ") VALUES ({$values_insert})";
-                       $result  = $this->db->query($query);
+                       $values_insert   = $this->db->validate_insert($values);
+                       $query                   = "INSERT INTO 
rental_adjustment (" . join(',', $cols) . ") VALUES ({$values_insert})";
+                       $result                  = $this->db->query($query);
 
                        $adjustment_id = 
$this->db->get_last_insert_id('rental_adjustment', 'id');
                        $adjustment->set_id($adjustment_id);
@@ -381,10 +381,10 @@
 
                                                $notification = new 
rental_notification
                                                (
-                                                       0, // No notification 
identifier
-                                                       $account_id, 0, // No 
location identifier
-                                                       null, // No contract id
-                                                       $ts_today, 
$location_label . '_' . $adj_interval, null, null, null, null
+                                               0, // No notification identifier
+         $account_id, 0, // No location identifier
+         null, // No contract id
+         $ts_today, $location_label . '_' . $adj_interval, null, null, null, 
null
                                                );
                                                
rental_soworkbench_notification::get_instance()->store($notification);
                                        }
@@ -411,4 +411,4 @@
                        }
                        return false;
                }
-       }
+       }
\ No newline at end of file

Modified: branches/dev-syncromind/rental/inc/class.sobilling.inc.php
===================================================================
--- branches/dev-syncromind/rental/inc/class.sobilling.inc.php  2015-12-10 
14:38:47 UTC (rev 14566)
+++ branches/dev-syncromind/rental/inc/class.sobilling.inc.php  2015-12-10 
14:57:03 UTC (rev 14567)
@@ -23,7 +23,7 @@
                {
                        if(self::$so == null)
                        {
-                               self::$so = CreateObject('rental.sobilling');
+                               self::$so                                       
                 = CreateObject('rental.sobilling');
                                $virtual_file_system                            
 = CreateObject('phpgwapi.vfs');
                                $virtual_file_system->override_acl       = 1;
                                self::$so->vfs                                  
         = $virtual_file_system;
@@ -161,7 +161,7 @@
                public function add(&$billing)
                {
                        $values  = array
-                       (
+                               (
                                $this->marshal($billing->get_total_sum(), 
'float'),
                                $billing->is_success() ? 'true' : 'false',
                                $this->marshal($billing->get_created_by(), 
'int'),
@@ -187,7 +187,7 @@
                public function update($billing)
                {
                        $values  = array
-                       (
+                               (
                                'total_sum = ' . 
$this->marshal($billing->get_total_sum(), 'float'),
                                "success = '" . ($billing->is_success() ? 
'true' : 'false') . "'",
                                'timestamp_start = ' . 
$this->marshal($billing->get_timestamp_start(), 'int'),
@@ -305,7 +305,7 @@
 
                        foreach($contracts_to_bill as $contract_id) // Runs 
through all the contracts that should be billed in this run
                        {
-                               $invoice = 
rental_invoice::create_invoice($decimals, $billing->get_id(), $contract_id, 
in_array($contract_id, $contracts_overriding_billing_start) ? true : false, 
$bill_from_timestamp, $billing_end_timestamp, in_array($contract_id, 
$contracts_bill_only_one_time) ? true : false, false, $billing_term ); // 
Creates an invoice of the contract
+                               $invoice = 
rental_invoice::create_invoice($decimals, $billing->get_id(), $contract_id, 
in_array($contract_id, $contracts_overriding_billing_start) ? true : false, 
$bill_from_timestamp, $billing_end_timestamp, in_array($contract_id, 
$contracts_bill_only_one_time) ? true : false, false, $billing_term); // 
Creates an invoice of the contract
                                if($invoice != null)
                                {
                                        $total_sum += $invoice->get_total_sum();
@@ -407,12 +407,12 @@
                                        {
                                                $result = $vfs->write
                                                (
-                                                       array
+                                               array
                                                        (
-                                                               'string'        
 => $file_path,
-                                                               RELATIVE_NONE,
-                                                               'content'       
 => $export_data
-                                                       )
+                                                       'string'         => 
$file_path,
+                                                       RELATIVE_NONE,
+                                                       'content'        => 
$export_data
+                                               )
                                                );
                                                if($result)
                                                {
@@ -469,5 +469,4 @@
                        }
                        return '';
                }
-
        }
\ No newline at end of file

Modified: branches/dev-syncromind/rental/inc/class.sobilling_info.inc.php
===================================================================
--- branches/dev-syncromind/rental/inc/class.sobilling_info.inc.php     
2015-12-10 14:38:47 UTC (rev 14566)
+++ branches/dev-syncromind/rental/inc/class.sobilling_info.inc.php     
2015-12-10 14:57:03 UTC (rev 14567)
@@ -1,169 +1,179 @@
 <?php
-phpgw::import_class('rental.socommon');
-phpgw::import_class('rental.uicommon');
+       phpgw::import_class('rental.socommon');
+       phpgw::import_class('rental.uicommon');
 
-include_class('rental', 'billing_info', 'inc/model/');
+       include_class('rental', 'billing_info', 'inc/model/');
 
-class rental_sobilling_info extends rental_socommon
-{
-       protected static $so;
-       
-       /**
-        * Get a static reference to the storage object associated with this 
model object
-        * 
-        * @return the storage object
-        */
-       public static function get_instance()
+       class rental_sobilling_info extends rental_socommon
        {
-               if (self::$so == null) {
-                       self::$so = CreateObject('rental.sobilling_info');
-               }
-               return self::$so;
-       }
-       
-       protected function get_id_field_name()
-       {
-               return 'id';
-       }
-       
-       protected function get_query(string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean $return_count)
-       {
-               $clauses = array('1=1');
-               
-               //Add columns to this array to include them in the query
-               $columns = array();
-               
-               $dir = $ascending ? 'ASC' : 'DESC';
-               $order = $sort_field ? "ORDER BY $sort_field $dir": '';
-               
-               $filter_clauses = array();
-               
-               if(isset($filters[$this->get_id_field_name()])){
-                       $id = 
$this->marshal($filters[$this->get_id_field_name()],'int');
-                       $filter_clauses[] = "{$this->get_id_field_name()} = 
{$id}";
-               }
-               if(isset($filters['billing_id'])){
-                       $filter_clauses[] = "billing_id = 
{$this->marshal($filters['billing_id'], 'int')}";
-               }
-               
-               if(count($filter_clauses))
+
+               protected static $so;
+
+               /**
+                * Get a static reference to the storage object associated with 
this model object
+                * 
+                * @return the storage object
+                */
+               public static function get_instance()
                {
-                       $clauses[] = join(' AND ', $filter_clauses);
+                       if(self::$so == null)
+                       {
+                               self::$so = 
CreateObject('rental.sobilling_info');
+                       }
+                       return self::$so;
                }
-               
-               $condition =  join(' AND ', $clauses);
-               
-               if($return_count) // We should only return a count
+
+               protected function get_id_field_name()
                {
-                       $cols = 'COUNT(DISTINCT(id)) AS count';
+                       return 'id';
                }
-               else
+
+               protected function get_query(string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count)
                {
-                       $cols = '*';
+                       $clauses = array('1=1');
+
+                       //Add columns to this array to include them in the query
+                       $columns = array();
+
+                       $dir     = $ascending ? 'ASC' : 'DESC';
+                       $order   = $sort_field ? "ORDER BY $sort_field $dir" : 
'';
+
+                       $filter_clauses = array();
+
+                       if(isset($filters[$this->get_id_field_name()]))
+                       {
+                               $id                                      = 
$this->marshal($filters[$this->get_id_field_name()], 'int');
+                               $filter_clauses[]        = 
"{$this->get_id_field_name()} = {$id}";
+                       }
+                       if(isset($filters['billing_id']))
+                       {
+                               $filter_clauses[] = "billing_id = 
{$this->marshal($filters['billing_id'], 'int')}";
+                       }
+
+                       if(count($filter_clauses))
+                       {
+                               $clauses[] = join(' AND ', $filter_clauses);
+                       }
+
+                       $condition = join(' AND ', $clauses);
+
+                       if($return_count) // We should only return a count
+                       {
+                               $cols = 'COUNT(DISTINCT(id)) AS count';
+                       }
+                       else
+                       {
+                               $cols = '*';
+                       }
+
+                       $tables  = "rental_billing_info";
+                       $joins   = '';
+//             var_dump("SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}");
+                       return "SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}";
                }
-               
-               $tables = "rental_billing_info";
-               $joins = '';
-//             var_dump("SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}");
-               return "SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}";
-       }
-       
-       protected function populate(int $billing_info_id, &$billing_info)
-       {
-               if($billing_info == null)
+
+               protected function populate(int $billing_info_id, 
&$billing_info)
                {
-                       $billing_info = new 
rental_billing_info($this->unmarshal($this->db->f('id'),'int'));
-                       
$billing_info->set_billing_id($this->unmarshal($this->db->f('billing_id'),'int'));
-                       
$billing_info->set_location_id($this->unmarshal($this->db->f('location_id'),'int'));
-                       
$billing_info->set_term_id($this->unmarshal($this->db->f('term_id'),'int'));
-                       
$billing_info->set_year($this->unmarshal($this->db->f('year'),'int'));
-                       
$billing_info->set_month($this->unmarshal($this->db->f('month'),'int'));
-                       if($billing_info->get_term_id() == 2){ // yearly
-                               $billing_info->set_term_label(lang('annually'));
-                       }
-                       else if($billing_info->get_term_id() == 3){ // half year
-                               if($billing_info->get_month() == 6){
-                                       
$billing_info->set_term_label(lang('first_half'));
+                       if($billing_info == null)
+                       {
+                               $billing_info = new 
rental_billing_info($this->unmarshal($this->db->f('id'), 'int'));
+                               
$billing_info->set_billing_id($this->unmarshal($this->db->f('billing_id'), 
'int'));
+                               
$billing_info->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
+                               
$billing_info->set_term_id($this->unmarshal($this->db->f('term_id'), 'int'));
+                               
$billing_info->set_year($this->unmarshal($this->db->f('year'), 'int'));
+                               
$billing_info->set_month($this->unmarshal($this->db->f('month'), 'int'));
+                               if($billing_info->get_term_id() == 2)
+                               { // yearly
+                                       
$billing_info->set_term_label(lang('annually'));
                                }
-                               else{
-                                       
$billing_info->set_term_label(lang('second_half'));
+                               else if($billing_info->get_term_id() == 3)
+                               { // half year
+                                       if($billing_info->get_month() == 6)
+                                       {
+                                               
$billing_info->set_term_label(lang('first_half'));
+                                       }
+                                       else
+                                       {
+                                               
$billing_info->set_term_label(lang('second_half'));
+                                       }
                                }
-                               
-                       }
-                       else if($billing_info->get_term_id() == 4){ // quarterly
-                               if($billing_info->get_month() == 3){
-                                       
$billing_info->set_term_label(lang('first_quarter'));
+                               else if($billing_info->get_term_id() == 4)
+                               { // quarterly
+                                       if($billing_info->get_month() == 3)
+                                       {
+                                               
$billing_info->set_term_label(lang('first_quarter'));
+                                       }
+                                       else if($billing_info->get_month() == 6)
+                                       {
+                                               
$billing_info->set_term_label(lang('second_quarter'));
+                                       }
+                                       else if($billing_info->get_month() == 9)
+                                       {
+                                               
$billing_info->set_term_label(lang('third_quarter'));
+                                       }
+                                       else
+                                       {
+                                               
$billing_info->set_term_label(lang('fourth_quarter'));
+                                       }
                                }
-                               else if($billing_info->get_month() == 6){
-                                       
$billing_info->set_term_label(lang('second_quarter'));
-                               }
-                               else if($billing_info->get_month() == 9){
-                                       
$billing_info->set_term_label(lang('third_quarter'));
-                               }
-                               else{
-                                       
$billing_info->set_term_label(lang('fourth_quarter'));
-                               }
                        }
+                       return $billing_info;
                }
-               return $billing_info;
-       }
-       
-       /**
-        * Add a new contract_price_item to the database.  Adds the new insert 
id to the object reference.
-        * 
-        * @param $billing_info the billing_info to be added
-        * @return mixed receipt from the db operation
-        */
-       protected function add(&$billing_info)
-       {
-               // Build a db-friendly array of the composite object
-               $values = array(
-                       $billing_info->get_billing_id(),
-                       $billing_info->get_term_id(),
-                       $billing_info->get_location_id(),
-                       $billing_info->get_month(),
-                       $billing_info->get_year(),
-                       ($billing_info->is_deleted() ? "true" : "false")
-               );
-               
-               $cols = array('billing_id', 'term_id', 'location_id', 'month', 
'year', 'deleted');
-               
-               $q ="INSERT INTO rental_billing_info (" . join(',', $cols) . ") 
VALUES (" . join(',', $values) . ")";
 
-               $result = $this->db->query($q);
-               $receipt['id'] = 
$this->db->get_last_insert_id("rental_billing_info", 'id');
-               
-               $billing_info->set_id($receipt['id']);
-               
-               return $receipt;
-       }
-       
-       /**
-        * Update the database values for an existing contract billing_info.
-        * 
-        * @param $billing_info the billing info to be updated
-        * @return result receipt from the db operation
-        */
-       protected function update($billing_info)
-       {
-               $id = intval($billing_info->get_id());
-               
-               // Build a db-friendly array of the composite object
-               $values = array(
-                       "billing_id = " . 
$this->marshal($billing_info->get_billing_id(), 'int'),
-                       "term_id = " . 
$this->marshal($billing_info->get_term_id(), 'int'),
-                       "location_id = " . 
$this->marshal($billing_info->get_location_id(), 'int'),
-                       "month = " . $this->marshal($billing_info->get_month(), 
'int'),
-                       "year = " . $this->marshal($billing_info->get_year(), 
'int'),
-                       "deleted = " . ($billing_info->is_deleted() ? "true" : 
"false")
-               );
+               /**
+                * Add a new contract_price_item to the database.  Adds the new 
insert id to the object reference.
+                *
+                * @param $billing_info the billing_info to be added
+                * @return mixed receipt from the db operation
+                */
+               protected function add(&$billing_info)
+               {
+                       // Build a db-friendly array of the composite object
+                       $values = array(
+                               $billing_info->get_billing_id(),
+                               $billing_info->get_term_id(),
+                               $billing_info->get_location_id(),
+                               $billing_info->get_month(),
+                               $billing_info->get_year(),
+                               ($billing_info->is_deleted() ? "true" : "false")
+                       );
 
-               $this->db->query('UPDATE rental_billing_info SET ' . join(',', 
$values) . " WHERE id=$id", __LINE__,__FILE__);
-               
-               $receipt['id'] = $id;
-               $receipt['message'][] = array('msg'=>lang('Entity %1 has been 
updated', $entry['id']));
-               return $receipt;
-       }
-}
+                       $cols = array('billing_id', 'term_id', 'location_id', 
'month', 'year', 'deleted');
 
-?>
+                       $q = "INSERT INTO rental_billing_info (" . join(',', 
$cols) . ") VALUES (" . join(',', $values) . ")";
+
+                       $result                  = $this->db->query($q);
+                       $receipt['id']   = 
$this->db->get_last_insert_id("rental_billing_info", 'id');
+
+                       $billing_info->set_id($receipt['id']);
+
+                       return $receipt;
+               }
+
+               /**
+                * Update the database values for an existing contract 
billing_info.
+                *
+                * @param $billing_info the billing info to be updated
+                * @return result receipt from the db operation
+                */
+               protected function update($billing_info)
+               {
+                       $id = intval($billing_info->get_id());
+
+                       // Build a db-friendly array of the composite object
+                       $values = array(
+                               "billing_id = " . 
$this->marshal($billing_info->get_billing_id(), 'int'),
+                               "term_id = " . 
$this->marshal($billing_info->get_term_id(), 'int'),
+                               "location_id = " . 
$this->marshal($billing_info->get_location_id(), 'int'),
+                               "month = " . 
$this->marshal($billing_info->get_month(), 'int'),
+                               "year = " . 
$this->marshal($billing_info->get_year(), 'int'),
+                               "deleted = " . ($billing_info->is_deleted() ? 
"true" : "false")
+                       );
+
+                       $this->db->query('UPDATE rental_billing_info SET ' . 
join(',', $values) . " WHERE id=$id", __LINE__, __FILE__);
+
+                       $receipt['id']                   = $id;
+                       $receipt['message'][]    = array('msg' => lang('Entity 
%1 has been updated', $entry['id']));
+                       return $receipt;
+               }
+       }
\ No newline at end of file

Modified: branches/dev-syncromind/rental/inc/class.socommon.inc.php
===================================================================
--- branches/dev-syncromind/rental/inc/class.socommon.inc.php   2015-12-10 
14:38:47 UTC (rev 14566)
+++ branches/dev-syncromind/rental/inc/class.socommon.inc.php   2015-12-10 
14:57:03 UTC (rev 14567)
@@ -1,405 +1,407 @@
 <?php
-abstract class rental_socommon
-{
-       protected $db;
-       protected $like;
-       protected $join;
-       protected $left_join;
-       protected $sort_field;
-       protected $skip_limit_query;
 
+       abstract class rental_socommon
+       {
 
-       public function __construct()
-       {
-               $this->db                               = clone 
$GLOBALS['phpgw']->db;
-               $this->like                             = & $this->db->like;
-               $this->join                             = & $this->db->join;
-               $this->left_join                = & $this->db->left_join;
-               $this->sort_field               = null;
-               $this->skip_limit_query = null;
-       }
-       
+               protected $db;
+               protected $like;
+               protected $join;
+               protected $left_join;
+               protected $sort_field;
+               protected $skip_limit_query;
+
+               public function __construct()
+               {
+                       $this->db                                = clone 
$GLOBALS['phpgw']->db;
+                       $this->like                              = & 
$this->db->like;
+                       $this->join                              = & 
$this->db->join;
+                       $this->left_join                 = & 
$this->db->left_join;
+                       $this->sort_field                = null;
+                       $this->skip_limit_query  = null;
+               }
+
                /**
-               * Begin transaction
-               *
-               * @return integer|boolean current transaction id
-               */
+                * Begin transaction
+                *
+                * @return integer|boolean current transaction id
+                */
                public function transaction_begin()
                {
                        return $this->db->transaction_begin();
                }
 
                /**
-               * Complete the transaction
-               *
-               * @return boolean True if sucessful, False if fails
-               */ 
+                * Complete the transaction
+                *
+                * @return boolean True if sucessful, False if fails
+                */
                public function transaction_commit()
                {
                        return $this->db->transaction_commit();
                }
 
                /**
-               * Rollback the current transaction
-               *
-               * @return boolean True if sucessful, False if fails
-               */
+                * Rollback the current transaction
+                *
+                * @return boolean True if sucessful, False if fails
+                */
                public function transaction_abort()
                {
                        return $this->db->transaction_abort();
                }
 
-
-       /**
-        * Marshal values according to type
-        * @param $value the value
-        * @param $type the type of value
-        * @return database value
-        */
-       protected function marshal($value, $type)
-       {
-               if($value === null)
+               /**
+                * Marshal values according to type
+                * @param $value the value
+                * @param $type the type of value
+                * @return database value
+                */
+               protected function marshal($value, $type)
                {
-                       return 'NULL';
-               }
-               else if($type == 'int')
-               {
-                       if($value == '')
+                       if($value === null)
                        {
                                return 'NULL';
                        }
-                       return intval($value);
+                       else if($type == 'int')
+                       {
+                               if($value == '')
+                               {
+                                       return 'NULL';
+                               }
+                               return intval($value);
+                       }
+                       else if($type == 'float')
+                       {
+                               return str_replace(',', '.', $value);
+                       }
+                       else if($type == 'field')
+                       {
+                               return $this->db->db_addslashes($value);
+                       }
+                       return "'" . $this->db->db_addslashes($value) . "'";
                }
-               else if($type == 'float')
+
+               /**
+                * Unmarchal database values according to type
+                * @param $value the field value
+                * @param $type a string dictating value type
+                * @return the php value
+                */
+               protected function unmarshal($value, $type)
                {
-                       return str_replace(',', '.', $value);
+                       if($type == 'bool')
+                       {
+                               return (boolean)$value;
+                       }
+                       elseif($value === null || $value == 'NULL')
+                       {
+                               return null;
+                       }
+                       elseif($type == 'int')
+                       {
+                               return intval($value);
+                       }
+                       elseif($type == 'float')
+                       {
+                               return floatval($value);
+                       }
+                       return $value;
                }
-               else if($type == 'field')
-               {
-                       return $this->db->db_addslashes($value);
-               }
-               return "'" . $this->db->db_addslashes($value) . "'";
-       }
 
-       /**
-        * Unmarchal database values according to type
-        * @param $value the field value
-        * @param $type a string dictating value type
-        * @return the php value
-        */
-       protected function unmarshal($value, $type)
-       {
-               if($type == 'bool')
+               /**
+                * Get the count of the specified query. Query must return a 
signel column
+                * called count.
+                * 
+                * @param $sql the sql query
+                * @return the count value
+                */
+               protected function get_query_count($sql)
                {
-                       return (boolean)$value;
+                       $result = $this->db->query($sql);
+                       if($result && $this->db->next_record())
+                       {
+                               return $this->unmarshal($this->db->f('count', 
true), 'int');
+                       }
                }
-               elseif($value === null || $value == 'NULL')
-               {
-                       return null;
-               }
-               elseif($type == 'int')
-               {
-                       return intval($value);
-               }
-        elseif($type == 'float')
-        {
-            return floatval($value);
-        }
-               return $value;
-       }
 
-       /**
-        * Get the count of the specified query. Query must return a signel 
column
-        * called count.
-        * 
-        * @param $sql the sql query
-        * @return the count value
-        */
-       protected function get_query_count($sql)
-       {
-               $result = $this->db->query($sql);
-               if($result && $this->db->next_record())
-               {
-                       return $this->unmarshal($this->db->f('count', true), 
'int');
-               } 
-       }
-       
-       /**
-        * Implementing classes must return an instance of itself.
-        *  
-        * @return the class instance.
-        */
-       public abstract static function get_instance();
+               /**
+                * Implementing classes must return an instance of itself.
+                *  
+                * @return the class instance.
+                */
+               public abstract static function get_instance();
 
-       /**
-        * Convenience method for getting one single object. Calls get() with 
the
-        * specified id as a filter.
-        * 
-        * @param $id int with id of object to return.
-        * @return object with the specified id, null if not found.
-        */
-       public function get_single(int $id)
-       {
-               $objects = $this->get(null, null, null, null, null, null, 
array($this->get_id_field_name() => $id));
-               if(count($objects) > 0)
+               /**
+                * Convenience method for getting one single object. Calls 
get() with the
+                * specified id as a filter.
+                *
+                * @param $id int with id of object to return.
+                * @return object with the specified id, null if not found.
+                */
+               public function get_single(int $id)
                {
-                       $keys = array_keys($objects);
-                       return $objects[$keys[0]];
+                       $objects = $this->get(null, null, null, null, null, 
null, array($this->get_id_field_name() => $id));
+                       if(count($objects) > 0)
+                       {
+                               $keys = array_keys($objects);
+                               return $objects[$keys[0]];
+                       }
+                       return null;
                }
-               return null;
-       }
-       
-       /**
-        * Method for retrieving the db-object (security "forgotten")
-        */
-       public function get_db(){
-               return $this->db;
-       }
 
-       /**
-        * Method for retreiving objects.
-        * 
-        * @param $start_index int with index of first object.
-        * @param $num_of_objects int with max number of objects to return.
-        * @param $sort_field string representing the object field to sort on.
-        * @param $ascending boolean true for ascending sort on sort field, 
false
-        * for descending.
-        * @param $search_for string with free text search query.
-        * @param $search_type string with the query type.
-        * @param $filters array with key => value of filters.
-        * @return array of objects. May return an empty
-        * array, never null. The array keys are the respective index numbers.
-        */
-       public function get(int $start_index, int $num_of_objects, string 
$sort_field, boolean $ascending, string $search_for, string $search_type, array 
$filters)
-       {
-               $results = array();                     // Array to store 
result objects
-               $map = array();                         // Array to hold number 
of records per target object
-               $check_map = array();           // Array to hold the actual 
number of record read per target object
-               $object_ids = array();          // All of the object ids 
encountered
-               $added_object_ids = array();// All of the added objects ids
-               
-               // Retrieve information about the table name and the name and 
alias of id column
-               // $break_on_limit -    flag indicating whether to break the 
loop when the number of records 
-               //                                              for all the 
result objects are traversed
-               $id_field_name_info = $this->get_id_field_name(true);
-               if(is_array($id_field_name_info))
+               /**
+                * Method for retrieving the db-object (security "forgotten")
+                */
+               public function get_db()
                {
-                       $break_on_limit = true;
-                       $id_field_name = $id_field_name_info['translated'];
+                       return $this->db;
                }
-               else
-               {
-                       $break_on_limit = false;
-                       $id_field_name = $id_field_name_info;
-               }
 
-               // Special case: Sort on id field. Always changed to the id 
field name.
-               // $break_when_num_of_objects_reached - flag indicating to 
break the loop when the number of 
-               //              results are reached and we are sure that the 
records are ordered by the id
-               if($sort_field == null || $sort_field == 'id' || $sort_field == 
'')
-               {
-                       $sort_field = $id_field_name;
-                       $break_when_num_of_objects_reached = true;
-               }
-               else
-               {
-                       $break_when_num_of_objects_reached = false;
-               }
-               
-               // Only allow positive start index
-               if($start_index < 0)
-               {
-                       $start_index = 0;
-               }
-               
-
-               // test-input for break on ordered queries
-               $db2 = clone($this->db);
-
-               $sql = $this->get_query($sort_field, $ascending, $search_for, 
$search_type, $filters, false);
-               $sql_parts = explode('1=1',$sql); // Split the query to insert 
extra condition on test for break
-
                /**
-                * Sigurd: try to limit the candidates to a minimum
+                * Method for retreiving objects.
+                *
+                * @param $start_index int with index of first object.
+                * @param $num_of_objects int with max number of objects to 
return.
+                * @param $sort_field string representing the object field to 
sort on.
+                * @param $ascending boolean true for ascending sort on sort 
field, false
+                * for descending.
+                * @param $search_for string with free text search query.
+                * @param $search_type string with the query type.
+                * @param $filters array with key => value of filters.
+                * @return array of objects. May return an empty
+                * array, never null. The array keys are the respective index 
numbers.
                 */
-               $bypass_offset_check = false;
-               if(!$this->skip_limit_query && $num_of_objects && 
is_array($id_field_name_info) && $id_field_name_info['translated'])
+               public function get(int $start_index, int $num_of_objects, 
string $sort_field, boolean $ascending, string $search_for, string 
$search_type, array $filters)
                {
-                       $bypass_offset_check = true;
-                       $sql_parts_filter = explode('FROM',$sql, 2);
-
-                       $sql_filter = "SELECT DISTINCT 
{$id_field_name_info['table']}.{$id_field_name_info['field']} AS 
{$id_field_name_info['translated']}";
-
-                       if($this->sort_field)
+                       $results                         = array();   // Array 
to store result objects
+                       $map                             = array(); // Array to 
hold number of records per target object
+                       $check_map                       = array();  // Array 
to hold the actual number of record read per target object
+                       $object_ids                      = array();   // All of 
the object ids encountered
+                       $added_object_ids        = array();// All of the added 
objects ids
+                       // Retrieve information about the table name and the 
name and alias of id column
+                       // $break_on_limit -    flag indicating whether to 
break the loop when the number of records
+                       //                                              for all 
the result objects are traversed
+                       $id_field_name_info      = 
$this->get_id_field_name(true);
+                       if(is_array($id_field_name_info))
                        {
-                               if(is_array($this->sort_field))
-                               {
-                                       $_sort_field = implode(',', 
$this->sort_field);
-                               }
-                               else
-                               {
-                                       $_sort_field = $this->sort_field;
-                               }
+                               $break_on_limit  = true;
+                               $id_field_name   = 
$id_field_name_info['translated'];
                        }
                        else
                        {
-                               $_sort_field =  $sort_field;
+                               $break_on_limit  = false;
+                               $id_field_name   = $id_field_name_info;
                        }
 
-                       if($_sort_field && $_sort_field != 
$id_field_name_info['translated'])
+                       // Special case: Sort on id field. Always changed to 
the id field name.
+                       // $break_when_num_of_objects_reached - flag indicating 
to break the loop when the number of
+                       //              results are reached and we are sure 
that the records are ordered by the id
+                       if($sort_field == null || $sort_field == 'id' || 
$sort_field == '')
                        {
-                               $sql_filter .= ",{$_sort_field}";
+                               $sort_field                                     
                 = $id_field_name;
+                               $break_when_num_of_objects_reached       = true;
                        }
-
-                       $sql_filter .= " FROM {$sql_parts_filter[1]}";
-
-                       $this->db->limit_query($sql_filter, $start_index, 
__LINE__, __FILE__, (int)$num_of_objects);
-                       $ids = array();
-                       while ($this->db->next_record())
+                       else
                        {
-                               $ids[] = 
$this->db->f($id_field_name_info['translated']);
+                               $break_when_num_of_objects_reached = false;
                        }
 
-                       if($ids)
+                       // Only allow positive start index
+                       if($start_index < 0)
                        {
-                               $id_filter = 
"{$id_field_name_info['table']}.{$id_field_name_info['field']} IN(" . 
implode(',', $ids) . ') ';
-                               $sql = str_replace('1=1', $id_filter, $sql);
+                               $start_index = 0;
                        }
-               }
 
-               $this->db->query($sql,__LINE__, __FILE__, false, true);
 
-               while ($this->db->next_record()) // Runs through all of the 
results
-               {
-                       $should_populate_object = false; // Default value - we 
won't populate object    
-                       $result_id = 
$this->unmarshal($this->db->f($id_field_name), 'int'); // The id of object
-                       if(in_array($result_id, $added_object_ids)) // Object 
with this id already added
+                       // test-input for break on ordered queries
+                       $db2 = clone($this->db);
+
+                       $sql             = $this->get_query($sort_field, 
$ascending, $search_for, $search_type, $filters, false);
+                       $sql_parts       = explode('1=1', $sql); // Split the 
query to insert extra condition on test for break
+
+                       /**
+                        * Sigurd: try to limit the candidates to a minimum
+                        */
+                       $bypass_offset_check = false;
+                       if(!$this->skip_limit_query && $num_of_objects && 
is_array($id_field_name_info) && $id_field_name_info['translated'])
                        {
-                               $should_populate_object = true; // We should 
populate this object as we already have it in our result array
-                       }
-                       else // Object isn't already added to array
-                       {
-                               if(!in_array($result_id, $object_ids)) // 
Haven't already added this id
+                               $bypass_offset_check = true;
+                               $sql_parts_filter        = explode('FROM', 
$sql, 2);
+
+                               $sql_filter = "SELECT DISTINCT 
{$id_field_name_info['table']}.{$id_field_name_info['field']} AS 
{$id_field_name_info['translated']}";
+
+                               if($this->sort_field)
                                {
-                                       $object_ids[] = $result_id; // We have 
to add the new id
-                               }
-                               // We have to check if we should populate this 
object
-                               if($bypass_offset_check || ( count($object_ids) 
> $start_index) ) // We're at index above start index
-                               {
-                                       if($num_of_objects == null || 
count($results) < $num_of_objects) // We haven't found all the objects we're 
looking for
+                                       if(is_array($this->sort_field))
                                        {
-                                               $should_populate_object = true; 
// We should populate this object
-                                               $added_object_ids[] = 
$result_id; // We keep the id
+                                               $_sort_field = implode(',', 
$this->sort_field);
                                        }
+                                       else
+                                       {
+                                               $_sort_field = 
$this->sort_field;
+                                       }
                                }
+                               else
+                               {
+                                       $_sort_field = $sort_field;
+                               }
+
+                               if($_sort_field && $_sort_field != 
$id_field_name_info['translated'])
+                               {
+                                       $sql_filter .= ",{$_sort_field}";
+                               }
+
+                               $sql_filter .= " FROM {$sql_parts_filter[1]}";
+
+                               $this->db->limit_query($sql_filter, 
$start_index, __LINE__, __FILE__, (int)$num_of_objects);
+                               $ids = array();
+                               while($this->db->next_record())
+                               {
+                                       $ids[] = 
$this->db->f($id_field_name_info['translated']);
+                               }
+
+                               if($ids)
+                               {
+                                       $id_filter       = 
"{$id_field_name_info['table']}.{$id_field_name_info['field']} IN(" . 
implode(',', $ids) . ') ';
+                                       $sql             = str_replace('1=1', 
$id_filter, $sql);
+                               }
                        }
-                       if($should_populate_object)
-                       {       
-                               $result = &$results[$result_id];
-                               $results[$result_id] = 
$this->populate($result_id,$result);
-                               $last_result_id = $result_id;
-                               $map[$result_id] = (int)$map[$result_id] +1;
-                       }
-                       
-                       //Stop looping when array not sorted on other then id 
and wanted number of results is reached
-                       if(count($results) == $num_of_objects  && 
$last_result_id != $result_id && $break_when_num_of_objects_reached)
+
+                       $this->db->query($sql, __LINE__, __FILE__, false, true);
+
+                       while($this->db->next_record()) // Runs through all of 
the results
                        {
-                               break;
-                       }
-                       // else stop looping when wanted number of results is 
reached all records for result objects are read
-                       else if($break_on_limit && (count($results) == 
$num_of_objects)  && $last_result_id != $result_id)
-                       {
-                               $id_ok = 0;
-                               foreach ($map as $_result_id => $_count)
+                               $should_populate_object  = false; // Default 
value - we won't populate object
+                               $result_id                               = 
$this->unmarshal($this->db->f($id_field_name), 'int'); // The id of object
+                               if(in_array($result_id, $added_object_ids)) // 
Object with this id already added
                                {
-                                       if(!isset($check_map[$_result_id]))
+                                       $should_populate_object = true; // We 
should populate this object as we already have it in our result array
+                               }
+                               else // Object isn't already added to array
+                               {
+                                       if(!in_array($result_id, $object_ids)) 
// Haven't already added this id
                                        {
-                                               // Query the number of records 
for the specific object in question
-                                               $sql2 = "{$sql_parts[0]} 1=1 
AND {$id_field_name_info['table']}.{$id_field_name_info['field']} = 
{$_result_id} {$sql_parts[1]}";
-                                               $db2->query($sql2,__LINE__, 
__FILE__);
-                                               $db2->next_record();
-                                               $check_map[$_result_id] = 
$db2->num_rows();
+                                               $object_ids[] = $result_id; // 
We have to add the new id
                                        }
-                                       if(     $check_map[$_result_id] == 
$_count )
+                                       // We have to check if we should 
populate this object
+                                       if($bypass_offset_check || ( 
count($object_ids) > $start_index)) // We're at index above start index
                                        {
-                                               $id_ok++;
+                                               if($num_of_objects == null || 
count($results) < $num_of_objects) // We haven't found all the objects we're 
looking for
+                                               {
+                                                       $should_populate_object 
 = true; // We should populate this object
+                                                       $added_object_ids[]     
         = $result_id; // We keep the id
+                                               }
                                        }
                                }
-                               if($id_ok == $num_of_objects)
+                               if($should_populate_object)
                                {
+                                       $result                          = 
&$results[$result_id];
+                                       $results[$result_id] = 
$this->populate($result_id, $result);
+                                       $last_result_id          = $result_id;
+                                       $map[$result_id]         = 
(int)$map[$result_id] + 1;
+                               }
+
+                               //Stop looping when array not sorted on other 
then id and wanted number of results is reached
+                               if(count($results) == $num_of_objects && 
$last_result_id != $result_id && $break_when_num_of_objects_reached)
+                               {
                                        break;
                                }
+                               // else stop looping when wanted number of 
results is reached all records for result objects are read
+                               else if($break_on_limit && (count($results) == 
$num_of_objects) && $last_result_id != $result_id)
+                               {
+                                       $id_ok = 0;
+                                       foreach($map as $_result_id => $_count)
+                                       {
+                                               
if(!isset($check_map[$_result_id]))
+                                               {
+                                                       // Query the number of 
records for the specific object in question
+                                                       $sql2                   
                 = "{$sql_parts[0]} 1=1 AND 
{$id_field_name_info['table']}.{$id_field_name_info['field']} = {$_result_id} 
{$sql_parts[1]}";
+                                                       $db2->query($sql2, 
__LINE__, __FILE__);
+                                                       $db2->next_record();
+                                                       $check_map[$_result_id] 
 = $db2->num_rows();
+                                               }
+                                               if($check_map[$_result_id] == 
$_count)
+                                               {
+                                                       $id_ok++;
+                                               }
+                                       }
+                                       if($id_ok == $num_of_objects)
+                                       {
+                                               break;
+                                       }
+                               }
                        }
+
+                       $this->db->set_fetch_single(false);
+
+                       return $results;
                }
 
-               $this->db->set_fetch_single(false);
+               /**
+                * Returns count of matching objects.
+                * 
+                * @param $search_for string with free text search query.
+                * @param $search_type string with the query type.
+                * @param $filters array with key => value of filters.
+                * @return int with object count.
+                */
+               public function get_count(string $search_for, string 
$search_type, array $filters)
+               {
+                       return $this->get_query_count($this->get_query(null, 
null, $search_for, $search_type, $filters, true));
+               }
 
-               return $results;
-       }
-       
-       /**
-        * Returns count of matching objects.
-        * 
-        * @param $search_for string with free text search query.
-        * @param $search_type string with the query type.
-        * @param $filters array with key => value of filters.
-        * @return int with object count.
-        */
-       public function get_count(string $search_for, string $search_type, 
array $filters)
-       {
-               return $this->get_query_count($this->get_query(null, null, 
$search_for, $search_type, $filters, true));
-       }
-       
-       /**
-        * Implementing classes must return the name of the field used in the 
query
-        * returned from get_query().
-        * 
-        * @return string with name of id field.
-        */
-       protected abstract function get_id_field_name();
-       
-       /**
-        * Returns SQL for retrieving matching objects or object count.
-        * 
-        * @param $start_index int with index of first object.
-        * @param $num_of_objects int with max number of objects to return.
-        * @param $sort_field string representing the object field to sort on.
-        * @param $ascending boolean true for ascending sort on sort field, 
false
-        * for descending.
-        * @param $search_for string with free text search query.
-        * @param $search_type string with the query type.
-        * @param $filters array with key => value of filters.
-        * @param $return_count boolean telling to return only the count of the
-        * matching objects, or the objects themself.
-        * @return string with SQL.
-        */
-       protected abstract function get_query(string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count);
-       
-       protected abstract function populate(int $object_id, &$object);
-       
-       protected abstract function add(&$object);
-       
-       protected abstract function update($object);
-       
-       /**
-       * Store the object in the database.  If the object has no ID it is 
assumed to be new and
-       * inserted for the first time.  The object is then updated with the new 
insert id.
-       */
-       public function store(&$object)
-       {
-               if ($object->validates()) {
-                       if ($object->get_id() > 0) {
-                               // We can assume this composite came from the 
database since it has an ID. Update the existing row
-                               return $this->update($object);
-                       }
-                       else
+               /**
+                * Implementing classes must return the name of the field used 
in the query
+                * returned from get_query().
+                * 
+                * @return string with name of id field.
+                */
+               protected abstract function get_id_field_name();
+
+               /**
+                * Returns SQL for retrieving matching objects or object count.
+                *
+                * @param $start_index int with index of first object.
+                * @param $num_of_objects int with max number of objects to 
return.
+                * @param $sort_field string representing the object field to 
sort on.
+                * @param $ascending boolean true for ascending sort on sort 
field, false
+                * for descending.
+                * @param $search_for string with free text search query.
+                * @param $search_type string with the query type.
+                * @param $filters array with key => value of filters.
+                * @param $return_count boolean telling to return only the 
count of the
+                * matching objects, or the objects themself.
+                * @return string with SQL.
+                */
+               protected abstract function get_query(string $sort_field, 
boolean $ascending, string $search_for, string $search_type, array $filters, 
boolean $return_count);
+
+               protected abstract function populate(int $object_id, &$object);
+
+               protected abstract function add(&$object);
+
+               protected abstract function update($object);
+
+               /**
+                * Store the object in the database.  If the object has no ID 
it is assumed to be new and
+                * inserted for the first time.  The object is then updated 
with the new insert id.
+                */
+               public function store(&$object)
+               {
+                       if($object->validates())
                        {
-                               // This object does not have an ID, so will be 
saved as a new DB row
-                               return $this->add($object);
+                               if($object->get_id() > 0)
+                               {
+                                       // We can assume this composite came 
from the database since it has an ID. Update the existing row
+                                       return $this->update($object);
+                               }
+                               else
+                               {
+                                       // This object does not have an ID, so 
will be saved as a new DB row
+                                       return $this->add($object);
+                               }
                        }
+
+                       // The object did not validate
+                       return false;
                }
-
-               // The object did not validate
-               return false;
-       }
-}
\ No newline at end of file
+       }
\ No newline at end of file

Modified: branches/dev-syncromind/rental/inc/class.socomposite.inc.php
===================================================================
--- branches/dev-syncromind/rental/inc/class.socomposite.inc.php        
2015-12-10 14:38:47 UTC (rev 14566)
+++ branches/dev-syncromind/rental/inc/class.socomposite.inc.php        
2015-12-10 14:57:03 UTC (rev 14567)
@@ -1,101 +1,108 @@
 <?php
-phpgw::import_class('rental.socommon');
-phpgw::import_class('rental.uicommon');
+       phpgw::import_class('rental.socommon');
+       phpgw::import_class('rental.uicommon');
 
-include_class('rental', 'composite', 'inc/model/');
-include_class('rental', 'property_location', 'inc/model/');
+       include_class('rental', 'composite', 'inc/model/');
+       include_class('rental', 'property_location', 'inc/model/');
 
-class rental_socomposite extends rental_socommon
-{
-       protected static $so;
-               
-       /**
-        * Get a static reference to the storage object associated with this 
model object
-        * 
-        * @return the storage object
-        */
-       public static function get_instance()
-       {                                                                       
-               if (self::$so == null) {                
-                       self::$so = CreateObject('rental.socomposite');
+       class rental_socomposite extends rental_socommon
+       {
+
+               protected static $so;
+
+               /**
+                * Get a static reference to the storage object associated with 
this model object
+                *
+                * @return the storage object
+                */
+               public static function get_instance()
+               {
+                       if(self::$so == null)
+                       {
+                               self::$so = CreateObject('rental.socomposite');
+                       }
+
+                       return self::$so;
                }
-               
-               return self::$so;
-       }
 
-       protected function get_query(string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean $return_count)
-       {
-               $location_id_into = $GLOBALS['phpgw']->locations->get_id( 
'rental', '.RESPONSIBILITY.INTO');
+               protected function get_query(string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count)
+               {
+                       $location_id_into = 
$GLOBALS['phpgw']->locations->get_id('rental', '.RESPONSIBILITY.INTO');
 
-               $clauses = array('1=1');
-               if($search_for)
-               {
-                       $like_pattern = "'%" . 
$this->db->db_addslashes($search_for) . "%'";
-                       $like_clauses = array();
-                       switch($search_type){
-                               case "name":
-                                       $like_clauses[] = 
"rental_composite.name $this->like $like_pattern";
+                       $clauses = array('1=1');
+                       if($search_for)
+                       {
+                               $like_pattern    = "'%" . 
$this->db->db_addslashes($search_for) . "%'";
+                               $like_clauses    = array();
+                               switch($search_type)
+                               {
+                                       case "name":
+                                               $like_clauses[]  = 
"rental_composite.name $this->like $like_pattern";
+                                               break;
+                                       case "address":
+                                               $like_clauses[]  = 
"rental_composite.address_1 $this->like $like_pattern";
+                                               $like_clauses[]  = 
"rental_composite.address_2 $this->like $like_pattern";
+                                               $like_clauses[]  = 
"rental_composite.house_number $this->like $like_pattern";
+                                               break;
+                                       case "property_id":
+                                               $like_clauses[]  = 
"rental_unit.location_code $this->like $like_pattern";
+                                               break;
+                                       case "all":
+                                               $like_clauses[]  = 
"rental_composite.name $this->like $like_pattern";
+                                               $like_clauses[]  = 
"rental_composite.address_1 $this->like $like_pattern";
+                                               $like_clauses[]  = 
"rental_composite.address_2 $this->like $like_pattern";
+                                               $like_clauses[]  = 
"rental_composite.house_number $this->like $like_pattern";
+                                               $like_clauses[]  = 
"rental_unit.location_code $this->like $like_pattern";
+                                               break;
+                               }
+                               if(count($like_clauses))
+                               {
+                                       $clauses[] = '(' . join(' OR ', 
$like_clauses) . ')';
+                               }
+                       }
+
+                       $filter_clauses = array();
+                       switch($filters['is_active'])
+                       {
+                               case "active":
+                                       $filter_clauses[]        = 
"rental_composite.is_active = TRUE";
                                        break;
-                               case "address":
-                                       $like_clauses[] = 
"rental_composite.address_1 $this->like $like_pattern";
-                                       $like_clauses[] = 
"rental_composite.address_2 $this->like $like_pattern";
-                                       $like_clauses[] = 
"rental_composite.house_number $this->like $like_pattern";
+                               case "non_active":
+                                       $filter_clauses[]        = 
"rental_composite.is_active = FALSE";
                                        break;
-                               case "property_id":
-                                       $like_clauses[] = 
"rental_unit.location_code $this->like $like_pattern";
+                               case "both":
                                        break;
-                               case "all":
-                                       $like_clauses[] = 
"rental_composite.name $this->like $like_pattern";
-                                       $like_clauses[] = 
"rental_composite.address_1 $this->like $like_pattern";
-                                       $like_clauses[] = 
"rental_composite.address_2 $this->like $like_pattern";
-                                       $like_clauses[] = 
"rental_composite.house_number $this->like $like_pattern";
-                                       $like_clauses[] = 
"rental_unit.location_code $this->like $like_pattern";
-                                       break;
                        }
-                       if(count($like_clauses))
+                       $special_query                   = false; //specify if 
the query should use distinct on rental_composite.id (used for selecting 
composites that has an active or inactive contract)
+                       $ts_query                                = 
strtotime(date('Y-m-d')); // timestamp for query (today)
+                       $availability_date_from  = $ts_query;
+                       $availability_date_to    = $ts_query;
+
+                       if(isset($filters['availability_date_from']) && 
$filters['availability_date_from'] != '')
                        {
-                               $clauses[] = '(' . join(' OR ', $like_clauses) 
. ')';
+                               $availability_date_from = 
strtotime($filters['availability_date_from']);
                        }
-               }
 
-               $filter_clauses = array();
-               switch($filters['is_active']){
-                       case "active":
-                               $filter_clauses[] = "rental_composite.is_active 
= TRUE";
-                               break;
-                       case "non_active":
-                               $filter_clauses[] = "rental_composite.is_active 
= FALSE";
-                               break;
-                       case "both":
-                               break;
-               }
-               $special_query = false; //specify if the query should use 
distinct on rental_composite.id (used for selecting composites that has an 
active or inactive contract)
-               $ts_query = strtotime(date('Y-m-d')); // timestamp for query 
(today)
-               $availability_date_from = $ts_query;
-               $availability_date_to = $ts_query;
-               
-               if(isset($filters['availability_date_from']) && 
$filters['availability_date_from'] != ''){
-                       $availability_date_from = 
strtotime($filters['availability_date_from']); 
-               }
-               
-               if(isset($filters['availability_date_to']) && 
$filters['availability_date_to'] != ''){
-                       $availability_date_to = 
strtotime($filters['availability_date_to']); 
-               }
-               
-               switch($filters['has_contract']){
-                       case "has_contract":
-                               $filter_clauses[] = "NOT 
rental_contract_composite.contract_id IS NULL"; // Composite must have a 
contract
-                               $filter_clauses[] = "NOT 
rental_contract.date_start IS NULL"; // The contract must have start date
-                               
-                               /* The contract's start date not after the end 
of the period if there is no end date */
-                               $filter_clauses[] = "
+                       if(isset($filters['availability_date_to']) && 
$filters['availability_date_to'] != '')
+                       {
+                               $availability_date_to = 
strtotime($filters['availability_date_to']);
+                       }
+
+                       switch($filters['has_contract'])
+                       {
+                               case "has_contract":
+                                       $filter_clauses[]        = "NOT 
rental_contract_composite.contract_id IS NULL"; // Composite must have a 
contract
+                                       $filter_clauses[]        = "NOT 
rental_contract.date_start IS NULL"; // The contract must have start date
+
+                                       /* The contract's start date not after 
the end of the period if there is no end date */
+                                       $filter_clauses[]        = "
                                        ((NOT rental_contract.date_start > 
$availability_date_to AND rental_contract.date_end IS NULL)
                                         OR
                                        (NOT rental_contract.date_start > 
$availability_date_to AND NOT rental_contract.date_end IS NULL AND NOT 
rental_contract.date_end < $availability_date_from))";
-                               $special_query=true;
-                               break;
-                       case "has_no_contract":
-                               $filter_clauses[] = "
+                                       $special_query           = true;
+                                       break;
+                               case "has_no_contract":
+                                       $filter_clauses[]        = "
                                (
                                        rental_contract_composite.contract_id 
IS NULL OR 
                                        NOT rental_composite.id IN 
@@ -114,79 +121,82 @@
                                        )
                                )
                                ";
-                               $special_query=true;
-                               break;
-                       case "both":
-                               break;
-               }
-               
-               // Furnished, partly furnished, not furnished, not specified
-               if(isset($filters['furnished_status']) & 
$filters['furnished_status'] < 4){
-                       // Not specified
-                       if($filters['furnished_status'] == 0)
-                               $filter_clauses[] = 
"rental_composite.furnish_type_id IS NULL";
-                       else 
-                               $filter_clauses[] = 
"rental_composite.furnish_type_id=".$filters['furnished_status'];
-               }
+                                       $special_query           = true;
+                                       break;
+                               case "both":
+                                       break;
+                       }
 
-               if(isset($filters['not_in_contract'])){
-                       $filter_clauses[] = 
"(rental_contract_composite.contract_id != ".$filters['not_in_contract']." OR 
rental_contract_composite.contract_id IS NULL)";
-               }
-               
-               if(isset($filters['location_code'])){
-                       $filter_clauses[] = "rental_unit.location_code = '". 
$filters['location_code'] . "'";
-               }
-               
-               if(isset($filters['contract_id']))
-               {
-                       $filter_clauses[] = "contract_id = 
{$this->marshal($filters['contract_id'],'int')}";
-               }
-               
-               if(isset($filters[$this->get_id_field_name()]))
-               {
-                       $filter_clauses[] = "rental_composite.id = 
{$this->marshal($filters[$this->get_id_field_name()],'int')}";
-               }
+                       // Furnished, partly furnished, not furnished, not 
specified
+                       if(isset($filters['furnished_status']) & 
$filters['furnished_status'] < 4)
+                       {
+                               // Not specified
+                               if($filters['furnished_status'] == 0)
+                                       $filter_clauses[]        = 
"rental_composite.furnish_type_id IS NULL";
+                               else
+                                       $filter_clauses[]        = 
"rental_composite.furnish_type_id=" . $filters['furnished_status'];
+                       }
 
+                       if(isset($filters['not_in_contract']))
+                       {
+                               $filter_clauses[] = 
"(rental_contract_composite.contract_id != " . $filters['not_in_contract'] . " 
OR rental_contract_composite.contract_id IS NULL)";
+                       }
 
-               $tables = "rental_composite";
-               $joins = "      {$this->left_join} rental_unit ON 
(rental_composite.id = rental_unit.composite_id)";
-               $joins .= "     {$this->left_join} rental_contract_composite ON 
(rental_contract_composite.composite_id = rental_composite.id)";
-               $joins .= "     {$this->left_join} rental_contract ON 
(rental_contract.id = rental_contract_composite.contract_id)";
+                       if(isset($filters['location_code']))
+                       {
+                               $filter_clauses[] = "rental_unit.location_code 
= '" . $filters['location_code'] . "'";
+                       }
 
-               if(isset($filters['district_id']) && $filters['district_id'])
-               {
-                       $joins .= "     {$this->join} fm_locations ON 
(rental_unit.location_code = fm_locations.location_code)";
-                       $joins .= "     {$this->join} fm_location1 ON 
(fm_location1.loc1 = fm_locations.loc1)";
-                       $joins .= "     {$this->join} fm_part_of_town ON 
(fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id)";
+                       if(isset($filters['contract_id']))
+                       {
+                               $filter_clauses[] = "contract_id = 
{$this->marshal($filters['contract_id'], 'int')}";
+                       }
 
-                       $filter_clauses[] = "fm_part_of_town.district_id ="  . 
(int) $filters['district_id'];
-               }
-               if(count($filter_clauses))
-               {
-                       $clauses[] = join(' AND ', $filter_clauses);
-               }
+                       if(isset($filters[$this->get_id_field_name()]))
+                       {
+                               $filter_clauses[] = "rental_composite.id = 
{$this->marshal($filters[$this->get_id_field_name()], 'int')}";
+                       }
 
-               $condition =  join(' AND ', $clauses);
 
-               if($return_count) // We should only return a count
-               {
-                       $cols = 'COUNT(DISTINCT(rental_composite.id)) AS count';
-               }
-               else
-               {
-                       if($special_query)
+                       $tables  = "rental_composite";
+                       $joins   = "    {$this->left_join} rental_unit ON 
(rental_composite.id = rental_unit.composite_id)";
+                       $joins .= "     {$this->left_join} 
rental_contract_composite ON (rental_contract_composite.composite_id = 
rental_composite.id)";
+                       $joins .= "     {$this->left_join} rental_contract ON 
(rental_contract.id = rental_contract_composite.contract_id)";
+
+                       if(isset($filters['district_id']) && 
$filters['district_id'])
                        {
-                               $cols = "DISTINCT(rental_composite.id) AS 
composite_id,";
+                               $joins .= "     {$this->join} fm_locations ON 
(rental_unit.location_code = fm_locations.location_code)";
+                               $joins .= "     {$this->join} fm_location1 ON 
(fm_location1.loc1 = fm_locations.loc1)";
+                               $joins .= "     {$this->join} fm_part_of_town 
ON (fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id)";
+
+                               $filter_clauses[] = 
"fm_part_of_town.district_id =" . (int)$filters['district_id'];
                        }
-                       else
+                       if(count($filter_clauses))
                        {
-                               $cols = "rental_composite.id AS composite_id,";
+                               $clauses[] = join(' AND ', $filter_clauses);
                        }
 
-                       $cols .= "rental_unit.id AS unit_id, 
rental_unit.location_code, rental_composite.name, 
rental_composite.has_custom_address, rental_composite.address_1, 
rental_composite.house_number,
+                       $condition = join(' AND ', $clauses);
+
+                       if($return_count) // We should only return a count
+                       {
+                               $cols = 'COUNT(DISTINCT(rental_composite.id)) 
AS count';
+                       }
+                       else
+                       {
+                               if($special_query)
+                               {
+                                       $cols = "DISTINCT(rental_composite.id) 
AS composite_id,";
+                               }
+                               else
+                               {
+                                       $cols = "rental_composite.id AS 
composite_id,";
+                               }
+
+                               $cols .= "rental_unit.id AS unit_id, 
rental_unit.location_code, rental_composite.name, 
rental_composite.has_custom_address, rental_composite.address_1, 
rental_composite.house_number,
                                          rental_composite.address_2, 
rental_composite.postcode, rental_composite.place, rental_composite.is_active, 
rental_composite.area, rental_composite.description, 
rental_composite.furnish_type_id, rental_composite.standard_id, ";
-                       $cols .= "rental_contract.id AS contract_id, 
rental_contract.date_start, rental_contract.date_end, 
rental_contract.old_contract_id, ";
-                       $cols .= "
+                               $cols .= "rental_contract.id AS contract_id, 
rental_contract.date_start, rental_contract.date_end, 
rental_contract.old_contract_id, ";
+                               $cols .= "
                        CASE WHEN 
                        (
                                NOT rental_contract_composite.contract_id IS 
NULL AND
@@ -197,299 +207,305 @@
                                (NOT rental_contract.date_start > 
$availability_date_to AND NOT rental_contract.date_end IS NULL AND NOT 
rental_contract.date_end < $availability_date_from))
                        )
                        THEN 'Ikke ledig' ELSE 'Ledig' END as status";
-               }
-               $dir = $ascending ? 'ASC' : 'DESC';
-               $order = $sort_field ? "ORDER BY {$this->marshal($sort_field, 
'field')} $dir ": '';
-               $this->sort_field = $sort_field;
+                       }
+                       $dir                             = $ascending ? 'ASC' : 
'DESC';
+                       $order                           = $sort_field ? "ORDER 
BY {$this->marshal($sort_field, 'field')} $dir " : '';
+                       $this->sort_field        = $sort_field;
 
-               switch($sort_field)
-               {
-                       case 'status':
-                               $this->skip_limit_query = true;
-                               break;
+                       switch($sort_field)
+                       {
+                               case 'status':
+                                       $this->skip_limit_query = true;
+                                       break;
 
-                       default:
-                               break;
+                               default:
+                                       break;
+                       }
+
+//             _debug_array("SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}");
+
+                       return "SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}";
                }
 
-//             _debug_array("SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}");
-           
-               return "SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}";
-       }
-       
-       function populate(int $composite_id, &$composite)
-       { 
-               if($composite == null ) // new object
+               function populate(int $composite_id, &$composite)
                {
-                       $composite = new rental_composite($composite_id);
-                       
$composite->set_description($this->unmarshal($this->db->f('description', true), 
'string'));
-                       $composite->set_is_active($this->db->f('is_active'));
-                       $composite_name = $this->unmarshal($this->db->f('name', 
true), 'string');
-                       if($composite_name == null || $composite_name == '')
+                       if($composite == null) // new object
                        {
-                               $composite_name = lang('no_name_composite', 
$composite_id);
+                               $composite               = new 
rental_composite($composite_id);
+                               
$composite->set_description($this->unmarshal($this->db->f('description', true), 
'string'));
+                               
$composite->set_is_active($this->db->f('is_active'));
+                               $composite_name  = 
$this->unmarshal($this->db->f('name', true), 'string');
+                               if($composite_name == null || $composite_name 
== '')
+                               {
+                                       $composite_name = 
lang('no_name_composite', $composite_id);
+                               }
+
+                               $composite->set_name($composite_name);
+                               
$composite->set_has_custom_address($this->unmarshal($this->db->f('has_custom_address',
 true), 'bool'));
+                               
$composite->set_custom_address_1($this->unmarshal($this->db->f('address_1', 
true), 'string'));
+                               
$composite->set_custom_address_2($this->unmarshal($this->db->f('address_2', 
true), 'string'));
+                               
$composite->set_custom_house_number($this->unmarshal($this->db->f('house_number',
 true), 'string'));
+                               
$composite->set_custom_postcode($this->unmarshal($this->db->f('postcode', 
true), 'string'));
+                               
$composite->set_custom_place($this->unmarshal($this->db->f('place', true), 
'string'));
+                               
$composite->set_area($this->unmarshal($this->db->f('area', true), 'float'));
+                               
$composite->set_furnish_type_id($this->unmarshal($this->db->f('furnish_type_id'),
 'int'));
+                               
$composite->set_standard_id($this->unmarshal($this->db->f('standard_id'), 
'int'));
                        }
-                       
-                       $composite->set_name($composite_name);
-                       
$composite->set_has_custom_address($this->unmarshal($this->db->f('has_custom_address',
 true), 'bool'));
-                       
$composite->set_custom_address_1($this->unmarshal($this->db->f('address_1', 
true), 'string'));
-                       
$composite->set_custom_address_2($this->unmarshal($this->db->f('address_2', 
true), 'string'));
-                       
$composite->set_custom_house_number($this->unmarshal($this->db->f('house_number',
 true), 'string'));
-                       
$composite->set_custom_postcode($this->unmarshal($this->db->f('postcode', 
true), 'string'));
-                       
$composite->set_custom_place($this->unmarshal($this->db->f('place', true), 
'string'));
-                       
$composite->set_area($this->unmarshal($this->db->f('area', true), 'float'));
-                       
$composite->set_furnish_type_id($this->unmarshal($this->db->f('furnish_type_id'),
 'int'));
-                       
$composite->set_standard_id($this->unmarshal($this->db->f('standard_id'), 
'int'));
-               }
-               // Location code
-               $location_code = $this->unmarshal($this->db->f('location_code', 
true), 'string');
-               
-               //Status
-               $database_status = $this->unmarshal($this->db->f('status', 
true), 'string');
-               $composite_status = $composite->get_status();
-                               
-               if($composite_status != 'Ikke ledig')
-               {
-                       $composite->set_status($database_status);
-               }
-               
-               $contract_id = $this->unmarshal($this->db->f('contract_id', 
true), 'int'); 
-               
-               // Adds contract to array in composite object if it's not 
already added 
-               if($contract_id != 0 & 
!$composite->contains_contract($contract_id))
-               {
-                       $contract = new rental_contract($contract_id);
-                       
-                       $start_date = 
$this->unmarshal($this->db->f('date_start', true), 'int');
-                       $end_date = $this->unmarshal($this->db->f('date_end', 
true), 'int');
-                       $old_contract_id = 
$this->unmarshal($this->db->f('old_contract_id', true), 'string');
-                       
-                       // Adds contract if end date is not specified or 
greater than todays date  
-                       if($end_date == 0 || $end_date > time()){
-                               $contract_date = new 
rental_contract_date($start_date, $end_date);
-                               $contract->set_contract_date($contract_date);
-                               
$contract->set_old_contract_id($old_contract_id);
-                               
-                               $composite->add_contract($contract);    
+                       // Location code
+                       $location_code = 
$this->unmarshal($this->db->f('location_code', true), 'string');
+
+                       //Status
+                       $database_status         = 
$this->unmarshal($this->db->f('status', true), 'string');
+                       $composite_status        = $composite->get_status();
+
+                       if($composite_status != 'Ikke ledig')
+                       {
+                               $composite->set_status($database_status);
                        }
-               }
-               
-               if(!$composite->contains_unit($location_code))
-               {
-                       //composite inneholder ikke unit -> legg den til
-                       $location = null;
-                       try
+
+                       $contract_id = 
$this->unmarshal($this->db->f('contract_id', true), 'int');
+
+                       // Adds contract to array in composite object if it's 
not already added
+                       if($contract_id != 0 & 
!$composite->contains_contract($contract_id))
                        {
-                               // We get the data from the property module
-                               $data = 
@execMethod('property.bolocation.read_single', array('location_code' => 
$location_code, 'extra' => array('view' => true)));
-                               if($data != null)
+                               $contract = new rental_contract($contract_id);
+
+                               $start_date              = 
$this->unmarshal($this->db->f('date_start', true), 'int');
+                               $end_date                = 
$this->unmarshal($this->db->f('date_end', true), 'int');
+                               $old_contract_id = 
$this->unmarshal($this->db->f('old_contract_id', true), 'string');
+
+                               // Adds contract if end date is not specified 
or greater than todays date
+                               if($end_date == 0 || $end_date > time())
                                {
-                                       $level = -1;
-                                       $names = array();
-                                       $levelFound = false;
-                                       for($i = 1; $i < 6; $i++)
+                                       $contract_date = new 
rental_contract_date($start_date, $end_date);
+                                       
$contract->set_contract_date($contract_date);
+                                       
$contract->set_old_contract_id($old_contract_id);
+
+                                       $composite->add_contract($contract);
+                               }
+                       }
+
+                       if(!$composite->contains_unit($location_code))
+                       {
+                               //composite inneholder ikke unit -> legg den til
+                               $location = null;
+                               try
+                               {
+                                       // We get the data from the property 
module
+                                       $data = 
@execMethod('property.bolocation.read_single', array('location_code'     => 
$location_code,
+                                               'extra'                  => 
array('view' => true)));
+                                       if($data != null)
                                        {
-                                               $loc_name = 'loc'.$i.'_name';
-                                               if(array_key_exists($loc_name, 
$data))
+                                               $level           = -1;
+                                               $names           = array();
+                                               $levelFound      = false;
+                                               for($i = 1; $i < 6; $i++)
                                                {
-                                                       $level = $i;
-                                                       $names[$level] = 
$data[$loc_name];
+                                                       $loc_name = 'loc' . $i 
. '_name';
+                                                       
if(array_key_exists($loc_name, $data))
+                                                       {
+                                                               $level          
         = $i;
+                                                               $names[$level]  
 = $data[$loc_name];
+                                                       }
                                                }
+                                               $gab_id          = '';
+                                               $gabinfos        = 
@execMethod('property.sogab.read', array('location_code'      => $location_code,
+                                                       'allrows'               
 => true));
+                                               if($gabinfos != null && 
is_array($gabinfos) && count($gabinfos) == 1)
+                                               {
+                                                       $gabinfo = 
array_shift($gabinfos);
+                                                       $gab_id  = 
$gabinfo['gab_id'];
+                                               }
+                                               $location = new 
rental_property_location($location_code, 
rental_uicommon::get_nicely_formatted_gab_id($gab_id), $level, $names);
+                                               if(isset($data['street_name']) 
&& $data['street_name'])
+                                               {
+                                                       
$location->set_address_1($data['street_name'] . ' ' . $data['street_number']);
+                                               }
+                                               
//$location->set_address_1($data['address']);
+                                               foreach($data['attributes'] as 
$attributes)
+                                               {
+                                                       
switch($attributes['column_name'])
+                                                       {
+                                                               case 
'area_gross':
+                                                                       
$location->set_area_gros($attributes['value']);
+                                                                       break;
+                                                               case 'area_net':
+                                                                       
$location->set_area_net($attributes['value']);
+                                                                       break;
+                                                       }
+                                               }
                                        }
-                                       $gab_id = '';
-                                       $gabinfos  = 
@execMethod('property.sogab.read', array('location_code' => $location_code, 
'allrows' => true));
-                                       if($gabinfos != null && 
is_array($gabinfos) && count($gabinfos) == 1)
+                                       else
                                        {
-                                               $gabinfo = 
array_shift($gabinfos);
-                                               $gab_id = $gabinfo['gab_id'];
+                                               $location = new 
rental_property_location($location_code, null, 1, array());
                                        }
-                                       $location = new 
rental_property_location($location_code, 
rental_uicommon::get_nicely_formatted_gab_id($gab_id), $level, $names);
-                                       if(isset($data['street_name']) && 
$data['street_name'])
-                                       {
-                                               
$location->set_address_1($data['street_name'].' '.$data['street_number']);
-                                       }
-                                       
//$location->set_address_1($data['address']);
-                                       foreach($data['attributes'] as 
$attributes)
-                                       {
-                                               
switch($attributes['column_name'])
-                                               {
-                                                       case 'area_gross':
-                                                               
$location->set_area_gros($attributes['value']);
-                                                               break;
-                                                       case 'area_net':
-                                                               
$location->set_area_net($attributes['value']);
-                                                               break;
-                                               }
-                                       }
                                }
-                               else
+                               catch(Exception $e)
                                {
                                        $location = new 
rental_property_location($location_code, null, 1, array());
                                }
+                               $composite->add_unit(new 
rental_unit($this->unmarshal($this->db->f('unit_id', true), 'int'), 
$composite_id, $location));
                        }
-                       catch(Exception $e)
+
+                       return $composite;
+               }
+
+               public function get_id_field_name($extended_info = false)
+               {
+                       if(!$extended_info)
                        {
-                               $location = new 
rental_property_location($location_code, null, 1, array());
+                               $ret = 'composite_id';
                        }
-                       $composite->add_unit(new 
rental_unit($this->unmarshal($this->db->f('unit_id', true), 'int'), 
$composite_id, $location));
+                       else
+                       {
+                               $ret = array
+                                       (
+                                       'table'          => 'rental_composite', 
// alias
+                                       'field'          => 'id',
+                                       'translated' => 'composite_id'
+                               );
+                       }
+                       return $ret;
                }
-               
-               return $composite;
-       }
-       
-       public function get_id_field_name($extended_info = false)
-       {
-               if(!$extended_info)
+
+               /**
+                * Update the database values for an existing composite object. 
Also updates associated rental units.
+                *
+                * @param $composite the composite to be updated
+                * @return result receipt from the db operation
+                */
+               public function update($composite)
                {
-                       $ret = 'composite_id';
-               }
-               else
-               {
-                       $ret = array
-                       (
-                               'table'                 => 'rental_composite', 
// alias
-                               'field'                 => 'id',
-                               'translated'    => 'composite_id'
+                       $id = intval($composite->get_id());
+
+                       $values = array(
+                               'name = \'' . $composite->get_name() . '\'',
+                               'description = \'' . 
$composite->get_description() . '\'',
+                               'has_custom_address = ' . 
($composite->has_custom_address() ? "true" : "false"),
+                               'address_1 = \'' . 
$composite->get_custom_address_1() . '\'',
+                               'address_2 = \'' . 
$composite->get_custom_address_2() . '\'',
+                               'house_number = \'' . 
$composite->get_custom_house_number() . '\'',
+                               'postcode = \'' . 
$composite->get_custom_postcode() . '\'',
+                               'place = \'' . $composite->get_custom_place() . 
'\'',
+                               'is_active = \'' . ($composite->is_active() ? 
'true' : 'false') . '\'',
+                               'object_type_id = ' . 
$composite->get_object_type_id(),
+                               'area = ' . 
$this->marshal($composite->get_area(), 'float'),
+                               'furnish_type_id = ' . 
$composite->get_furnish_type_id(),
+                               'standard_id = ' . 
$composite->get_standard_id(),
                        );
-               }
-               return $ret;
-       }
 
-       /**
-        * Update the database values for an existing composite object. Also 
updates associated rental units.
-        *
-        * @param $composite the composite to be updated
-        * @return result receipt from the db operation
-        */
-       public function update($composite)
-       {
-               $id = intval($composite->get_id());
+                       $result = $this->db->query('UPDATE rental_composite SET 
' . join(',', $values) . " WHERE id=$id", __LINE__, __FILE__);
 
-               $values = array(
-                       'name = \'' . $composite->get_name() . '\'',
-                       'description = \'' . $composite->get_description() . 
'\'',
-                       'has_custom_address = ' . 
($composite->has_custom_address() ? "true" : "false"),
-                       'address_1 = \'' . $composite->get_custom_address_1() . 
'\'',
-                       'address_2 = \'' . $composite->get_custom_address_2() . 
'\'',
-                       'house_number = \'' . 
$composite->get_custom_house_number() . '\'',
-                       'postcode = \'' . $composite->get_custom_postcode() . 
'\'',
-                       'place = \'' . $composite->get_custom_place() . '\'',
-                       'is_active = \'' . ($composite->is_active() ? 'true' : 
'false') . '\'',
-            'object_type_id = '.$composite->get_object_type_id(),
-            'area = ' . $this->marshal($composite->get_area(), 'float'),
-                       'furnish_type_id = '.$composite->get_furnish_type_id(),
-                       'standard_id = '.$composite->get_standard_id(),
-               );
+                       return $result != null;
+               }
 
-               $result = $this->db->query('UPDATE rental_composite SET ' . 
join(',', $values) . " WHERE id=$id", __LINE__,__FILE__);
+               /**
+                * Add a new composite to the database.  Adds the new insert id 
to the object reference.
+                * Also saves included rental_unit objects.
+                *
+                * @param $composite the composite to be added
+                * @return int with id of the composite
+                */
+               public function add(&$composite)
+               {
+                       // Build a db-friendly array of the composite object
+                       $cols    = array('name', 'description', 
'has_custom_address', 'address_1', 'address_2',
+                               'house_number', 'postcode', 'place', 
'object_type_id', 'area', 'furnish_type_id',
+                               'standard_id');
+                       $values  = array(
+                               "'" . $composite->get_name() . "'",
+                               "'" . $composite->get_description() . "'",
+                               ($composite->has_custom_address() ? "true" : 
"false"),
+                               "'" . $composite->get_custom_address_1() . "'",
+                               "'" . $composite->get_custom_address_2() . "'",
+                               "'" . $composite->get_custom_house_number() . 
"'",
+                               "'" . $composite->get_custom_postcode() . "'",
+                               "'" . $composite->get_custom_place() . "'",
+                               $composite->get_object_type_id(),
+                               $this->marshal($composite->get_area(), 'float'),
+                               $composite->get_furnish_type_id(),
+                               $composite->get_standard_id()
+                       );
 
-               return $result != null;
-       }
-       
-       /**
-        * Add a new composite to the database.  Adds the new insert id to the 
object reference.
-        * Also saves included rental_unit objects.
-        *
-        * @param $composite the composite to be added
-        * @return int with id of the composite
-        */
-       public function add(&$composite)
-       {
-               // Build a db-friendly array of the composite object
-               $cols = array('name', 'description', 'has_custom_address', 
'address_1', 'address_2', 'house_number', 'postcode', 'place', 
'object_type_id', 'area', 'furnish_type_id', 'standard_id');
-               $values = array(
-                       "'".$composite->get_name()."'",
-                       "'".$composite->get_description()."'",
-                       ($composite->has_custom_address() ? "true" : "false"),
-                       "'".$composite->get_custom_address_1()."'",
-                       "'".$composite->get_custom_address_2()."'",
-                       "'".$composite->get_custom_house_number()."'",
-                       "'".$composite->get_custom_postcode()."'",
-                       "'".$composite->get_custom_place()."'",
-            $composite->get_object_type_id(),
-            $this->marshal($composite->get_area(), 'float'),
-            $composite->get_furnish_type_id(),
-            $composite->get_standard_id()
-               );
+                       $query   = "INSERT INTO rental_composite (" . join(',', 
$cols) . ") VALUES (" . join(',', $values) . ")";
+                       $result  = $this->db->query($query);
 
-               $query ="INSERT INTO rental_composite (" . join(',', $cols) . 
") VALUES (" . join(',', $values) . ")";
-               $result = $this->db->query($query);
+                       $composite_id = 
$this->db->get_last_insert_id('rental_composite', 'id');
+                       $composite->set_id($composite_id);
+                       return $composite_id;
+               }
 
-               $composite_id = 
$this->db->get_last_insert_id('rental_composite', 'id');
-               $composite->set_id($composite_id);
-               return $composite_id;
-       }
-       
-       /**
-        * HACK to return the location code for a given contract id. The metod
-        * could've been more generalized, but the Agresso file format already
-        * breaks the model of PE..
-        * 
-        * @param $contract_id int with id of contract.
-        * @return string with location code, empty string if not found.
-        */
-       public function get_building_location_code($contract_id)
-       {
-               $query = "SELECT location_code FROM rental_unit 
{$this->left_join} rental_contract_composite ON 
(rental_contract_composite.composite_id = rental_unit.composite_id) WHERE 
rental_contract_composite.contract_id = {$contract_id}";
-               $result = $this->db->limit_query($query, 0, __LINE__, __FILE__, 
1);
-               
-               if($result && $this->db->next_record()) // Query ok
+               /**
+                * HACK to return the location code for a given contract id. 
The metod
+                * could've been more generalized, but the Agresso file format 
already
+                * breaks the model of PE..
+                *
+                * @param $contract_id int with id of contract.
+                * @return string with location code, empty string if not found.
+                */
+               public function get_building_location_code($contract_id)
                {
-                       $location_code = $this->db->f('location_code', true);
-                       if($location_code != null && $location_code != '')
+                       $query   = "SELECT location_code FROM rental_unit 
{$this->left_join} rental_contract_composite ON 
(rental_contract_composite.composite_id = rental_unit.composite_id) WHERE 
rental_contract_composite.contract_id = {$contract_id}";
+                       $result  = $this->db->limit_query($query, 0, __LINE__, 
__FILE__, 1);
+
+                       if($result && $this->db->next_record()) // Query ok
                        {
-                               return substr(str_replace('-', '', 
$location_code), 0, 6);
+                               $location_code = $this->db->f('location_code', 
true);
+                               if($location_code != null && $location_code != 
'')
+                               {
+                                       return substr(str_replace('-', '', 
$location_code), 0, 6);
+                               }
                        }
+                       return '';
                }
-               return '';
-       }
 
+               public function get_area($composite_id)
+               {
+                       $sql = "SELECT area FROM rental_composite WHERE id = " 
. $this->marshal($composite_id, 'float');
+                       $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
 
-    public function get_area($composite_id) {
-        $sql = "SELECT area FROM rental_composite WHERE id = " . 
$this->marshal($composite_id, 'float');
-               $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+                       if($this->db->next_record())
+                       {
+                               return $this->unmarshal($this->db->f('area', 
true), 'float');
+                       }
 
-               if ($this->db->next_record()) {
-                       return $this->unmarshal($this->db->f('area', true), 
'float');
+                       return null;
                }
 
-               return null;
-    }
-       
-    public function get_uicols() 
-       {
-               $uicols = array();
-               
-               $uicols['name'][]               = 'id';
-               $uicols['descr'][]              = lang('serial');
-               $uicols['sortable'][]   = false;
-               $uicols['input_type'][] = 'hidden';
+               public function get_uicols()
+               {
+                       $uicols = array();
 
-               $uicols['name'][]               = 'location_code';
-               $uicols['descr'][]              = lang('object_number');
-               $uicols['sortable'][]   = true;
-               $uicols['input_type'][] = 'text';
-               
-               $uicols['name'][]               = 'name';
-               $uicols['descr'][]              = lang('name');
-               $uicols['sortable'][]   = true;
-               $uicols['input_type'][] = 'text';
-               
-               $uicols['name'][]               = 'address';
-               $uicols['descr'][]              = lang('address');
-               $uicols['sortable'][]   = false;
-               $uicols['input_type'][] = 'text';
-               
-               $uicols['name'][]               = 'gab_id';
-               $uicols['descr'][]              = lang('propertyident');
-               $uicols['sortable'][]   = false;
-               $uicols['input_type'][] = 'text';
-               
-               $uicols['name'][]               = 'status';
-               $uicols['descr'][]              = lang('status');
-               $uicols['sortable'][]   = true;
-               $uicols['input_type'][] = 'text';
-               
-               return $uicols;
-    }
-}
+                       $uicols['name'][]                = 'id';
+                       $uicols['descr'][]               = lang('serial');
+                       $uicols['sortable'][]    = false;
+                       $uicols['input_type'][]  = 'hidden';
+
+                       $uicols['name'][]                = 'location_code';
+                       $uicols['descr'][]               = 
lang('object_number');
+                       $uicols['sortable'][]    = true;
+                       $uicols['input_type'][]  = 'text';
+
+                       $uicols['name'][]                = 'name';
+                       $uicols['descr'][]               = lang('name');
+                       $uicols['sortable'][]    = true;
+                       $uicols['input_type'][]  = 'text';
+
+                       $uicols['name'][]                = 'address';
+                       $uicols['descr'][]               = lang('address');
+                       $uicols['sortable'][]    = false;
+                       $uicols['input_type'][]  = 'text';
+
+                       $uicols['name'][]                = 'gab_id';
+                       $uicols['descr'][]               = 
lang('propertyident');
+                       $uicols['sortable'][]    = false;
+                       $uicols['input_type'][]  = 'text';
+
+                       $uicols['name'][]                = 'status';
+                       $uicols['descr'][]               = lang('status');
+                       $uicols['sortable'][]    = true;
+                       $uicols['input_type'][]  = 'text';
+
+                       return $uicols;
+               }
+       }
\ No newline at end of file

Modified: branches/dev-syncromind/rental/inc/class.socontract.inc.php
===================================================================
--- branches/dev-syncromind/rental/inc/class.socontract.inc.php 2015-12-10 
14:38:47 UTC (rev 14566)
+++ branches/dev-syncromind/rental/inc/class.socontract.inc.php 2015-12-10 
14:57:03 UTC (rev 14567)
@@ -7,1208 +7,1257 @@
         * @package Frontend
         * @version $Id$
         */
-
        /*
-          This program is free software: you can redistribute it and/or modify
-          it under the terms of the GNU General Public License as published by
-          the Free Software Foundation, either version 2 of the License, or
-          (at your option) any later version.
+         This program is free software: you can redistribute it and/or modify
+         it under the terms of the GNU General Public License as published by
+         the Free Software Foundation, either version 2 of the License, or
+         (at your option) any later version.
 
-          This program is distributed in the hope that it will be useful,
-          but WITHOUT ANY WARRANTY; without even the implied warranty of
-          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-          GNU General Public License for more details.
+         This program is distributed in the hope that it will be useful,
+         but WITHOUT ANY WARRANTY; without even the implied warranty of
+         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+         GNU General Public License for more details.
 
-          You should have received a copy of the GNU General Public License
-          along with this program.  If not, see <http://www.gnu.org/licenses/>.
-       */
+         You should have received a copy of the GNU General Public License
+         along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
 
-phpgw::import_class('rental.socommon');
+       phpgw::import_class('rental.socommon');
 
-include_class('rental', 'contract_date', 'inc/model/');
-include_class('rental', 'contract', 'inc/model/');
-include_class('rental', 'composite', 'inc/model/');
-include_class('rental', 'party', 'inc/model/');
-include_class('rental', 'price_item', 'inc/model/');
-include_class('rental', 'contract_price_item', 'inc/model/');
+       include_class('rental', 'contract_date', 'inc/model/');
+       include_class('rental', 'contract', 'inc/model/');
+       include_class('rental', 'composite', 'inc/model/');
+       include_class('rental', 'party', 'inc/model/');
+       include_class('rental', 'price_item', 'inc/model/');
+       include_class('rental', 'contract_price_item', 'inc/model/');
 
-class rental_socontract extends rental_socommon
-{
-       protected static $so;
-       protected $fields_of_responsibility; // Used for caching the values
-
-       /**
-        * Get a static reference to the storage object associated with this 
model object
-        *
-        * @return rental_socontract the storage object
-        */
-       public static function get_instance()
+       class rental_socontract extends rental_socommon
        {
-               if (self::$so == null) {
-                       self::$so = CreateObject('rental.socontract');
-               }
-               return self::$so;
-       }
 
-       /**
-        * Filters:
-        * Contracts with party as contract party
-        * Contracts for executive officer
-        * Contracts last edited by user
-        * Contracts of type
-        * Contracts with this id (get single)
-        * Contracts with composite as contract composite
-        * Contracts with contract status
-        * Contracts for billing
-        *
-        * @see rental/inc/rental_socommon#get_query($sort_field, $ascending, 
$search_for, $search_type, $filters, $return_count)
-        */
-       protected function get_query(string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean $return_count)
-       {
-               $clauses = array('1=1');
+               protected static $so;
+               protected $fields_of_responsibility; // Used for caching the 
values
 
-               //Add columns to this array to include them in the query
-               $columns = array();
+               /**
+                * Get a static reference to the storage object associated with 
this model object
+                *
+                * @return rental_socontract the storage object
+                */
 
-               $dir = $ascending ? 'ASC' : 'DESC';
-               if($sort_field == null || $sort_field == '')
+               public static function get_instance()
                {
-                       $sort_field = 'contract.id';
+                       if(self::$so == null)
+                       {
+                               self::$so = CreateObject('rental.socontract');
+                       }
+                       return self::$so;
                }
-               else if ($sort_field == 'party'){
-                       $sort_field = "party.company_name {$dir}, 
party.last_name {$dir}, party.first_name";
-               }
-               else if ($sort_field == 'composite'){
-                       $sort_field = "composite.name";
-               }
-               else if ($sort_field == 'type'){
-                       $sort_field = 'contract.location_id';
-               }
-               else if($sort_field == 'term_label'){
-                       $sort_field = 'contract.term_id';
-               }
-               $this->sort_field = str_ireplace(" {$dir}", '', $sort_field);
 
-               //Contracts for billing should always be sorted on biling start
-               if(isset($filters['contracts_for_billing']))
+               /**
+                * Filters:
+                * Contracts with party as contract party
+                * Contracts for executive officer
+                * Contracts last edited by user
+                * Contracts of type
+                * Contracts with this id (get single)
+                * Contracts with composite as contract composite
+                * Contracts with contract status
+                * Contracts for billing
+                *
+                * @see rental/inc/rental_socommon#get_query($sort_field, 
$ascending, $search_for, $search_type, $filters, $return_count)
+                */
+               protected function get_query(string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count)
                {
-                       $order = "ORDER BY contract.billing_start ASC";
-               }
-               else
-               {
-                       $order = "ORDER BY {$sort_field} {$dir}";
-               }
+                       $clauses = array('1=1');
 
-               // Search for based on search type
-               if($search_for)
-               {
-                       $search_for = $this->marshal($search_for,'field');
-                       $like_pattern = "'%".$search_for."%'";
-                       $int_value_of_search = (int) $search_for;
-                       $like_clauses = array();
-                       switch($search_type){
-                               case "id":
-                                       $like_clauses[] = 
"contract.old_contract_id $this->like $like_pattern";
-                                       break;
-                               case "party_name":
-                                       $like_clauses[] = "party.first_name 
$this->like $like_pattern";
-                                       $like_clauses[] = "party.last_name 
$this->like $like_pattern";
-                                       $like_clauses[] = "party.company_name 
$this->like $like_pattern";
-                                       break;
-                               case "composite":
-                                       $like_clauses[] = "composite.name 
$this->like $like_pattern";
-                                       break;
-                               case "composite_address":
-                                       $composite_address = true;
-                                       break;
-                               case "location_id":
-                                       $like_clauses[] = "r_u.location_code 
like '{$search_for}%'";
-                                       break;
-                               case "all":
+                       //Add columns to this array to include them in the query
+                       $columns = array();
 
-                                       $like_clauses[] = 
"contract.old_contract_id $this->like $like_pattern";
-                                       $like_clauses[] = "contract.comment 
$this->like $like_pattern";
-                                       $like_clauses[] = "party.first_name 
$this->like $like_pattern";
-                                       $like_clauses[] = "party.last_name 
$this->like $like_pattern";
-                                       $like_clauses[] = "party.company_name 
$this->like $like_pattern";
-                                       $like_clauses[] = "composite.name 
$this->like $like_pattern";
-                                       $like_clauses[] = "r_u.location_code 
$this->like $like_pattern";
-                                       break;
+                       $dir = $ascending ? 'ASC' : 'DESC';
+                       if($sort_field == null || $sort_field == '')
+                       {
+                               $sort_field = 'contract.id';
                        }
+                       else if($sort_field == 'party')
+                       {
+                               $sort_field = "party.company_name {$dir}, 
party.last_name {$dir}, party.first_name";
+                       }
+                       else if($sort_field == 'composite')
+                       {
+                               $sort_field = "composite.name";
+                       }
+                       else if($sort_field == 'type')
+                       {
+                               $sort_field = 'contract.location_id';
+                       }
+                       else if($sort_field == 'term_label')
+                       {
+                               $sort_field = 'contract.term_id';
+                       }
+                       $this->sort_field = str_ireplace(" {$dir}", '', 
$sort_field);
 
-                       if($composite_address)
+                       //Contracts for billing should always be sorted on 
biling start
+                       if(isset($filters['contracts_for_billing']))
                        {
-                               $sql_composite_address = "select 
rental_composite.id as rc_id from rental_composite,rental_unit,fm_gab_location 
where rental_unit.composite_id=rental_composite.id and 
fm_gab_location.location_code=rental_unit.location_code and 
fm_gab_location.address like upper({$like_pattern})";
-                               $this->db->query($sql_composite_address, 
__LINE__, __FILE__,false,true);
-                               $array_composites = array();
-                               while($this->db->next_record())
+                               $order = "ORDER BY contract.billing_start ASC";
+                       }
+                       else
+                       {
+                               $order = "ORDER BY {$sort_field} {$dir}";
+                       }
+
+                       // Search for based on search type
+                       if($search_for)
+                       {
+                               $search_for                      = 
$this->marshal($search_for, 'field');
+                               $like_pattern            = "'%" . $search_for . 
"%'";
+                               $int_value_of_search = (int)$search_for;
+                               $like_clauses            = array();
+                               switch($search_type)
                                {
-                                       $array_composites[] = 
$this->db->f('rc_id');
+                                       case "id":
+                                               $like_clauses[]          = 
"contract.old_contract_id $this->like $like_pattern";
+                                               break;
+                                       case "party_name":
+                                               $like_clauses[]          = 
"party.first_name $this->like $like_pattern";
+                                               $like_clauses[]          = 
"party.last_name $this->like $like_pattern";
+                                               $like_clauses[]          = 
"party.company_name $this->like $like_pattern";
+                                               break;
+                                       case "composite":
+                                               $like_clauses[]          = 
"composite.name $this->like $like_pattern";
+                                               break;
+                                       case "composite_address":
+                                               $composite_address       = true;
+                                               break;
+                                       case "location_id":
+                                               $like_clauses[]          = 
"r_u.location_code like '{$search_for}%'";
+                                               break;
+                                       case "all":
+
+                                               $like_clauses[]  = 
"contract.old_contract_id $this->like $like_pattern";
+                                               $like_clauses[]  = 
"contract.comment $this->like $like_pattern";
+                                               $like_clauses[]  = 
"party.first_name $this->like $like_pattern";
+                                               $like_clauses[]  = 
"party.last_name $this->like $like_pattern";
+                                               $like_clauses[]  = 
"party.company_name $this->like $like_pattern";
+                                               $like_clauses[]  = 
"composite.name $this->like $like_pattern";
+                                               $like_clauses[]  = 
"r_u.location_code $this->like $like_pattern";
+                                               break;
                                }
-                               if($array_composites)
+
+                               if($composite_address)
                                {
-                                       $composites = 
implode(',',$array_composites);
-                                       $like_clauses[] = "composite.id in 
($composites)";
+                                       $sql_composite_address   = "select 
rental_composite.id as rc_id from rental_composite,rental_unit,fm_gab_location 
where rental_unit.composite_id=rental_composite.id and 
fm_gab_location.location_code=rental_unit.location_code and 
fm_gab_location.address like upper({$like_pattern})";
+                                       
$this->db->query($sql_composite_address, __LINE__, __FILE__, false, true);
+                                       $array_composites                = 
array();
+                                       while($this->db->next_record())
+                                       {
+                                               $array_composites[] = 
$this->db->f('rc_id');
+                                       }
+                                       if($array_composites)
+                                       {
+                                               $composites              = 
implode(',', $array_composites);
+                                               $like_clauses[]  = 
"composite.id in ($composites)";
+                                       }
+                                       else
+                                       {
+                                               $like_clauses[] = "composite.id 
in (-1)";
+                                       }
                                }
-                               else
+
+
+                               if(count($like_clauses))
                                {
-                                       $like_clauses[] = "composite.id in 
(-1)";
+                                       $clauses[] = '(' . join(' OR ', 
$like_clauses) . ')';
                                }
                        }
 
+                       $filter_clauses = array();
 
-                       if(count($like_clauses))
+                       // Contracts with party as contract party
+                       if(isset($filters['party_id']))
                        {
-                               $clauses[] = '(' . join(' OR ', $like_clauses) 
. ')';
+                               $party_id                        = 
$this->marshal($filters['party_id'], 'int');
+                               $filter_clauses[]        = "party.id = 
$party_id";
                        }
 
+                       // Contracts for this executive officer
+                       if(isset($filters['executive_officer']))
+                       {
+                               $account_id                      = 
$this->marshal($filters['executive_officer'], 'int');
+                               $filter_clauses[]        = 
"contract.executive_officer = $account_id";
+                       }
 
-               }
+                       // Contracts of type
+                       if(isset($filters['contract_type']) && 
$filters['contract_type'] != 'all')
+                       {
+                               $type                            = 
$this->marshal($filters['contract_type'], 'field');
+                               $filter_clauses[]        = 
"contract.location_id IN ($type)";
+                       }
 
-               $filter_clauses = array();
+                       // Contracts with this id (filter for retrieveing a 
single contract)
+                       if(isset($filters[$this->get_id_field_name()]))
+                       {
+                               $id                                      = 
$this->marshal($filters[$this->get_id_field_name()], 'int');
+                               $filter_clauses[]        = "contract.id = 
{$id}";
+                       }
 
-               // Contracts with party as contract party
-               if(isset($filters['party_id'])){
-                       $party_id  =   
$this->marshal($filters['party_id'],'int');
-                       $filter_clauses[] = "party.id = $party_id";
-               }
+                       // All contracts with composite as contract composite
+                       if(isset($filters['composite_id']))
+                       {
+                               $composite_id            = 
$this->marshal($filters['composite_id'], 'int');
+                               $filter_clauses[]        = "composite.id = 
{$composite_id}";
+                       }
 
-               // Contracts for this executive officer
-               if(isset($filters['executive_officer'])){
-                       $account_id  =   
$this->marshal($filters['executive_officer'],'int');
-                       $filter_clauses[] = "contract.executive_officer = 
$account_id";
-               }
+                       // Affected contracts by regulation
+                       if(isset($filters['adjustment_interval']) && 
isset($filters['adjustment_year']))
+                       {
+                               $adjustment_interval = 
$this->marshal($filters['adjustment_interval'], 'int');
+                               $adjustment_year         = 
$this->marshal($filters['adjustment_year'], 'int');
 
-               // Contracts of type
-               if(isset($filters['contract_type']) && 
$filters['contract_type'] != 'all'){
-                       $type = 
$this->marshal($filters['contract_type'],'field');
-                       $filter_clauses[] = "contract.location_id IN ($type)";
-               }
+                               if($filters['adjustment_is_executed'])
+                               {
+                                       $filter_clauses[] = 
"contract.adjustment_year = {$adjustment_year}";
+                               }
+                               else if($filters['extra_adjustment'])
+                               {
+                                       $filter_clauses[] = 
"(contract.adjustment_year + {$adjustment_interval} <= {$adjustment_year} OR 
contract.adjustment_year = {$adjustment_year} )";
+                               }
+                               else
+                               {
+                                       $filter_clauses[] = 
"contract.adjustment_year + {$adjustment_interval} <= {$adjustment_year}";
+                               }
 
-               // Contracts with this id (filter for retrieveing a single 
contract)
-               if(isset($filters[$this->get_id_field_name()])){
-                       $id = 
$this->marshal($filters[$this->get_id_field_name()],'int');
-                       $filter_clauses[] = "contract.id = {$id}";
-               }
+                               $firstJanAdjYear = mktime(0, 0, 0, 1, 1, 
$adjustment_year);
 
-               // All contracts with composite as contract composite
-               if(isset($filters['composite_id']))
-               {
-                       $composite_id = 
$this->marshal($filters['composite_id'],'int');
-                       $filter_clauses[] = "composite.id = {$composite_id}";
-               }
+                               //make sure the contracts are active
+                               $filter_clauses[]        = "(contract.date_end 
is null OR contract.date_end >= {$firstJanAdjYear})";
+                               $filter_clauses[]        = "contract.date_start 
is not null AND contract.date_start <= {$firstJanAdjYear}";
 
-               // Affected contracts by regulation
-               if(isset($filters['adjustment_interval']) && 
isset($filters['adjustment_year']))
-               {
-                       $adjustment_interval = 
$this->marshal($filters['adjustment_interval'],'int');
-                       $adjustment_year = 
$this->marshal($filters['adjustment_year'],'int');
+                               $filter_clauses[]        = "contract.adjustable 
IS true";
+                               $filter_clauses[]        = 
"contract.adjustment_interval = {$adjustment_interval}";
+                       }
 
-                       if($filters['adjustment_is_executed']){
-                               $filter_clauses[] = "contract.adjustment_year = 
{$adjustment_year}";
+                       /*
+                        * Contract status is defined by the dates in each 
contract compared to the target date (default today):
+                        * - contracts under planning:
+                        * the start date is larger (in the future) than the 
target date, or start date is undefined
+                        * - active contracts:
+                        * the start date is smaller (in the past) than the 
target date, and the end date is undefined (running) or
+                        * larger (fixed) than the target date
+                        * - under dismissal:
+                        * the start date is smaller than the target date,
+                        * the end date is larger than the target date, and
+                        * the end date substracted the contract type 
notification period is smaller than the target date
+                        * - ended:
+                        * the end date is smaller than the target date
+                        */
+                       if($filters['start_date_report'])
+                       {
+                               $filters['contract_status']      = 'all';
+                               $filter_clauses[]                        = 
"contract.date_end > {$filters['start_date_report']}";
+                               $filter_clauses[]                        = 
"contract.date_start < {$filters['start_date_report']}";
                        }
-                        else if($filters['extra_adjustment']){
-                            $filter_clauses[] = "(contract.adjustment_year + 
{$adjustment_interval} <= {$adjustment_year} OR contract.adjustment_year = 
{$adjustment_year} )";
-                        }
-                       else{
-                               $filter_clauses[] = "contract.adjustment_year + 
{$adjustment_interval} <= {$adjustment_year}";
+                       if($filters['end_date_report'])
+                       {
+                               $filters['contract_status']      = 'all';
+                               $filter_clauses[]                        = 
"contract.date_end < {$filters['end_date_report']}";
                        }
+//_debug_array($filtes);die();
+                       if(isset($filters['contract_status']) && 
$filters['contract_status'] != 'all')
+                       {
+                               if(isset($filters['status_date']) && 
$filters['status_date'])
+                               {
+                                       $ts_query = $filters['status_date']; // 
target timestamp specified by user
+                               }
+                               else
+                               {
+                                       $ts_query = strtotime(date('Y-m-d')); 
// timestamp for query (today)
+                               }
+                               switch($filters['contract_status'])
+                               {
+                                       case 'under_planning':
+                                               $filter_clauses[]        = 
"contract.date_start > {$ts_query} OR contract.date_start IS NULL";
+                                               break;
+                                       case 'active':
+                                               $filter_clauses[]        = 
"contract.date_start <= {$ts_query} AND ( contract.date_end >= {$ts_query} OR 
contract.date_end IS NULL)";
+                                               break;
+                                       case 'under_dismissal':
+                                               $filter_clauses[]        = 
"contract.date_start <= {$ts_query} AND contract.date_end >= {$ts_query} AND 
(contract.date_end - (type.notify_before * (24 * 60 * 60)))  <= {$ts_query}";
+                                               break;
+                                       case 'closing_due_date':
+                                               $filter_clauses[]        = 
"contract.due_date >= {$ts_query} AND (contract.due_date - 
(type.notify_before_due_date * (24 * 60 * 60)))  <= {$ts_query}";
+                                               $order                          
 = "ORDER BY contract.due_date ASC";
+                                               $this->sort_field        = 
'contract.due_date';
+                                               break;
+                                       case 'terminated_contracts':
+                                               $filter_clauses[]        = 
"contract.date_end >= ({$ts_query} - (type.notify_after_termination_date * (24 
* 60 * 60))) AND contract.date_end < {$ts_query}";
+                                               $order                          
 = "ORDER BY contract.date_end DESC";
+                                               $this->sort_field        = 
'contract.date_end';
+                                               break;
+                                       case 'ended':
+                                               $filter_clauses[]        = 
"contract.date_end < {$ts_query}";
+                                               break;
+                               }
+                       }
 
-                       $firstJanAdjYear = mktime(0,0,0,1,1,$adjustment_year);
+                       /*
+                        * Contracts for billing
+                        */
+                       if(isset($filters['contracts_for_billing']))
+                       {
+                               $billing_term_id = 
(int)$filters['billing_term_id'];
+                               $sql                     = "SELECT months FROM 
rental_billing_term WHERE id = {$billing_term_id}";
+                               $result                  = 
$this->db->query($sql);
+                               if(!$result)
+                               {
+                                       return;
+                               }
+                               if(!$this->db->next_record())
+                               {
+                                       return;
+                               }
+                               $month                   = 
(int)$filters['month'];
+                               $year                    = 
(int)$filters['year'];
+                               $months                  = 
$this->unmarshal($this->db->f('months', true), 'int');
+                               $timestamp_end   = 
strtotime("{$year}-{$month}-01"); // The first day in the month to bill for
+                               if($months == 1)
+                               {
+                                       $timestamp_start = $timestamp_end; // 
The first day of the period to bill for
+                               }
+                               else
+                               {
+                                       $months                  = $months - 1;
+                                       $timestamp_start = 
strtotime("-{$months} months", $timestamp_end); // The first day of the period 
to bill for
+                               }
+                               $timestamp_end = strtotime('+1 month', 
$timestamp_end); // The first day in the month after the one to bill for
+                               //$timestamp_start = 
strtotime("{$year}-{$month}-01");
 
-                       //make sure the contracts are active
-                       $filter_clauses[] = "(contract.date_end is null OR 
contract.date_end >= {$firstJanAdjYear})";
-                       $filter_clauses[] = "contract.date_start is not null 
AND contract.date_start <= {$firstJanAdjYear}";
+                               $filter_clauses[]        = "contract.term_id = 
{$billing_term_id}";
+                               $filter_clauses[]        = "contract.date_start 
< $timestamp_end";
+                               $filter_clauses[]        = "(contract.date_end 
IS NULL OR contract.date_end >= {$timestamp_start})";
+                               $filter_clauses[]        = 
"(contract.billing_start IS NULL OR contract.billing_start < {$timestamp_end})";
 
-                       $filter_clauses[] = "contract.adjustable IS true";
-                       $filter_clauses[] = "contract.adjustment_interval = 
{$adjustment_interval}";
+                               $specific_ordering       = 
'invoice.timestamp_end DESC, contract.billing_start DESC, contract.date_start 
DESC, contract.date_end DESC';
+                               $order                           = $order ? 
$order . ', ' . $specific_ordering : "ORDER BY {$specific_ordering}";
+                       }
 
-               }
+                       if(count($filter_clauses))
+                       {
+                               $clauses[] = join(' AND ', $filter_clauses);
+                       }
 
-               /*
-                * Contract status is defined by the dates in each contract 
compared to the target date (default today):
-                * - contracts under planning:
-                * the start date is larger (in the future) than the target 
date, or start date is undefined
-                * - active contracts:
-                * the start date is smaller (in the past) than the target 
date, and the end date is undefined (running) or
-                * larger (fixed) than the target date
-                * - under dismissal:
-                * the start date is smaller than the target date,
-                * the end date is larger than the target date, and
-                * the end date substracted the contract type notification 
period is smaller than the target date
-                * - ended:
-                * the end date is smaller than the target date
-                */
-               if($filters['start_date_report'])
-               {
-                       $filters['contract_status'] = 'all';
-                       $filter_clauses[] = "contract.date_end > 
{$filters['start_date_report']}";
-                       $filter_clauses[] = "contract.date_start < 
{$filters['start_date_report']}";
+                       $condition = join(' AND ', $clauses);
 
-               }
-               if($filters['end_date_report'])
-               {
-                       $filters['contract_status'] = 'all';
-                       $filter_clauses[] = "contract.date_end < 
{$filters['end_date_report']}";
-
-               }
-//_debug_array($filtes);die();
-               if(isset($filters['contract_status']) && 
$filters['contract_status'] != 'all')
-               {
-                       if(isset($filters['status_date']) && 
$filters['status_date'])
+                       if($return_count) // We should only return a count
                        {
-                               $ts_query = $filters['status_date']; // target 
timestamp specified by user
+                               $cols    = 'COUNT(DISTINCT(contract.id)) AS 
count';
+                               $order   = ''; // No ordering
                        }
                        else
                        {
-                               $ts_query = strtotime(date('Y-m-d')); // 
timestamp for query (today)
+                               // columns to retrieve
+                               $columns[]       = 'contract.id AS contract_id';
+                               $columns[]       = 'contract.date_start, 
contract.date_end, contract.old_contract_id, contract.executive_officer, 
contract.last_updated, contract.location_id, contract.billing_start, 
contract.billing_end, contract.service_id, contract.responsibility_id, 
contract.reference, contract.invoice_header, contract.project_id, 
billing.deleted, contract.account_in, contract.account_out, contract.term_id, 
contract.security_type, contract.security_amount, contract.comment, 
contract.due_date, 
contract.contract_type_id,contract.rented_area,contract.adjustable,contract.adjustment_interval,contract.adjustment_share,contract.adjustment_year,contract.publish_comment';
+                               $columns[]       = 'party.id AS party_id';
+                               $columns[]       = 'party.first_name, 
party.last_name, party.company_name, party.department, party.org_enhet_id';
+                               $columns[]       = 'c_t.is_payer';
+                               $columns[]       = 'composite.id AS 
composite_id';
+                               $columns[]       = 'composite.name AS 
composite_name';
+                               $columns[]       = 'type.title, 
type.notify_before, type.notify_before_due_date, 
type.notify_after_termination_date';
+                               $columns[]       = 'last_edited.edited_on';
+                               $columns[]       = 'invoice.timestamp_end';
+                               $columns[]       = 'r_b_t.title AS term_title';
+                               $cols            = implode(',', $columns);
                        }
-                       switch($filters['contract_status'])
-                       {
-                               case 'under_planning':
-                                       $filter_clauses[] = 
"contract.date_start > {$ts_query} OR contract.date_start IS NULL";
-                                       break;
-                               case 'active':
-                                       $filter_clauses[] = 
"contract.date_start <= {$ts_query} AND ( contract.date_end >= {$ts_query} OR 
contract.date_end IS NULL)";
-                                       break;
-                               case 'under_dismissal':
-                                       $filter_clauses[] = 
"contract.date_start <= {$ts_query} AND contract.date_end >= {$ts_query} AND 
(contract.date_end - (type.notify_before * (24 * 60 * 60)))  <= {$ts_query}";
-                                       break;
-                               case 'closing_due_date':
-                                       $filter_clauses[] = "contract.due_date 
>= {$ts_query} AND (contract.due_date - (type.notify_before_due_date * (24 * 60 
* 60)))  <= {$ts_query}";
-                                       $order = "ORDER BY contract.due_date 
ASC";
-                                       $this->sort_field = 'contract.due_date';
-                                       break;
-                               case 'terminated_contracts':
-                                       $filter_clauses[] = "contract.date_end 
>= ({$ts_query} - (type.notify_after_termination_date * (24 * 60 * 60))) AND 
contract.date_end < {$ts_query}";
-                                       $order = "ORDER BY contract.date_end 
DESC";
-                                       $this->sort_field = 'contract.date_end';
-                                       break;
-                               case 'ended':
-                                       $filter_clauses[] = "contract.date_end 
< {$ts_query}" ;
-                                       break;
-                       }
+
+                       $tables                          = "rental_contract 
contract";
+                       $join_contract_type      = $this->left_join . ' 
rental_contract_responsibility type ON (type.location_id = 
contract.location_id)';
+                       $join_parties            = $this->left_join . ' 
rental_contract_party c_t ON (contract.id = c_t.contract_id) LEFT JOIN 
rental_party party ON (c_t.party_id = party.id)';
+                       $join_composites         = $this->left_join . " 
rental_contract_composite c_c ON (contract.id = c_c.contract_id) 
{$this->left_join} rental_composite composite ON c_c.composite_id = 
composite.id";
+                       $join_units                      = $this->left_join . " 
rental_unit r_u ON (r_u.composite_id=composite.id)";
+                       $join_last_edited        = $this->left_join . ' 
rental_contract_last_edited last_edited ON (contract.id = 
last_edited.contract_id)';
+                       $join_last_billed        = "{$this->left_join} 
rental_invoice invoice ON (contract.id = invoice.contract_id) 
{$this->left_join} rental_billing billing ON (invoice.billing_id = billing.id)";
+                       $join_term_title         = "{$this->left_join} 
rental_billing_term r_b_t ON (contract.term_id = r_b_t.id)";
+                       $joins                           = $join_contract_type 
. ' ' . $join_parties . ' ' . $join_composites . ' ' . $join_units . ' ' . 
$join_last_edited . ' ' . $join_last_billed . ' ' . $join_term_title;
+
+                       //var_dump("SELECT {$cols} FROM {$tables} {$joins} 
WHERE {$condition} {$order}");
+
+                       return "SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}";
                }
 
-               /*
-                * Contracts for billing
-                */
-               if(isset($filters['contracts_for_billing']))
+               public function get_id_field_name($extended_info = false)
                {
-                       $billing_term_id = (int)$filters['billing_term_id'];
-                       $sql = "SELECT months FROM rental_billing_term WHERE id 
= {$billing_term_id}";
-                       $result = $this->db->query($sql);
-                       if(!$result)
+                       if(!$extended_info)
                        {
-                               return;
+                               $ret = 'contract_id';
                        }
-                       if(!$this->db->next_record())
+                       else
                        {
-                               return;
+                               $ret = array
+                                       (
+                                       'table'          => 'contract', // alias
+                                       'field'          => 'id',
+                                       'translated' => 'contract_id'
+                               );
                        }
-                       $month = (int)$filters['month'];
-                       $year = (int)$filters['year'];
-                       $months = $this->unmarshal($this->db->f('months', 
true), 'int');
-                       $timestamp_end = strtotime("{$year}-{$month}-01"); // 
The first day in the month to bill for
-                       if($months == 1){
-                               $timestamp_start = $timestamp_end; // The first 
day of the period to bill for
-                       }else{
-                               $months = $months-1;
-                               $timestamp_start = strtotime("-{$months} 
months", $timestamp_end); // The first day of the period to bill for
-                       }
-                       $timestamp_end = strtotime('+1 month', $timestamp_end); 
// The first day in the month after the one to bill for
-                       //$timestamp_start = strtotime("{$year}-{$month}-01");
-
-                       $filter_clauses[] = "contract.term_id = 
{$billing_term_id}";
-                       $filter_clauses[] = "contract.date_start < 
$timestamp_end";
-                       $filter_clauses[] = "(contract.date_end IS NULL OR 
contract.date_end >= {$timestamp_start})";
-                       $filter_clauses[] = "(contract.billing_start IS NULL OR 
contract.billing_start < {$timestamp_end})";
-
-                       $specific_ordering = 'invoice.timestamp_end DESC, 
contract.billing_start DESC, contract.date_start DESC, contract.date_end DESC';
-                       $order = $order ? $order.', '.$specific_ordering : 
"ORDER BY {$specific_ordering}";
+                       return $ret;
                }
 
-               if(count($filter_clauses))
+               function populate(int $contract_id, &$contract)
                {
-                       $clauses[] = join(' AND ', $filter_clauses);
-               }
 
-               $condition =  join(' AND ', $clauses);
+                       if($contract == null) // new contract
+                       {
+                               $contract_id = (int)$contract_id;
+                               $contract        = new 
rental_contract($contract_id);
+                               $contract->set_contract_date(new 
rental_contract_date
+                               (
+                               $this->unmarshal($this->db->f('date_start'), 
'int'), $this->unmarshal($this->db->f('date_end'), 'int')
+                               )
+                               );
+                               
$contract->set_billing_start_date($this->unmarshal($this->db->f('billing_start'),
 'int'));
+                               
$contract->set_billing_end_date($this->unmarshal($this->db->f('billing_end'), 
'int'));
+                               
$contract->set_old_contract_id($this->unmarshal($this->db->f('old_contract_id'),
 'string'));
+                               
$contract->set_contract_type_title($this->unmarshal($this->db->f('title'), 
'string'));
+                               
$contract->set_comment($this->unmarshal($this->db->f('comment'), 'string'));
+                               
$contract->set_last_edited_by_current_user($this->unmarshal($this->db->f('edited_on'),
 'int'));
+                               
$contract->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
+                               
$contract->set_last_updated($this->unmarshal($this->db->f('last_updated'), 
'int'));
+                               
$contract->set_service_id($this->unmarshal($this->db->f('service_id'), 
'string'));
+                               
$contract->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id'),
 'string'));
+                               
$contract->set_reference($this->unmarshal($this->db->f('reference'), 'string'));
+                               
$contract->set_invoice_header($this->unmarshal($this->db->f('invoice_header'), 
'string'));
+                               
$contract->set_account_in($this->unmarshal($this->db->f('account_in'), 
'string'));
+                               
$contract->set_account_out($this->unmarshal($this->db->f('account_out'), 
'string'));
+                               
$contract->set_project_id($this->unmarshal($this->db->f('project_id'), 
'string'));
+                               
$contract->set_executive_officer_id($this->unmarshal($this->db->f('executive_officer'),
 'int'));
+                               
$contract->set_term_id($this->unmarshal($this->db->f('term_id'), 'int'));
+                               
$contract->set_term_id_title($this->unmarshal($this->db->f('term_title'), 
'string'));
+                               
$contract->set_security_type($this->unmarshal($this->db->f('security_type'), 
'int'));
+                               
$contract->set_security_amount($this->unmarshal($this->db->f('security_amount'),
 'string'));
+                               
$contract->set_due_date($this->unmarshal($this->db->f('due_date'), 'int'));
+                               
$contract->set_contract_type_id($this->unmarshal($this->db->f('contract_type_id'),
 int));
+                               
$contract->set_rented_area($this->unmarshal($this->db->f('rented_area'), 
'float'));
+                               
$contract->set_adjustable($this->unmarshal($this->db->f('adjustable'), 'bool'));
+                               
$contract->set_adjustment_interval($this->unmarshal($this->db->f('adjustment_interval'),
 'int'));
+                               
$contract->set_adjustment_share($this->unmarshal($this->db->f('adjustment_share'),
 'int'));
+                               
$contract->set_adjustment_year($this->unmarshal($this->db->f('adjustment_year'),
 'int'));
+                               
$contract->set_publish_comment($this->unmarshal($this->db->f('publish_comment'),
 'bool'));
+                               
$contract->set_notify_before($this->unmarshal($this->db->f('notify_before'), 
'int'));
+                               
$contract->set_notify_before_due_date($this->unmarshal($this->db->f('notify_before_due_date'),
 'int'));
+                               
$contract->set_notify_after_termination_date($this->unmarshal($this->db->f('notify_after_termination_date'),
 'int'));
+                       }
 
-               if($return_count) // We should only return a count
-               {
-                       $cols = 'COUNT(DISTINCT(contract.id)) AS count';
-                       $order = ''; // No ordering
-               }
-               else
-               {
-                       // columns to retrieve
-                       $columns[] = 'contract.id AS contract_id';
-                       $columns[] = 'contract.date_start, contract.date_end, 
contract.old_contract_id, contract.executive_officer, contract.last_updated, 
contract.location_id, contract.billing_start, contract.billing_end, 
contract.service_id, contract.responsibility_id, contract.reference, 
contract.invoice_header, contract.project_id, billing.deleted, 
contract.account_in, contract.account_out, contract.term_id, 
contract.security_type, contract.security_amount, contract.comment, 
contract.due_date, 
contract.contract_type_id,contract.rented_area,contract.adjustable,contract.adjustment_interval,contract.adjustment_share,contract.adjustment_year,contract.publish_comment';
-                       $columns[] = 'party.id AS party_id';
-                       $columns[] = 'party.first_name, party.last_name, 
party.company_name, party.department, party.org_enhet_id';
-                       $columns[] = 'c_t.is_payer';
-                       $columns[] = 'composite.id AS composite_id';
-                       $columns[] = 'composite.name AS composite_name';
-                       $columns[] = 'type.title, type.notify_before, 
type.notify_before_due_date, type.notify_after_termination_date';
-                       $columns[] = 'last_edited.edited_on';
-                       $columns[] = 'invoice.timestamp_end';
-                       $columns[] = 'r_b_t.title AS term_title';
-                       $cols = implode(',',$columns);
-               }
+                       $timestamp_end   = 
$this->unmarshal($this->db->f('timestamp_end'), 'int');
+                       $billing_deleted = 
$this->unmarshal($this->db->f('deleted'), 'bool');
+                       if($timestamp_end && !$billing_deleted)
+                       {
+                               $contract->add_bill_timestamp($timestamp_end);
+                       }
 
-               $tables = "rental_contract contract";
-               $join_contract_type =   $this->left_join.' 
rental_contract_responsibility type ON (type.location_id = 
contract.location_id)';
-               $join_parties = $this->left_join.' rental_contract_party c_t ON 
(contract.id = c_t.contract_id) LEFT JOIN rental_party party ON (c_t.party_id = 
party.id)';
-               $join_composites =              $this->left_join." 
rental_contract_composite c_c ON (contract.id = c_c.contract_id) 
{$this->left_join} rental_composite composite ON c_c.composite_id = 
composite.id";
-               $join_units = $this->left_join." rental_unit r_u ON 
(r_u.composite_id=composite.id)";
-               $join_last_edited = $this->left_join.' 
rental_contract_last_edited last_edited ON (contract.id = 
last_edited.contract_id)';
-               $join_last_billed = "{$this->left_join} rental_invoice invoice 
ON (contract.id = invoice.contract_id) {$this->left_join} rental_billing 
billing ON (invoice.billing_id = billing.id)";
-               $join_term_title = "{$this->left_join} rental_billing_term 
r_b_t ON (contract.term_id = r_b_t.id)";
-               $joins = $join_contract_type.' '.$join_parties.' 
'.$join_composites.' '.$join_units.' '.$join_last_edited.' 
'.$join_last_billed.' '.$join_term_title;
+                       $total_price = 
$this->unmarshal($this->db->f('total_price'), 'int');
+                       if($total_price)
+                       {
+                               $contract->set_total_price($total_price);
+                       }
 
-               //var_dump("SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}");
+                       $party_id = $this->unmarshal($this->db->f('party_id', 
true), 'int');
+                       if($party_id)
+                       {
+                               $party           = new rental_party($party_id);
+                               
$party->set_first_name($this->unmarshal($this->db->f('first_name', true), 
'string'));
+                               
$party->set_last_name($this->unmarshal($this->db->f('last_name', true), 
'string'));
+                               
$party->set_company_name($this->unmarshal($this->db->f('company_name', true), 
'string'));
+                               
$party->set_department($this->unmarshal($this->db->f('department', true), 
'string'));
+                               
$party->set_org_enhet_id($this->unmarshal($this->db->f('org_enhet_id'), 'int'));
+                               $is_payer        = 
$this->unmarshal($this->db->f('is_payer', true), 'bool');
+                               if($is_payer)
+                               {
+                                       $contract->set_payer_id($party_id);
+                               }
+                               $contract->add_party($party);
+                       }
 
-               return "SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}";
-       }
-
-       public function get_id_field_name($extended_info = false)
-       {
-               if(!$extended_info)
-               {
-                       $ret = 'contract_id';
+                       $composite_id = 
$this->unmarshal($this->db->f('composite_id', true), 'int');
+                       if($composite_id)
+                       {
+                               $composite = new 
rental_composite($composite_id);
+                               
$composite->set_name($this->unmarshal($this->db->f('composite_name', true), 
'string'));
+                               $contract->add_composite($composite);
+                       }
+                       return $contract;
                }
-               else
-               {
-                       $ret = array
-                       (
-                               'table'                 => 'contract', // alias
-                               'field'                 => 'id',
-                               'translated'    => 'contract_id'
-                       );
-               }
-               return $ret;
-       }
 
-
-       function populate(int $contract_id, &$contract)
-       {
-
-               if($contract == null ) // new contract
+               /**
+                * Get a key/value array of contract type titles keyed by their 
id
+                *
+                * @return array
+                */
+               function get_fields_of_responsibility()
                {
-                       $contract_id = (int) $contract_id;
-                       $contract = new rental_contract($contract_id);
-                       $contract->set_contract_date(new rental_contract_date
-                               (
-                                       
$this->unmarshal($this->db->f('date_start'),'int'),
-                                       
$this->unmarshal($this->db->f('date_end'),'int')
-                               )
-                       );
-                       
$contract->set_billing_start_date($this->unmarshal($this->db->f('billing_start'),'int'));
-                       
$contract->set_billing_end_date($this->unmarshal($this->db->f('billing_end'),'int'));
-                       
$contract->set_old_contract_id($this->unmarshal($this->db->f('old_contract_id'),'string'));
-                       
$contract->set_contract_type_title($this->unmarshal($this->db->f('title'),'string'));
-                       
$contract->set_comment($this->unmarshal($this->db->f('comment'),'string'));
-                       
$contract->set_last_edited_by_current_user($this->unmarshal($this->db->f('edited_on'),'int'));
-                       
$contract->set_location_id($this->unmarshal($this->db->f('location_id'),'int'));
-                       
$contract->set_last_updated($this->unmarshal($this->db->f('last_updated'),'int'));
-                       
$contract->set_service_id($this->unmarshal($this->db->f('service_id'),'string'));
-                       
$contract->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id'),'string'));
-                       
$contract->set_reference($this->unmarshal($this->db->f('reference'),'string'));
-                       
$contract->set_invoice_header($this->unmarshal($this->db->f('invoice_header'),'string'));
-                       
$contract->set_account_in($this->unmarshal($this->db->f('account_in'),'string'));
-                       
$contract->set_account_out($this->unmarshal($this->db->f('account_out'),'string'));
-                       
$contract->set_project_id($this->unmarshal($this->db->f('project_id'),'string'));
-                       
$contract->set_executive_officer_id($this->unmarshal($this->db->f('executive_officer'),'int'));
-                       
$contract->set_term_id($this->unmarshal($this->db->f('term_id'),'int'));
-                       
$contract->set_term_id_title($this->unmarshal($this->db->f('term_title'),'string'));
-                       
$contract->set_security_type($this->unmarshal($this->db->f('security_type'),'int'));
-                       
$contract->set_security_amount($this->unmarshal($this->db->f('security_amount'),'string'));
-                       
$contract->set_due_date($this->unmarshal($this->db->f('due_date'),'int'));
-                       
$contract->set_contract_type_id($this->unmarshal($this->db->f('contract_type_id'),int));
-                       
$contract->set_rented_area($this->unmarshal($this->db->f('rented_area'),'float'));
-                       
$contract->set_adjustable($this->unmarshal($this->db->f('adjustable'),'bool'));
-                       
$contract->set_adjustment_interval($this->unmarshal($this->db->f('adjustment_interval'),'int'));
-                       
$contract->set_adjustment_share($this->unmarshal($this->db->f('adjustment_share'),'int'));
-                       
$contract->set_adjustment_year($this->unmarshal($this->db->f('adjustment_year'),'int'));
-                       
$contract->set_publish_comment($this->unmarshal($this->db->f('publish_comment'),'bool'));
-                       
$contract->set_notify_before($this->unmarshal($this->db->f('notify_before'),'int'));
-                       
$contract->set_notify_before_due_date($this->unmarshal($this->db->f('notify_before_due_date'),'int'));
-                       
$contract->set_notify_after_termination_date($this->unmarshal($this->db->f('notify_after_termination_date'),'int'));
-
-
+                       if($this->fields_of_responsibility == null)
+                       {
+                               $sql     = "SELECT location_id,title FROM 
rental_contract_responsibility";
+                               $this->db->query($sql, __LINE__, __FILE__);
+                               $results = array();
+                               while($this->db->next_record())
+                               {
+                                       $location_id                     = 
$this->db->f('location_id', true);
+                                       $results[$location_id]   = 
$this->db->f('title', true);
+                               }
+                               $this->fields_of_responsibility = $results;
+                       }
+                       return $this->fields_of_responsibility;
                }
 
-               $timestamp_end = 
$this->unmarshal($this->db->f('timestamp_end'),'int');
-               $billing_deleted = 
$this->unmarshal($this->db->f('deleted'),'bool');
-               if($timestamp_end && !$billing_deleted)
+               function get_default_account(int $location_id, bool $in)
                {
-                       $contract->add_bill_timestamp($timestamp_end);
-               }
+                       if(isset($location_id) && $location_id > 0)
+                       {
+                               if($in)
+                               {
+                                       $col = 'account_in';
+                               }
+                               else
+                               {
+                                       $col = 'account_out';
+                               }
 
-               $total_price = 
$this->unmarshal($this->db->f('total_price'),'int');
-               if($total_price)
-               {
-                       $contract->set_total_price($total_price);
+                               $sql = "SELECT {$col} FROM 
rental_contract_responsibility WHERE location_id = {$location_id}";
+                               $this->db->query($sql, __LINE__, __FILE__);
+                               $this->db->next_record();
+                               return $this->db->f($col, true);
+                       }
+                       return '';
                }
 
-               $party_id = $this->unmarshal($this->db->f('party_id', true), 
'int');
-               if($party_id)
+               function get_default_project_number(int $location_id)
                {
-                       $party = new rental_party($party_id);
-                       
$party->set_first_name($this->unmarshal($this->db->f('first_name', true), 
'string'));
-                       
$party->set_last_name($this->unmarshal($this->db->f('last_name', true), 
'string'));
-                       
$party->set_company_name($this->unmarshal($this->db->f('company_name', true), 
'string'));
-                       
$party->set_department($this->unmarshal($this->db->f('department', true), 
'string'));
-                       
$party->set_org_enhet_id($this->unmarshal($this->db->f('org_enhet_id'), 'int'));
-                       $is_payer = $this->unmarshal($this->db->f('is_payer', 
true), 'bool');
-                       if($is_payer)
+                       if(isset($location_id) && $location_id > 0)
                        {
-                               $contract->set_payer_id($party_id);
+                               $sql = "SELECT project_number FROM 
rental_contract_responsibility WHERE location_id = {$location_id}";
+                               $this->db->query($sql, __LINE__, __FILE__);
+                               $this->db->next_record();
+                               return $this->db->f('project_number', true);
                        }
-                       $contract->add_party($party);
                }
 
-               $composite_id = $this->unmarshal($this->db->f('composite_id', 
true), 'int');
-               if($composite_id)
+               function get_responsibility_title(int $location_id)
                {
-                       $composite = new rental_composite($composite_id);
-                       
$composite->set_name($this->unmarshal($this->db->f('composite_name', true), 
'string'));
-                       $contract->add_composite($composite);
-               }
-               return $contract;
-       }
-
-       /**
-        * Get a key/value array of contract type titles keyed by their id
-        *
-        * @return array
-        */
-       function get_fields_of_responsibility(){
-               if($this->fields_of_responsibility == null)
-               {
-                       $sql = "SELECT location_id,title FROM 
rental_contract_responsibility";
-                       $this->db->query($sql, __LINE__, __FILE__);
-                       $results = array();
-                       while($this->db->next_record()){
-                               $location_id = $this->db->f('location_id', 
true);
-                               $results[$location_id] = $this->db->f('title', 
true);
+                       if(isset($location_id) && $location_id > 0)
+                       {
+                               $sql = "SELECT title FROM 
rental_contract_responsibility WHERE location_id = {$location_id}";
+                               $this->db->query($sql, __LINE__, __FILE__);
+                               $this->db->next_record();
+                               return $this->db->f('title', true);
                        }
-                       $this->fields_of_responsibility = $results;
                }
-               return $this->fields_of_responsibility;
-       }
 
-       function get_default_account(int $location_id, bool $in){
-               if(isset($location_id) && $location_id > 0)
+               /**
+                * Returns the range of year there are contracts. That is, the 
array
+                * returned contains reversed chronologically all the years 
from the earliest start
+                * year of the contracts to next year.
+                *
+                * @return array of string values, never null.
+                */
+               public function get_year_range()
                {
-                       if($in)
+                       $year_range      = array();
+                       $sql             = "SELECT date_start FROM 
rental_contract ORDER BY date_start ASC";
+                       $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+                       $first_year      = (int)date('Y'); // First year in the 
array returned - we first set it to default this year
+                       if($this->db->next_record())
                        {
-                               $col = 'account_in';
+                               $date = 
$this->unmarshal($this->db->f('date_start', true), 'int');
+                               if($date != null && $date != '')
+                               {
+                                       $first_contract_year = (int)date('Y', 
$date);
+                                       if($first_contract_year < $first_year) 
// First contract year is before this year
+                                       {
+                                               $first_year = 
$first_contract_year;
+                                       }
+                               }
                        }
-                       else
+                       $next_year = (int)date('Y', strtotime('+1 year'));
+                       for($year = $next_year; $year >= $first_year; $year--) 
// Runs through all years from next year to the first year we want
                        {
-                               $col = 'account_out';
+                               $year_range[] = $year;
                        }
 
-                       $sql = "SELECT {$col} FROM 
rental_contract_responsibility WHERE location_id = {$location_id}";
-                       $this->db->query($sql, __LINE__, __FILE__);
-                       $this->db->next_record();
-                       return $this->db->f($col,true);
+                       return $year_range;
                }
-               return '';
-       }
 
-       function get_default_project_number(int $location_id)
-       {
-               if(isset($location_id) && $location_id > 0)
+               /**
+                * Update the database values for an existing contract object.
+                *
+                * @param $contract the contract to be updated
+                * @return result receipt from the db operation
+                */
+               function update($contract)
                {
-                       $sql = "SELECT project_number FROM 
rental_contract_responsibility WHERE location_id = {$location_id}";
-                       $this->db->query($sql, __LINE__, __FILE__);
-                       $this->db->next_record();
-                       return $this->db->f('project_number',true);
-               }
-       }
+                       $id = intval($contract->get_id());
 
-       function get_responsibility_title(int $location_id)
-       {
-               if(isset($location_id) && $location_id > 0)
-               {
-                       $sql = "SELECT title FROM 
rental_contract_responsibility WHERE location_id = {$location_id}";
-                       $this->db->query($sql, __LINE__, __FILE__);
-                       $this->db->next_record();
-                       return $this->db->f('title',true);
-               }
-       }
+                       $values = array();
 
-       /**
-        * Returns the range of year there are contracts. That is, the array
-        * returned contains reversed chronologically all the years from the 
earliest start
-        * year of the contracts to next year.
-        *
-        * @return array of string values, never null.
-        */
-       public function get_year_range()
-       {
-               $year_range = array();
-               $sql = "SELECT date_start FROM rental_contract ORDER BY 
date_start ASC";
-               $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
-               $first_year = (int)date('Y'); // First year in the array 
returned - we first set it to default this year
-               if($this->db->next_record()){
-                       $date = $this->unmarshal($this->db->f('date_start', 
true), 'int');
-                       if($date != null && $date != '')
+                       // Set all fields in form
+                       // FORM COLUMN 1
+                       $values[]        = "contract_type_id = " . 
$this->marshal($contract->get_contract_type_id(), 'int');
+                       $values[]        = "executive_officer = " . 
$this->marshal($contract->get_executive_officer_id(), 'int');
+
+                       if($contract->get_contract_date())
                        {
-                               $first_contract_year = (int)date('Y', $date);
-                               if($first_contract_year < $first_year) // First 
contract year is before this year
-                               {
-                                       $first_year = $first_contract_year;
-                               }
+                               $values[]        = "date_start = " . 
$this->marshal($contract->get_contract_date()->get_start_date(), 'int');
+                               $values[]        = "date_end = " . 
$this->marshal($contract->get_contract_date()->get_end_date(), 'int');
                        }
-               }
-               $next_year = (int)date('Y', strtotime('+1 year'));
-               for($year = $next_year; $year >= $first_year; $year--) // Runs 
through all years from next year to the first year we want
-               {
-                       $year_range[] = $year;
-               }
 
-               return $year_range;
-       }
+                       $values[]        = "due_date = " . 
$this->marshal($contract->get_due_date(), 'int');
+                       $values[]        = "invoice_header = " . 
$this->marshal($contract->get_invoice_header(), 'string');
+                       $values[]        = "term_id = " . 
$this->marshal($contract->get_term_id(), 'int');
+                       $values[]        = "billing_start = " . 
$this->marshal($contract->get_billing_start_date(), 'int');
+                       $values[]        = "billing_end = " . 
$this->marshal($contract->get_billing_end_date(), 'int');
+                       $values[]        = "reference = " . 
$this->marshal($contract->get_reference(), 'string');
 
-       /**
-        * Update the database values for an existing contract object.
-        *
-        * @param $contract the contract to be updated
-        * @return result receipt from the db operation
-        */
-       function update($contract)
-       {
-               $id = intval($contract->get_id());
+                       // FORM COLUMN 2
+                       $values[]        = "service_id = " . 
$this->marshal($contract->get_service_id(), 'string');
+                       $values[]        = "responsibility_id = " . 
$this->marshal($contract->get_responsibility_id(), 'string');
+                       $values[]        = "account_in = " . 
$this->marshal($contract->get_account_in(), 'string');
+                       $values[]        = "account_out = " . 
$this->marshal($contract->get_account_out(), 'string');
+                       $values[]        = "project_id = " . 
$this->marshal($contract->get_project_id(), 'string');
+                       $values[]        = "security_type = " . 
$this->marshal($contract->get_security_type(), 'int');
+                       $values[]        = "security_amount = " . 
$this->marshal($contract->get_security_amount(), 'string');
+                       $values[]        = "rented_area = " . 
$this->marshal($contract->get_rented_area(), 'float');
+                       $values[]        = "adjustable = " . 
($contract->is_adjustable() ? "true" : "false");
+                       $values[]        = "adjustment_interval = " . 
$this->marshal($contract->get_adjustment_interval(), 'int');
+                       $values[]        = "adjustment_share = " . 
$this->marshal($contract->get_adjustment_share(), 'int');
+                       $values[]        = "publish_comment = " . 
($contract->get_publish_comment() ? "true" : "false");
 
-               $values = array();
+                       // FORM COLUMN 3
+                       $values[] = "comment = " . 
$this->marshal($contract->get_comment(), 'string');
 
-               // Set all fields in form
 
-               // FORM COLUMN 1
-               $values[] = "contract_type_id = ".      
$this->marshal($contract->get_contract_type_id(), 'int');
-               $values[] = "executive_officer = ". 
$this->marshal($contract->get_executive_officer_id(), 'int');
+                       // Set date last updated
+                       $values[] = "last_updated = " . strtotime('now');
 
-               if ($contract->get_contract_date()) {
-                       $values[] = "date_start = " .   
$this->marshal($contract->get_contract_date()->get_start_date(), 'int');
-                       $values[] = "date_end = " .             
$this->marshal($contract->get_contract_date()->get_end_date(), 'int');
-               }
+                       $result = $this->db->query('UPDATE rental_contract SET 
' . join(',', $values) . " WHERE id=$id", __LINE__, __FILE__);
 
-               $values[] = "due_date = " .             
$this->marshal($contract->get_due_date(), 'int');
-               $values[] = "invoice_header = ".        
$this->marshal($contract->get_invoice_header(),'string');
-               $values[] = "term_id = " .                      
$this->marshal($contract->get_term_id(), 'int');
-               $values[] = "billing_start = " .        
$this->marshal($contract->get_billing_start_date(), 'int');
-               $values[] = "billing_end = " .          
$this->marshal($contract->get_billing_end_date(), 'int');
-               $values[] = "reference = ".             
$this->marshal($contract->get_reference(),'string');
+                       if(isset($result))
+                       {
+                               $this->last_edited_by($id);
+                               return true;
+                       }
 
-               // FORM COLUMN 2

@@ Diff output truncated at 153600 characters. @@



reply via email to

[Prev in Thread] Current Thread [Next in Thread]