fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11166] Added column for party unit


From: Erik Holm-Larsen
Subject: [Fmsystem-commits] [11166] Added column for party unit
Date: Wed, 12 Jun 2013 05:03:43 +0000

Revision: 11166
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11166
Author:   erikhl
Date:     2013-06-12 05:03:43 +0000 (Wed, 12 Jun 2013)
Log Message:
-----------
Added column for party unit

Modified Paths:
--------------
    trunk/rental/inc/class.socontract.inc.php
    trunk/rental/inc/model/class.contract.inc.php

Modified: trunk/rental/inc/class.socontract.inc.php
===================================================================
--- trunk/rental/inc/class.socontract.inc.php   2013-06-11 13:07:32 UTC (rev 
11165)
+++ trunk/rental/inc/class.socontract.inc.php   2013-06-12 05:03:43 UTC (rev 
11166)
@@ -12,10 +12,10 @@
 {
        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()
@@ -25,7 +25,7 @@
                }
                return self::$so;
        }
-       
+
        /**
         * Filters:
         * Contracts with party as contract party
@@ -36,16 +36,16 @@
         * 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');
-               
+
                //Add columns to this array to include them in the query
                $columns = array();
-               
+
                $dir = $ascending ? 'ASC' : 'DESC';
                if($sort_field == null || $sort_field == '')
                {
@@ -63,18 +63,18 @@
                else if($sort_field == 'term_label'){
                        $sort_field = 'contract.term_id';
                }
-               
-               
+
+
                //Contracts for billing should always be sorted on biling start
                if(isset($filters['contracts_for_billing']))
                {
-                       $order = "ORDER BY contract.billing_start ASC"; 
+                       $order = "ORDER BY contract.billing_start ASC";
                }
                else
                {
                        $order = "ORDER BY {$sort_field} {$dir}";
                }
-               
+
                // Search for based on search type
                if($search_for)
                {
@@ -101,7 +101,7 @@
                                        $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";
@@ -111,7 +111,7 @@
                                        $like_clauses[] = "r_u.location_code 
$this->like $like_pattern";
                                        break;
                        }
-                       
+
                        if($composite_address)
                        {
                                $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})";
@@ -131,24 +131,24 @@
                                        $like_clauses[] = "composite.id in 
(-1)";
                                }
                        }
-                       
-                       
+
+
                        if(count($like_clauses))
                        {
                                $clauses[] = '(' . join(' OR ', $like_clauses) 
. ')';
                        }
-                       
-                       
+
+
                }
-               
+
                $filter_clauses = array();
-               
+
                // 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";
                }
-               
+
                // Contracts for this executive officer
                if(isset($filters['executive_officer'])){
                        $account_id  =   
$this->marshal($filters['executive_officer'],'int');
@@ -160,60 +160,60 @@
                        $type = 
$this->marshal($filters['contract_type'],'field');
                        $filter_clauses[] = "contract.location_id IN ($type)";
                }
-               
+
                // 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}";
                }
-               
+
                // 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}";
                }
-               
+
                // 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');
-                       
+
                        if($filters['adjustment_is_executed']){
                                $filter_clauses[] = "contract.adjustment_year = 
{$adjustment_year}";
                        }
                        else{
                                $filter_clauses[] = "contract.adjustment_year + 
{$adjustment_interval} <= {$adjustment_year}";
                        }
-                       
+
                        $firstJanAdjYear = mktime(0,0,0,1,1,$adjustment_year);
-                       
+
                        //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.adjustable IS true";
                        $filter_clauses[] = "contract.adjustment_interval = 
{$adjustment_interval}";
-                       
+
                }
-               
-               /* 
+
+               /*
                 * Contract status is defined by the dates in each contract 
compared to the target date (default today):
-                * - contracts under planning: 
+                * - 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 
+                * - 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 
+                * - 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(isset($filters['contract_status']) && 
$filters['contract_status'] != 'all'){ 
-                       
+               if(isset($filters['contract_status']) && 
$filters['contract_status'] != 'all'){
+
                        if(isset($filters['status_date_hidden']) && 
$filters['status_date_hidden'] != "")
                        {
                                $ts_query = 
strtotime($filters['status_date_hidden']); // target timestamp specified by user
@@ -245,7 +245,7 @@
                                        break;
                        }
                }
-               
+
                /*
                 * Contracts for billing
                 */
@@ -274,23 +274,23 @@
                        }
                        $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}";
                }
-               
+
                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(contract.id)) AS count';
@@ -302,17 +302,17 @@
                        $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.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';
-                       $columns[] = 'c_t.is_payer';            
+                       $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[] = 'invoice.timestamp_end';
                        $columns[] = 'r_b_t.title AS term_title';
                        $cols = implode(',',$columns);
                }
-               
+
                $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)';
@@ -324,10 +324,10 @@
                $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}";
        }
-       
+
        public function get_id_field_name($extended_info = false)
        {
                if(!$extended_info)
@@ -346,13 +346,13 @@
                return $ret;
        }
 
-       
+
        function populate(int $contract_id, &$contract)
        {
-               
+
                if($contract == null ) // new contract
                {
-                       $contract_id = (int) $contract_id; 
+                       $contract_id = (int) $contract_id;
                        $contract = new rental_contract($contract_id);
                        $contract->set_contract_date(new rental_contract_date
                                (
@@ -390,23 +390,23 @@
                        
$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'));
-                       
-                       
+
+
                }
-               
+
                $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);
                }
-               
+
                $total_price = 
$this->unmarshal($this->db->f('total_price'),'int');
                if($total_price)
                {
                        $contract->set_total_price($total_price);
                }
-               
+
                $party_id = $this->unmarshal($this->db->f('party_id', true), 
'int');
                if($party_id)
                {
@@ -414,6 +414,8 @@
                        
$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)
                        {
@@ -421,7 +423,7 @@
                        }
                        $contract->add_party($party);
                }
-               
+
                $composite_id = $this->unmarshal($this->db->f('composite_id', 
true), 'int');
                if($composite_id)
                {
@@ -431,10 +433,10 @@
                }
                return $contract;
        }
-       
+
        /**
         * Get a key/value array of contract type titles keyed by their id
-        * 
+        *
         * @return array
         */
        function get_fields_of_responsibility(){
@@ -451,7 +453,7 @@
                }
                return $this->fields_of_responsibility;
        }
-       
+
        function get_default_account(int $location_id, bool $in){
                if(isset($location_id) && $location_id > 0)
                {
@@ -463,7 +465,7 @@
                        {
                                $col = 'account_out';
                        }
-                       
+
                        $sql = "SELECT {$col} FROM 
rental_contract_responsibility WHERE location_id = {$location_id}";
                        $this->db->query($sql, __LINE__, __FILE__);
                        $this->db->next_record();
@@ -471,7 +473,7 @@
                }
                return '';
        }
-       
+
        function get_default_project_number(int $location_id)
        {
                if(isset($location_id) && $location_id > 0)
@@ -480,9 +482,9 @@
                        $this->db->query($sql, __LINE__, __FILE__);
                        $this->db->next_record();
                        return $this->db->f('project_number',true);
-               }       
+               }
        }
-       
+
        function get_responsibility_title(int $location_id)
        {
                if(isset($location_id) && $location_id > 0)
@@ -491,14 +493,14 @@
                        $this->db->query($sql, __LINE__, __FILE__);
                        $this->db->next_record();
                        return $this->db->f('title',true);
-               }       
+               }
        }
-       
+
        /**
         * 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. 
-        * 
+        * year of the contracts to next year.
+        *
         * @return array of string values, never null.
         */
        public function get_year_range()
@@ -523,20 +525,20 @@
                {
                        $year_range[] = $year;
                }
-               
+
                return $year_range;
        }
-       
+
        /**
         * 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());
-               
+
                $values = array();
 
                // Set all fields in form
@@ -544,18 +546,18 @@
                // 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()) {
                        $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');
                }
-               
+
                $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[] = "reference = ".             
$this->marshal($contract->get_reference(),'string');
-               
+
                // FORM COLUMN 2
                $values[] = "service_id = ".            
$this->marshal($contract->get_service_id(),'string');
                $values[] = "responsibility_id = ". 
$this->marshal($contract->get_responsibility_id(),'string');
@@ -569,45 +571,45 @@
                $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");
-               
+
                // FORM COLUMN 3
                $values[] = "comment = ".                       
$this->marshal($contract->get_comment(), 'string');
-               
-               
+
+
                // Set date last updated
                $values[] = "last_updated = ".          strtotime('now');
-               
+
                $result = $this->db->query('UPDATE rental_contract SET ' . 
join(',', $values) . " WHERE id=$id", __LINE__,__FILE__);
-               
+
                if(isset($result))
                {
                        $this->last_edited_by($id);
                        return true;
                }
-                       
+
                return false;
        }
-       
+
        /**
         * This method marks the combination contract/user account with the 
current timestamp. It updates the record if the user has updated
-        * this contract before; inserts a new record if the user has never 
updated this contract. 
-        * 
+        * this contract before; inserts a new record if the user has never 
updated this contract.
+        *
         * @param $contract_id
         * @return true if the contract was marker, false otherwise
         */
        public function last_edited_by($contract_id){
                $account_id = $GLOBALS['phpgw_info']['user']['account_id']; // 
current user
                $ts_now = strtotime('now');
-               
+
                $sql_has_edited_before = "SELECT account_id FROM 
rental_contract_last_edited WHERE contract_id = $contract_id AND account_id = 
$account_id";
                $result = $this->db->query($sql_has_edited_before);
-               
+
                if(isset($result))
                {
                        if($this->db->next_record())
                        {
                                $sql = "UPDATE rental_contract_last_edited SET 
edited_on=$ts_now WHERE contract_id = $contract_id AND account_id = 
$account_id";
-                       } 
+                       }
                        else
                        {
                                $sql = "INSERT INTO rental_contract_last_edited 
VALUES ($contract_id,$account_id,$ts_now)";
@@ -620,13 +622,13 @@
                }
                return false;
        }
-       
+
        public function remove_Last_edited_by_information()
        {
                $sql = "DELETE * FROM rental_contract_last_edited";
                $this->db->query($sql);
        }
-       
+
        public function get_last_edited_by($contract_id)
        {
                $sql = "SELECT account_id FROM rental_contract_last_edited 
where contract_id={$contract_id} ORDER by edited_on DESC";
@@ -641,10 +643,10 @@
                }
                return "";
        }
-       
+
        /**
         * This method markw the given contract with the current timestamp
-        * 
+        *
         * @param $contract_id
         * @return true if the contract was marked, false otherwise
         */
@@ -661,16 +663,16 @@
                        return false;
                }
        }
-       
+
        /**
         * Add a new contract to the database.  Adds the new insert id to the 
object reference.
-        * 
+        *
         * @param $contract the contract to be added
         * @return array result receipt from the db operation
         */
        function add(&$contract)
        {
-        
+
         $contract->set_id(self::get_new_id($contract->get_old_contract_id()));
 
         // Contract has no old or new ID, get next ID available from DB
@@ -681,7 +683,7 @@
 
                // These are the columns we know we have or that are nullable
                $cols = array('location_id', 'term_id');//
-               
+
                // Start making a db-formatted list of values of the columns we 
have to have
                $values = array(
                        $this->marshal($contract->get_location_id(), 'int'),
@@ -693,101 +695,101 @@
         $values[] = $new_id ? $new_id : $this->marshal($contract->get_id(), 
'int');
 
 
-               
+
                // Check values that can be null before trying to add them to 
the db-pretty list
                if ($contract->get_billing_start_date()) {
                        $cols[] = 'billing_start';
                        $values[] = 
$this->marshal($contract->get_billing_start_date(), 'int');
                }
-               
+
                if ($contract->get_contract_date()) {
                        $cols[] = 'date_start';
                        $cols[] = 'date_end';
                        $values[] = 
$this->marshal($contract->get_contract_date()->get_start_date(), 'int');
                        $values[] = 
$this->marshal($contract->get_contract_date()->get_end_date(), 'int');
                }
-               
+
                if($contract->get_executive_officer_id()) {
                        $cols[] = 'executive_officer';
                        $values[] = 
$this->marshal($contract->get_executive_officer_id(), 'int');
                }
-               
+
                $cols[] = 'created';
                $cols[] = 'created_by';
                $values[] = strtotime('now');
                $values[] = $GLOBALS['phpgw_info']['user']['account_id'];
-               
-               
+
+
                $cols[] = 'service_id';
                $cols[] = 'responsibility_id';
                $values[] = 
$this->marshal($contract->get_service_id(),'string');
                $values[] = 
$this->marshal($contract->get_responsibility_id(),'string');
-               
+
                $cols[] = 'reference';
                $cols[] = 'invoice_header';
                $values[] = $this->marshal($contract->get_reference(),'string');
                $values[] = 
$this->marshal($contract->get_invoice_header(),'string');
-               
+
                $cols[] = 'account_in';
                $cols[] = 'account_out';
                $values[] = 
$this->marshal($contract->get_account_in(),'string');
                $values[] = 
$this->marshal($contract->get_account_out(),'string');
-               
+
                $cols[] = 'project_id';
                $values[] = 
$this->marshal($contract->get_project_id(),'string');
-               
+
                $cols[] = 'old_contract_id';
         $values[] = $new_id ? 
$this->marshal(self::get_old_id($new_id),'string') : 
$this->marshal($contract->get_old_contract_id(),'string');
-               
+
         $cols[] = 'rented_area';
         $values[] =  $this->marshal($contract->get_rented_area(),'float');
-        
+
                $cols[] = 'comment';
                $values[] = $this->marshal($contract->get_comment(),'string');
-               
+
                $cols[] = 'adjustment_interval';
                $values[] = 
$this->marshal($contract->get_adjustment_interval(),'int');
-               
+
                $cols[] = 'adjustment_share';
                $values[] = 
$this->marshal($contract->get_adjustment_share(),'int');
-               
+
                $cols[] = 'adjustable';
                $values[] = ($contract->get_adjustable() ? "true" : "false");
-               
+
                $cols[] = 'adjustment_year';
                $values[] = 
$this->marshal($contract->get_adjustment_year(),'int');
-               
+
                $cols[] = 'publish_comment';
                $values[] = ($contract->get_publish_comment() ? "true" : 
"false");
-               
-               
+
+
                if ($contract->get_security_type()) {
                        $cols[] = 'security_type';
                        $values[] = 
$this->marshal($contract->get_security_type(),'int');
                        $cols[] = 'security_amount';
                        $values[] = 
$this->marshal($contract->get_security_amount(),'string');
                }
-               
+
                if ($contract->get_due_date()) {
                        $cols[] = 'due_date';
                        $values[] = $this->marshal($contract->get_due_date(), 
'int');
                }
-               
+
                if($contract->get_contract_type_id()) {
                        $cols[] = 'contract_type_id';
                        $values[] = 
$this->marshal($contract->get_contract_type_id(), 'int');
                }
-               
+
                // Insert the new contract
                $q ="INSERT INTO rental_contract (" . join(',', $cols) . ") 
VALUES (" . join(',', $values) . ")";
                $result = $this->db->query($q);
-               
+
                return $contract;
        }
-       
+
        /**
         * This method adds a party to a contract. Updates last edited history.
-        * 
+        *
         * @param $contract_id  the given contract
         * @param $party_id     the party to add
         * @return true if successful, false otherwise
@@ -804,10 +806,10 @@
                }
                return false;
        }
-       
+
        /**
         * This method removes a party from a contract. Updates last edited 
history.
-        * 
+        *
         * @param $contract_id  the given contract
         * @param $party_id     the party to remove
         * @return true if successful, false otherwise
@@ -824,10 +826,10 @@
                }
                return false;
        }
-       
+
        /**
         * This method adds a composite to a contract. Updates last edited 
history.
-        * 
+        *
         * @param $contract_id  the given contract
         * @param $composite_id the composite to add
         * @return true if successful, false otherwise
@@ -844,10 +846,10 @@
                }
                return false;
        }
-       
+
        /**
         * This method removes a composite from a contract. Updates last edited 
history.
-        * 
+        *
         * @param $contract_id  the given contract
         * @param $party_id     the composite to remove
         * @return true if successful, false otherwise
@@ -864,12 +866,12 @@
                }
                return false;
        }
-       
-       
-       
+
+
+
        /**
         * This method sets a payer on a contract
-        * 
+        *
         * @param $contract_id  the given contract
         * @param $party_id     the party to be the payer
         * @return true if successful, false otherwise
@@ -877,7 +879,7 @@
        function set_payer($contract_id, $party_id)
        {
                $pid =$this->marshal($party_id, 'int');
-               $cid = $this->marshal($contract_id, 'int'); 
+               $cid = $this->marshal($contract_id, 'int');
                $this->db->transaction_begin();
                $q = "UPDATE rental_contract_party SET is_payer = true WHERE 
party_id = ".$pid." AND contract_id = ".$cid;
                $result = $this->db->query($q);
@@ -927,7 +929,7 @@
 
         return $prefix.$cid;
     }
-    
+
     public function get_contract_types($location_id){
        $q1="SELECT rct.id, rct.label FROM rental_contract_types rct, 
rental_contract_responsibility rcr WHERE rcr.location_id={$location_id} AND 
rct.responsibility_id=rcr.id";
                $this->db->query($q1, __LINE__, __FILE__);
@@ -935,10 +937,10 @@
                while($this->db->next_record()){
                        $results[$this->db->f('id')] = $this->db->f('label');
                }
-               
+
                return $results;
     }
-    
+
     public function get_contract_type_label($contract_type_id){
        $result = "Ingen";
        if(isset($contract_type_id)){
@@ -948,10 +950,10 @@
                                $result = $this->db->f('label');
                        }
        }
-               
+
                return $result;
     }
-    
+
     public function get_contract_type_account($contract_type_id)
     {
        $q1="SELECT rct.account FROM rental_contract_types rct WHERE 
rct.id={$contract_type_id}";
@@ -960,11 +962,11 @@
                while($this->db->next_record()){
                        $result = $this->db->f('account');
                }
-               
+
                return $result;
     }
-    
-    
+
+
     public function get_term_label($billing_term_id){
        $q1="SELECT rbt.title FROM rental_billing_term rbt WHERE 
rbt.id={$billing_term_id}";
                $this->db->query($q1, __LINE__, __FILE__);
@@ -972,7 +974,7 @@
                while($this->db->next_record()){
                        $result = $this->db->f('title');
                }
-               
+
                return $result;
     }
 
@@ -988,7 +990,7 @@
        $success_composites = true;
        $success_parties = true;
        $success_price_items = true;
-       
+
        //composites
        $this->db->query($q_composites);
        while($this->db->next_record()){
@@ -1003,7 +1005,7 @@
                        $success_composites = false;
                }
        }
-       
+
        //parties
         $this->db->query($q_parties);
        while($this->db->next_record()){
@@ -1020,7 +1022,7 @@
                        $success_parties = false;
                }
        }
-       
+
        //price items
         $this->db->query($q_price_items);
        while($this->db->next_record()){
@@ -1059,9 +1061,9 @@
                return false;
        }
     }
-    
+
     public function get_months_in_term($term_id)
-    { 
+    {
                $sql = "SELECT months FROM rental_billing_term WHERE id = 
{$term_id}";
                $result = $this->db->query($sql);
                if(!$result)
@@ -1075,7 +1077,7 @@
                $months = $this->unmarshal($this->db->f('months', true), 'int');
                return $months;
     }
-    
+
     public function update_price_items($contract_id, $rented_area){
        $success_price_item = true;
        $new_area = $rented_area;
@@ -1101,14 +1103,14 @@
                return false;
        }
     }
-    
+
     public function import_contract_reference($contract_id, $reference)
     {
        $reference = $this->marshal($reference,'string');
        $sql = "UPDATE rental_contract SET reference={$reference} WHERE id = 
{$contract_id}";
        $this->db->query($sql);
     }
-    
+
     public function update_adjustment_year_interval($contract_id, 
$adjusted_year, $adjustment_interval)
     {
        $new_adjusted_year = $this->marshal($adjusted_year, 'int');
@@ -1117,7 +1119,7 @@
        $this->db->query($sql);
        return $this->db->affected_rows() > 0 ? true : false;
     }
-    
+
     public function update_contract_end_date($contract_id, $date)
     {
        $cid = $this->marshal($contract_id, 'int');
@@ -1125,7 +1127,7 @@
        $sql = "UPDATE rental_contract SET date_end={$end_date} WHERE id = 
{$cid}";
        $this->db->query($sql);
     }
-    
+
        public function update_adjustment_year($contract_id, $adjusted_year)
     {
        $new_adjusted_year = $this->marshal($adjusted_year, 'int');
@@ -1133,20 +1135,20 @@
        $this->db->query($sql);
        return $this->db->affected_rows() > 0 ? true : false;
     }
-    
+
     public function update_adjustment_share($contract_id, $adjustment_share)
     {
        $new_adjustment_share = $this->marshal($adjustment_share, 'int');
        $sql = "UPDATE rental_contract SET 
adjustment_share={$new_adjustment_share} WHERE id = {$contract_id}";
        $this->db->query($sql);
     }
-    
+
     public function get_default_price_items($location_id)
     {
        $price_items = array();
        $loc_id = $this->marshal($location_id, 'int');
-       
-       //select all standard price_items for given location_id 
+
+       //select all standard price_items for given location_id
        $sql = "SELECT id FROM rental_price_item WHERE 
responsibility_id={$loc_id} AND NOT is_inactive AND standard";
        $this->db->query($sql);
        while($this->db->next_record())

Modified: trunk/rental/inc/model/class.contract.inc.php
===================================================================
--- trunk/rental/inc/model/class.contract.inc.php       2013-06-11 13:07:32 UTC 
(rev 11165)
+++ trunk/rental/inc/model/class.contract.inc.php       2013-06-12 05:03:43 UTC 
(rev 11166)
@@ -11,10 +11,10 @@
                const SECURITY_TYPE_DEPOSIT = 2;
                const SECURITY_TYPE_ADVANCE = 3;
                const SECURITY_TYPE_OTHER_GUARANTEE = 4;
-               
+
                public static $so;
                public static $types;
-               
+
                protected $id;
                protected $parties;
                protected $contract_date;
@@ -55,11 +55,11 @@
                protected $bill_only_one_time;
                protected $publish_comment;
                protected $total_price_current_year;
-               
+
                /**
                 * Constructor.  Takes an optional ID.  If a contract is 
created from outside
                 * the database the ID should be empty so the database can add 
one according to its logic.
-                * 
+                *
                 * @param int $id the id of this composite
                 */
                public function __construct(int $id = null)
@@ -67,10 +67,10 @@
                        $this->id = (int)$id;
                        $this->parties = array();
                        $this->composites = array();
-                       $this->bill_timestamps = array(); // Consider to have 
all invoices here if other data than billing timetamps are needed 
+                       $this->bill_timestamps = array(); // Consider to have 
all invoices here if other data than billing timetamps are needed
                        $bill_only_one_time = false;
                }
-               
+
                public function toArray()
                {
 
@@ -87,7 +87,7 @@
                                'get_composites', //returnerer objekt
                                'get_parties' //returnerer objekt
                        );
-                       
+
                        $class_methods = get_class_methods($this);
                        $contract_arr = array();
                        foreach ($class_methods as $class_method)
@@ -107,78 +107,78 @@
                {
                        $this->id = $id;
                }
-               
+
                public function get_id() { return $this->id; }
-               
+
                public function set_payer($id)
                {
                        $so = self::get_so();
                        $so->set_payer($this->get_id(),$id);
                }
-               
+
                public function set_payer_id($id){
                        $this->payer_id = $id;
                }
-               
+
                public function set_old_contract_id($id){
                        $this->old_contract_id = $id;
                }
-               
+
                public function get_old_contract_id(){
                        return $this->old_contract_id;
                }
-               
+
                public function get_payer_id() { return $this->payer_id; }
-               
+
                public function set_parties($parties)
                {
                        $this->parties = $parties;
                }
-               
+
                public function set_contract_date($date)
                {
                        $this->contract_date = $date;
                }
-               
+
                public function get_contract_date() {
                        return $this->contract_date;
                }
-               
+
                public function set_billing_start_date($date)
                {
                        $this->billing_start_date = $date;
                }
-               
+
                public function set_next_bill_timestamp($next_bill_timestamp)
                {
                        $this->next_bill_timestamp = $next_bill_timestamp;
                }
-               
+
                public function get_next_bill_timestamp()
                {
                        return $this->next_bill_timestamp;
                }
-               
+
                public function get_executive_officer_id() {
                        return $this->executive_officer_id;
                }
-               
+
                public function set_executive_officer_id($id)
                {
                        $this->executive_officer_id = $id;
                }
-               
+
                /**
                 * Returns date of when the first invoice should be produced 
for the
                 * contract.
                 * @return string with UNIX time.
                 */
-               public function get_billing_start_date() { 
+               public function get_billing_start_date() {
                        if(isset($this->billing_start_date))
                        {
                                return $this->billing_start_date;
                        }
-                       
+
                        if(isset($this->contract_date))
                        {
                                return $this->contract_date->get_start_date();
@@ -186,89 +186,89 @@
 
                        return '';
                }
-               
+
                public function set_location_id($location_id)
                {
                        $this->field_of_responsibility_id = (int) $location_id;
                        $this->location_id = (int) $location_id;
                }
-               
+
                public function set_project_id($project_id)
                {
                        $this->project_id = $project_id;
                }
-       
+
                public function get_project_id(){ return $this->project_id; }
-               
+
                public function get_location_id() { return $this->location_id; }
-               
+
                public function set_service_id($service_id)
                {
                        $this->service_id = $service_id;
                }
-               
+
                public function get_service_id() { return $this->service_id; }
-               
+
                public function set_responsibility_id($responsibility_id)
                {
                        $this->responsibility_id = $responsibility_id;
                }
-               
+
                public function get_responsibility_id() { return 
$this->responsibility_id; }
-               
+
                public function set_term_id(int $term_id)
                {
                        $this->term_id = (int)$term_id;
                }
-               
+
                public function get_term_id() { return $this->term_id; }
-               
+
                public function get_account_in() { return $this->account_in; }
-               
+
                public function set_account_in($account_in)
                {
                        $this->account_in = $account_in;
                }
-               
+
                public function get_account_out() { return $this->account_out; }
-               
+
                public function set_account_out($account_out)
                {
                        $this->account_out = $account_out;
                }
-               
+
                public function get_reference() { return $this->reference; }
-               
+
                public function set_reference($reference)
                {
                        $this->reference = $reference;
                }
-               
+
                public function get_invoice_header() { return 
$this->invoice_header; }
-               
+
                public function set_invoice_header($invoice_header)
                {
                        $this->invoice_header = $invoice_header;
                }
-               
-               
-               
+
+
+
                public function set_term_id_title($term_id_title)
                {
                        $this->term_id_title = $term_id_title;
                }
 
-               public function get_term_id_title(){ 
+               public function get_term_id_title(){
                        if(isset($this->term_id_title) && $this->term_id_title 
!= '')
-                       {       
-                               return lang($this->term_id_title); 
+                       {
+                               return lang($this->term_id_title);
                        }
                        else
                        {
                                return null;
                        }
                }
-               
+
                public function set_security_type(int $security_type = null)
                {
                        switch($security_type)
@@ -290,41 +290,41 @@
                                        break;
                        }
                }
-               
+
                public function get_security_type() { return 
$this->security_type; }
-               
+
                public function set_security_amount($security_amount)
                {
                        $this->security_amount = $security_amount;
                }
-               
+
                public function get_security_amount() { return 
$this->security_amount; }
-               
+
                /**
                 * Get the name of the contract type @see get_location_id()
-                * 
+                *
                 * @return string
                 */
                public function get_contract_type_title()
                {
                        return $this->contract_type_title;
                }
-               
+
                public function set_contract_type_title($title)
                {
                        $this->contract_type_title = $title;
                }
-               
+
                public function get_bill_only_one_time()
                {
                        return $this->bill_only_one_time;
                }
-               
+
                public function set_bill_only_one_time()
                {
                        $this->bill_only_one_time = true;
                }
-               
+
                public function get_party_name(){
                        $names = '';
                        foreach($this->parties as $party) {
@@ -332,7 +332,15 @@
                        }
                        return $names;
                }
-               
+
+               public function get_party_department(){
+                       $names = '';
+                       foreach($this->parties as $party) {
+                               $names .= $party->get_department()."<br/>";
+                       }
+                       return $names;
+               }
+
                public function get_party_name_as_list(){
                        $names = '';
                        $tot_parties = count($this->parties);
@@ -346,7 +354,7 @@
                        }
                        return $names;
                }
-               
+
                public function get_composite_name(){
                        $names = '';
                        foreach($this->composites as $composite) {
@@ -354,7 +362,7 @@
                        }
                        return $names;
                }
-               
+
                public function get_composite_name_as_list(){
                        $names = '';
                        $tot_composites = count($this->composites);
@@ -368,34 +376,34 @@
                        }
                        return $names;
                }
-               
+
                public function set_composites($composites)
                {
                        $this->composites = $composites;
                }
-               
+
                public function set_last_edited_by_current_user($date)
                {
                        $this->last_edited_by_current_user = $date;
                }
-               
+
                public function get_last_edited_by_current_user() { return 
$this->last_edited_by_current_user;}
-               
+
                /**
                 * Get a list of the composites associated with this contract.
-                * 
+                *
                 * @return array with rental_composite objects, empty array if 
none, never null.
                 */
                public function get_composites()
                {
                        return $this->composites;
                }
-               
+
                /**
                 * Get a list of the composites associated with this contract.  
The composites are loaded
                 * lazily, so they will not be populated at object 
construction, but rather at first call
                 * of this function.
-                * 
+                *
                 * @return rental_composite[]
                 */
                public function get_available_composites()
@@ -403,59 +411,59 @@
                        $so = self::get_so();
                        return 
$so->get_available_composites_for_contract($this->get_id());
                }
-               
+
                /**
                 * Get a list of the parties associated with this contract.  
The parties are loaded
                 * lazily, so they will not be populated at object 
construction, but rather at first call
                 * of this function.
-                * 
+                *
                 * @return rental_party[]
                 */
                public function get_parties()
                {
                        return $this->parties;
                }
-               
 
+
         public function set_comment($comment)
         {
             $this->comment = $comment;
         }
-        
+
         /**
          * Get the timestamp for the last update on this contract
-         * 
+         *
          * @return int timestamp for last update
          */
         public function get_last_updated()
         {
             return $this->last_updated;
         }
-        
+
         /**
          * Set the timestamp for the last update on this contract
-         * 
+         *
          * @param $timestamp last update
          */
                public function set_last_updated($timestamp)
         {
             $this->last_updated = $timestamp;
         }
-        
+
         /**
          * Get comment associated with this contract.
-         * 
+         *
          * @return string comment
          */
         public function get_comment()
         {
             return $this->comment;
         }
-               
+
                /**
                 * Add a composite to this contract. This method does not check 
if
                 * object is already added and does not do any db handling.
-                * 
+                *
                 * @param $new_composite
                 */
                public function add_composite(rental_composite $new_composite)
@@ -466,27 +474,27 @@
                                $this->composites[$new_composite_id] = 
$new_composite;
                        }
                }
-               
+
                /**
                 * Add a party to this contract. This method does not check if
                 * object is already added and does not do any db handling.
-                * 
+                *
                 * @param rental_party $new_party the new party
                 */
                public function add_party(rental_party $new_party)
                {
                        $new_party_id = $new_party->get_id();
-                       
+
                        if(!in_array($new_party_id,$this->parties))
                        {
                                $this->parties[$new_party_id] = $new_party;
                        }
                }
-               
+
                /**
                 * Add a price_item to this contract. This function does not 
check for duplicates
                 * before adding the price_item because multiple instances of 
the same price items are allowed.
-                * 
+                *
                 * @param $new_price_item
                 */
                public function add_price_item(rental_price_item 
$new_price_item)
@@ -497,22 +505,22 @@
                        $price_items[] = $new_price_item;
                        $this->set_price_items($price_items);
                }
-               
+
                public function remove_party(rental_party $party_to_remove)
                {
                        unset($this->parties[$party_to_remove]);
                        $so = self::get_so();
                        
$so->remove_party($this->get_id(),$party_to_remove->get_id());
                }
-               
-               
+
+
                public function remove_composite(rental_composite 
$composite_to_remove)
                {
                        unset($this->composites[$composite_to_remove]);
                        $so = self::get_so();
                        
$so->remove_composite($this->get_id(),$composite_to_remove->get_id());
                }
-               
+
                public function remove_price_item(rental_contract_price_item 
$price_item_to_remove)
                {
                        // TODO: Does this work?
@@ -520,8 +528,8 @@
                        $so = self::get_so();
                        
$so->remove_price_item($this->get_id(),$price_item_to_remove);
                }
-               
-               
+
+
                public function add_bill_timestamp(int $timestamp)
                {
                        if(!in_array($timestamp, $this->bill_timestamps)) // 
New timestamnp
@@ -529,12 +537,12 @@
                                $this->bill_timestamps[] = (int)$timestamp;
                        }
                }
-               
+
                /**
                 * Helper method to return the end date of the last invoice. 
The timestamp
                 * parameter is optional, but when used the date returned will 
be the
                 * end date of the last invoice before or at that time.
-                *  
+                *
                 * @param $timestamp int with UNIX timestamp.
                 * @return int with UNIX timestamp with the end date of the 
invoice, or
                 * null if no such invoice was found.
@@ -547,7 +555,7 @@
                                $this->bill_timestamps = 
array_reverse($this->bill_timestamps); // ..then we reverse them to make the 
last biling come first
                                if($timestamp == null) // No timestamp specified
                                {
-                                       // We can just use the first invoice;   
        
+                                       // We can just use the first invoice;
                                        return $this->bill_timestamps[0];
                                }
                                foreach ($this->bill_timestamps as 
$bill_timestamp) // Runs through all invoices
@@ -563,7 +571,7 @@
 
                /**
                 * Get a static reference to the storage object associated with 
this model object
-                * 
+                *
                 * @return the storage object
                 */
                public static function get_so()
@@ -571,13 +579,13 @@
                        if (self::$so == null) {
                                self::$so = CreateObject('rental.socontract');
                        }
-                       
+
                        return self::$so;
                }
-               
+
                /**
                 * Return a list of all contracts registered on the given 
rental_composite
-                * 
+                *
                 * @param $composite_id which composite to return contracts for
                 * @param $start                which index to start the list at
                 * @param $results      how many results to return
@@ -593,27 +601,27 @@
                        $so = self::get_so();
                        return $so->get_contracts($composite_id, $sort = null, 
$dir = '', $start = 0, $results = 1000, $status = null, $date = null);
                }
-               
+
                public function get_last_edited_by()
                {
                        $so = self::get_so();
                        $contracts = $so->get_last_edited_by($this->get_id());
                        return $GLOBALS['phpgw']->accounts->id2name($contracts);
                }
-               
-               /** 
-                * 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. 
-                */ 
+
+               /**
+                * 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 static function get_year_range()
                {
                        return self::get_so()->get_year_range();
                }
-               
-       
+
+
                public function get_total_price_current_year()
                {
                        /* 1. Get current year
@@ -621,9 +629,9 @@
                         * 2.1 ...ended - return 0
                         * 2.2 ...active alle year - return total price
                         * 2.3 ...ends or starts current year - calculate price
-                        * 2.3.1 
+                        * 2.3.1
                         */
-                       
+
                        $date_start = phpgw::get_var('date_start');
                        $date_end = phpgw::get_var('date_end');
 
@@ -632,14 +640,14 @@
                                $date_start = 
$aDate[1]."/".$aDate[0]."/".$aDate[2];
                                $timestamp_invoice_start = 
strtotime($date_start);
                        }
-                       
+
                        if(isset($date_end)){
                                $aDate = split ("/", $date_end);
                                $date_end = 
$aDate[1]."/".$aDate[0]."/".$aDate[2];
                                $timestamp_invoice_end = strtotime($date_end);
                        }
-                       
-                       
+
+
                        if(!isset($timestamp_invoice_start) || 
$timestamp_invoice_start == "" || !isset($timestamp_invoice_end) || 
$timestamp_invoice_end == ""){
                                $current_year = date("Y");
                                $timestamp_invoice_start = 
strtotime("{$current_year}-1-1");
@@ -651,7 +659,7 @@
                        {
                                $contract_start = 
$contract_dates->get_start_date();
                                $contract_end = $contract_dates->get_end_date();
-                               
+
                                if(isset($contract_end) && $contract_end < 
$timestamp_invoice_start)
                                {
                                        return 0; // The contract ends before 
start of current year
@@ -665,13 +673,13 @@
                        {
                                return 0; // The contract has no dates
                        }
-                       
+
                        // The contract is active only parts of the current 
year, we must calculate the total sum using the billing logic
-                       
+
                        $total_sum = 0; // Holding the total price of the 
contract current year
                        $contract_price_items = 
rental_socontract_price_item::get_instance()->get(null, null, null, null, null, 
null, array('contract_id' => $this->get_id()));
-                       
-                       
+
+
                        // Run through the contract price items
                        foreach($contract_price_items as $contract_price_item)
                        {
@@ -683,7 +691,7 @@
                                        // We just use the invoice date for our 
calculations
                                        $contract_price_item_start = 
$timestamp_invoice_start;
                                }
-                               
+
                                // Determine end date for price item
                                $contract_price_item_end = 
$contract_price_item->get_date_end();
                                if($contract_price_item_end == null || 
$contract_price_item_end == '') // Date not set
@@ -691,13 +699,13 @@
                                        // We just use the invoice date for our 
calculations
                                        $contract_price_item_end = 
$timestamp_invoice_end;
                                }
-                               
+
                                // Sanity check - end date should never be 
before start date
-                               if($contract_price_item_end < 
$contract_price_item_start) 
+                               if($contract_price_item_end < 
$contract_price_item_start)
                                {
                                        continue; // We don't add this price 
item - continue to next
                                }
-                               
+
                                // Checking the start date against the invoice 
dates
                                if($contract_price_item_start < 
$timestamp_invoice_start) // Start of price item before invoice start
                                {
@@ -711,7 +719,7 @@
                                {
                                        $invoice_price_item_start = 
$contract_price_item_start; // We use the price item start
                                }
-                               
+
                                // Checking the end date against invoice dates
                                if($contract_price_item_end < 
$timestamp_invoice_start) // End of price item before this invoice starts
                                {
@@ -720,12 +728,12 @@
                                else if($contract_price_item_end < 
$timestamp_invoice_end) // End of price item before invoice end
                                {
                                        $invoice_price_item_end = 
$contract_price_item_end; // We use the price item end
-                               } 
+                               }
                                else // Price item end date is somewhere after 
invoice end
                                {
                                        $invoice_price_item_end = 
$timestamp_invoice_end;       // We use the invoice end
                                }
-                               
+
                                // Checking the contract dates against the 
temporary price item dates
                                if(isset($contract_start) && 
!$contract_price_item->is_one_time())
                                {
@@ -733,28 +741,28 @@
                                        {
                                                continue; //No price items for 
this contract will be billed
                                        }
-                                       
+
                                        if($contract_start > 
$invoice_price_item_start) // The contract start is after the start of the 
price item
                                        {
                                                $invoice_price_item_start = 
$contract_start;
                                        }
                                }
-                               
+
                                if(isset($contract_end) && 
!$contract_price_item->is_one_time())
                                {
                                        if($contract_end < 
$timestamp_invoice_start) // The end of the contract is before the billing 
period (should never happen)
                                        {
                                                continue; //No price items for 
this contract will be billed
                                        }
-                                       
+
                                        if($contract_end < 
$invoice_price_item_end) // The contract start is after the start of the price 
item
                                        {
                                                $invoice_price_item_end = 
$contract_end;
                                        }
                                }
-                               
+
                                // --- End of period calculation ---
-                               
+
                                // Create a new invoice price item
                                $invoice_price_item = new 
rental_invoice_price_item(
                                        2,                                      
                                // the number of decimals to use for the total 
price of the price item
@@ -769,12 +777,12 @@
                                        $invoice_price_item_start,              
                        // the start date from which this price item should be 
calculated
                                        $invoice_price_item_end                 
                        // the end date to which this price item should be 
calculated
                                );
-                               
-                               
+
+
                                $total_price_price_item = 0;
-                               
+
                                // If the contract price item is of type 
one-time and it's dates are within the invoice period ...
-                               if($contract_price_item->is_one_time()){ 
+                               if($contract_price_item->is_one_time()){
                                        if($contract_price_item_start >= 
$timestamp_invoice_start && $contract_price_item_start <= 
$timestamp_invoice_end){
                                                // ... set the total price of 
the invoice price item to the total price of the contract price item
                                                $total_price_price_item = 
$contract_price_item->get_total_price();
@@ -784,13 +792,13 @@
                                }
                                $total_sum += round($total_price_price_item,2);
                        } // end of looping through the contract price items
-                       
+
                        $total_sum = round($total_sum, 2);
                        return $total_sum;
-                       
+
                }
-               
-               
+
+
                public function serialize()
                {
 //                     require_once PHPGW_API_INC.'/adodb/adodb-time.inc.php';
@@ -799,14 +807,14 @@
                        {
                                $this->total_price =  
rental_socontract_price_item::get_instance()->get_total_price($this->get_id());
                        }
-                       
+
                if(!isset($this->total_price_current_year))
                        {
                                $this->total_price_current_year = 
$this->get_total_price_current_year();
-                               
+
                                //$this->total_price_current_year =  
rental_socontract_price_item::get_instance()->get_total_price_invoice($this->get_id());
                        }
-                       
+
                        return array(
                                'id' => $this->get_id(),
                                'date_start' => $this->get_contract_date() && 
$this->get_contract_date()->has_start_date() ? date($date_format, 
$this->get_contract_date()->get_start_date()): '',
@@ -815,6 +823,7 @@
                                'type'  => 
lang($this->get_contract_type_title()).' / 
'.lang(rental_socontract::get_instance()->get_contract_type_label($this->get_contract_type_id())),
                                'composite' => $this->get_composite_name(),
                                'party' => $this->get_party_name(),
+                               'department' => $this->get_party_department(),
                                'old_contract_id' => 
$this->get_old_contract_id(),
                                //'last_edited_by_current_user' => 
$this->get_last_edited_by_current_user() ? date($date_format.' h:i:s A', 
$this->get_last_edited_by_current_user()): '',
                                'last_edited_by_current_user' => 
$this->get_last_edited_by_current_user() ? date($date_format, 
$this->get_last_edited_by_current_user()): '',
@@ -840,118 +849,118 @@
                                'total_price_current_year' => 
$this->total_price_current_year
                        );
                }
-               
+
                public static function export(string $name, bool $return)
                {
-                       
+
                }
-               
-       
+
+
                public function set_due_date($due_date)
                {
                        $this->due_date = $due_date;
                }
-       
+
                public function get_due_date()
                {
                        return $this->due_date;
                }
-               
+
                public function set_total_price($total_price)
                {
                        $this->total_price = $total_price;
                }
-       
+
                public function get_total_price()
                {
                        return $this->total_price;
                }
-               
+
                public function 
set_total_price_current_year($total_price_current_year)
                {
                        $this->total_price_current_year = 
$total_price_current_year;
                }
-               
+
                public function set_max_area($max_area)
                {
                        $this->max_area = $max_area;
                }
-       
+
                public function get_max_area()
                {
                        return $this->max_area;
                }
-               
+
                public function set_adjustment_interval($adjustment_interval)
                {
                        $this->adjustment_interval = $adjustment_interval;
                }
-       
+
                public function get_adjustment_interval()
                {
                        return $this->adjustment_interval;
                }
-               
+
                public function set_adjustment_share($adjustment_share)
                {
                        $this->adjustment_share = $adjustment_share;
                }
-       
+
                public function get_adjustment_share()
                {
                        return $this->adjustment_share;
                }
-               
+
                public function set_adjustment_year($adjustment_year)
                {
                        $this->adjustment_year = $adjustment_year;
                }
-       
+
                public function get_adjustment_year()
                {
                        return $this->adjustment_year;
                }
-               
+
                public function set_adjustable($adjustable)
                {
                        $this->adjustable = (boolean)$adjustable;
                }
-               
+
                public function is_adjustable()
                {
                        return $this->adjustable;
                }
-               
+
                public function get_adjustable()
                {
                        return $this->adjustable;
                }
-               
+
                public function set_contract_type_id($contract_type_id)
                {
                        $this->contract_type_id = $contract_type_id;
                }
-       
+
                public function get_contract_type_id()
                {
                        return $this->contract_type_id;
                }
-               
+
                public function set_notify_before($notify_before)
                {
                        $this->notify_before = $notify_before;
                }
-       
+
                public function get_notify_before()
                {
                        return $this->notify_before;
                }
-               
+
                public function 
set_notify_before_due_date($notify_before_due_date)
                {
                        $this->notify_before_due_date = $notify_before_due_date;
                }
-       
+
                public function get_notify_before_due_date()
                {
                        return $this->notify_before_due_date;
@@ -961,12 +970,12 @@
                {
                        $this->notify_after_termination_date = 
$notify_after_termination_date;
                }
-       
+
                public function get_notify_after_termination_date()
                {
                        return $this->notify_after_termination_date;
                }
-               
+
                public function get_contract_notification_status()
                {
                        $ts = strtotime(date('Y-m-d')); // timestamp for today
@@ -975,27 +984,27 @@
                        $ts_notify_after_termination_date = 
$this->notify_after_termination_date * 60 * 60 * 24;
                        $date_start = 
$this->get_contract_date()->get_start_date();
                        $date_end = $this->get_contract_date()->get_end_date();
-                       
+
                        $status = array();
-                       
-                       if(isset($date_end) && ($date_end >= $ts) && ($ts >= 
($date_end - $ts_notify_before)))  
+
+                       if(isset($date_end) && ($date_end >= $ts) && ($ts >= 
($date_end - $ts_notify_before)))
                        {
                                // If contract has end date which is in the 
future and notification date is today or in the past
                                $status[] = lang("under_dismissal");    // 
CONTRACT UNDER DISMISSAL
                        }
-                       
-                       if(isset($date_end) && ($date_end < $ts) && ($ts < 
($date_end + $ts_notify_after_termination_date))) 
+
+                       if(isset($date_end) && ($date_end < $ts) && ($ts < 
($date_end + $ts_notify_after_termination_date)))
                        {
-                               // If the contract has end date shich is in the 
past and the end date is within a given time ago 
+                               // If the contract has end date shich is in the 
past and the end date is within a given time ago
                                $status[] =  lang("terminated_contract");       
// CONTRACT UNDER TERMINATION
                        }
-                       
+
                        if(isset($this->due_date) && ($this->due_date >= $ts) 
&& ($ts >= ($this->due_date - $ts_notify_before_due_date)))
                        {
                                // If the contract has a due date which is in 
the future and the due date is today or within a given time in the future
                                $status[] = lang("closing_due_date");   // 
CLOSING DUE DATE
                        }
-                       
+
                        if(count($status) > 0)
                        {
                                return implode("<br/>",$status);
@@ -1005,25 +1014,25 @@
                                return '';
                        }
                }
-       
+
                public function get_contract_status()
                {
                        $ts = strtotime(date('Y-m-d')); // timestamp for today
-                       
+
                        $date_start = 
$this->get_contract_date()->get_start_date();
                        $date_end = $this->get_contract_date()->get_end_date();
-                       
-                       if(isset($date_start) && ($ts < $date_start || 
$date_start == ''))                                                             
 
+
+                       if(isset($date_start) && ($ts < $date_start || 
$date_start == ''))
                        {
                                // If contract has start date AND (today is 
before start date OR empty start date)
                                return lang("under_planning");          // 
CONTRACT UNDER PLANNING
                        }
-                       
-                       else if(isset($date_start) && $ts >= $date_start && 
(!isset($date_end) || $ts <= $date_end))                                        
                    
-                       {       
-                               // else ... if contract has start date AND 
start date is today or in the past AND 
-                               // (contract has end date OR end date is in the 
future) 
-                               return lang("active_single");           // 
ACTIVE CONTRACT                                                                 
                     
+
+                       else if(isset($date_start) && $ts >= $date_start && 
(!isset($date_end) || $ts <= $date_end))
+                       {
+                               // else ... if contract has start date AND 
start date is today or in the past AND
+                               // (contract has end date OR end date is in the 
future)
+                               return lang("active_single");           // 
ACTIVE CONTRACT
                        }
                        else if(isset($date_end) && $ts > $date_end)
                        {
@@ -1036,35 +1045,35 @@
                                return lang("status_unknown");          // 
UNKNOWN STATUS
                        }
                }
-               
+
                public function is_active($date)
                {
                        $ts = $date;
                        if(!$ts)
                                $ts = strtotime(date('Y-m-d')); // timestamp 
for today
-                       
+
                        $date_start = 
$this->get_contract_date()->get_start_date();
                        $date_end = $this->get_contract_date()->get_end_date();
-                       
-                       if(isset($date_start) && $ts >= $date_start && 
(!isset($date_end) || $ts <= $date_end))                                        
                 
-                       {       
-                               return true;    // ACTIVE CONTRACT              
                                                                        
+
+                       if(isset($date_start) && $ts >= $date_start && 
(!isset($date_end) || $ts <= $date_end))
+                       {
+                               return true;    // ACTIVE CONTRACT
                        }
                        return false;
                }
-               
+
                public function set_rented_area($rented_area)
                {
                        $this->rented_area = $rented_area;
                }
-               
+
                public function get_rented_area() { return $this->rented_area; }
-               
+
                public function get_publish_comment()
                {
                        return $this->publish_comment;
                }
-               
+
                public function set_publish_comment($publish_comment)
                {
                        $this->publish_comment = (boolean)$publish_comment;
@@ -1075,20 +1084,20 @@
                 * @see rental/inc/model/rental_model#validates()
                 */
                public function validates(){
-                       
+
                        // If the contract has number as identifier, it must be 
greater than 1
                        /*$id = $this->get_id();
                        if(is_numeric($id) && $id < 1){
                                return false;
                        }*/
-                       
+
                        // The contract must be designated a responsibility area
                        if($this->get_location_id() == null || 
$this->get_location_id() < 1){
                                return false;
                        }
                        return true;
                }
-               
+
                /**
                 * (non-PHPdoc)
                 * @see rental/inc/model/rental_model#validate_numeric()
@@ -1129,7 +1138,7 @@
                        }
                        return $valid_numeric;
                }
-               
+
                /**
                 * (non-PHPdoc)
                 * @see rental/inc/model/rental_model#check_consistency()
@@ -1142,7 +1151,7 @@
                                $start_date = 
$this->get_contract_date()->get_start_date();
                                $end_date = 
$this->get_contract_date()->get_end_date();
                        }
-                       
+
                        // Give warning if the contract lacks a start date
                        if(!isset($start_date))
                        {
@@ -1150,23 +1159,23 @@
                        }
                        else
                        {
-                               
+
                                // If set, the billing date must be between the 
contract's start date and end date
                                $billing_start = 
$this->get_billing_start_date();
                                if(isset($billing_start) && 
is_numeric($billing_start) && $billing_start > 0)
                                {
                                        if($billing_start < $start_date || 
(isset($end_date) && $billing_start > $end_date)){
                                                
$this->set_consistency_warning(lang('warning_billing_date_between'));
-                                       } 
+                                       }
                                }
-                               
+
                                // If set, the due date must be between the 
contract's start date and end date
                                $due_date = $this->get_due_date();
                                if(isset($due_date) && is_numeric($due_date) && 
$due_date > 0)
                                {
                                        if($due_date < $start_date || 
(isset($end_date) && $due_date > $end_date)){
                                                
$this->set_consistency_warning(lang('warning_due_date_between'));
-                                       } 
+                                       }
                                }
                                $so_price_item = 
rental_socontract_price_item::get_instance();
                                $price_items = $so_price_item->get(null, null, 
null, null, null, null, array('contract_id' => $this->get_id()));
@@ -1187,7 +1196,7 @@
                                }
                        }
                }
-               
+
        }
 
 ?>




reply via email to

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