[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/class.soinvestment.php, 1.1.1.3
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/class.soinvestment.php, 1.1.1.3 |
Date: |
Fri, 21 May 2004 15:47:50 -0000 |
Update of /property
Modified Files:
Branch:
class.soinvestment.php
date: 2004/04/23 21:26:33; author: sigurdne; state: Exp; lines: +371 -371
Log Message:
no message
=====================================================================
Index: property/class.soinvestment.php
diff -u property/class.soinvestment.php:1.1.1.2
property/class.soinvestment.php:1.1.1.3
--- property/class.soinvestment.php:1.1.1.2 Fri Apr 23 20:25:48 2004
+++ property/class.soinvestment.php Fri Apr 23 21:26:33 2004
@@ -1,371 +1,371 @@
-<?php
-
/**************************************************************************\
- * phpGroupWare - property
*
- * http://www.phpgroupware.org
*
- *
*
- * Facilities Management
*
- * Written by Sigurd Nes [sigurdne at online.no]
*
- *
------------------------------------------------------------------------ *
- * Copyright 2000 - 2003 Free Software Foundation, Inc
*
- * This program is part of the GNU project, see http://www.gnu.org/
*
- *
------------------------------------------------------------------------ *
- * 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.
*
-
\**************************************************************************/
-
- class property_soinvestment
- {
-
- function property_soinvestment()
- {
- $this->currentapp = 'property';
//$GLOBALS['phpgw_info']['flags']['currentapp'];
- $this->db = $GLOBALS['phpgw']->db;
- $this->db2 = $this->db;
- $this->account = $GLOBALS['phpgw_data']['user']['id'];
- $this->bocommon =
CreateObject($this->currentapp.'_bocommon');
-
- $this->join = $this->bocommon->join;
- }
-
- function get_type_list()
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
entity_type FROM fm_investment GROUP BY entity_type ");
- while (!$dbresult->EOF)
- {
- $type_list[] = Array(
- 'id' =>
$dbresult->fields['entity_type'],
- 'num' =>
lang($dbresult->fields['entity_type'])
- );
- $dbresult->MoveNext();
- }
- return $type_list;
- }
-
-
- function read($data)
- {
- if(is_array($data))
- {
- if ($data['start'])
- {
- $start=$data['start'];
- }
- else
- {
- $start=0;
- }
- $filter =
(isset($data['filter'])?$data['filter']:'');
- $query =
(isset($data['query'])?$data['query']:'');
- $sort =
(isset($data['sort'])?$data['sort']:'DESC');
- $order =
(isset($data['order'])?$data['order']:'');
- $cat_id =
(isset($data['cat_id'])?$data['cat_id']:'');
- $part_of_town_id =
(isset($data['part_of_town_id'])?$data['part_of_town_id']:'');
- $allrows =
(isset($data['allrows'])?$data['allrows']:'');
-
- }
- if (!$cat_id)
- {
- return;
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
- }
- else
- {
- if ($cat_id=='property')
- {
- $ordermethod = ' order by
fm_part_of_town.name ,fm_location1.loc1 DESC';
- }
- else
- {
- $ordermethod = ' order by
fm_investment.entity_id DESC';
- }
- }
-
- if ($part_of_town_id)
- {
- $filtermethod = "and
fm_part_of_town.part_of_town_id ='$part_of_town_id'";
- }
-
- if ($filter=='investment')
- {
- $filtermethod .= "and initial_value > 0";
- }
- if ($filter=='funding')
- {
- $filtermethod .= "and initial_value < 0";
- }
-
- if ($cat_id=='property')
- {
- $sql = "SELECT fm_investment.entity_id as
entity_id, fm_investment.descr as descr,
fm_investment_value.invest_id,initial_value, fm_location1.loc1_name as name,
fm_part_of_town.district_id, fm_part_of_town.name as part_of_town,"
- . " fm_investment_value.value,
fm_investment_value.date, fm_investment_value.this_index, "
- . " fm_investment_value.index_count"
- . " FROM (((fm_investment $this->join
fm_investment_value ON ( fm_investment.entity_id =
fm_investment_value.entity_id) AND "
- . " (fm_investment.invest_id =
fm_investment_value.invest_id )) "
- . " $this->join fm_location1 ON
(fm_investment.loc1 = fm_location1.loc1)) "
- . " $this->join fm_part_of_town ON
(fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id)) "
- . " WHERE ( current_index = '1' or (this_index
= NULL and index_count= '1')) AND entity_type ='$cat_id' $filtermethod ";
-
- }
- else
- {
- $sql = "SELECT
fm_investment.location_code,fm_investment.entity_id, fm_investment.descr as
descr, fm_investment_value.invest_id,initial_value,
fm_part_of_town.district_id, fm_part_of_town.name as part_of_town,"
- . " fm_investment_value.value,
fm_investment_value.date,
fm_investment_value.this_index,fm_entity_category.name as entity_name, "
- . " fm_investment_value.index_count "
- . " FROM ((((fm_investment $this->join "
- . " fm_entity_category ON
(fm_investment.p_entity_id = fm_entity_category.entity_id AND
fm_investment.p_cat_id = fm_entity_category.id)) $this->join "
- . " fm_investment_value ON
(fm_investment_value.entity_id = fm_investment.entity_id) AND "
- . " (fm_investment_value.invest_id =
fm_investment.invest_id)) "
- . " $this->join fm_location1 ON
(fm_investment.loc1 = fm_location1.loc1)) "
- . " $this->join fm_part_of_town ON
(fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id)) "
- . " WHERE ( current_index = '1' or (this_index
= NULL and index_count= '1')) AND entity_type ='$cat_id' $filtermethod ";
- }
- if($sql)
- {
- $dbresult2 =
$GLOBALS['phpgw']->db->Execute($sql);
- $this->total_records = $dbresult2->_numOfRows;
-
-
- $maxmatchs = 15;
-
- if(!$allrows)
- {
- $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
-
- }
- else
- {
- $dbresult =
$GLOBALS['phpgw']->db->Execute($sql . $ordermethod);
- }
-
- }
-
-
- $i=0;
- while (!$dbresult->EOF)
- {
- $investment[$i]['counter']
= $i;
- $investment[$i]['location_code'] =
$dbresult->fields['location_code'];
- $investment[$i]['entity_id'] =
$dbresult->fields['entity_id'];
- $investment[$i]['investment_id'] =
$dbresult->fields['invest_id'];
- $investment[$i]['district_id'] =
$dbresult->fields['district_id'];
- $investment[$i]['part_of_town'] =
$dbresult->fields['part_of_town'];
- $investment[$i]['descr']
= $dbresult->fields['descr'];
- $investment[$i]['initial_value'] =
$dbresult->fields['initial_value'];
- $investment[$i]['value']
= $dbresult->fields['value'];
- $investment[$i]['this_index'] =
$dbresult->fields['this_index'];
- $investment[$i]['index_count'] =
$dbresult->fields['index_count'];
- $investment[$i]['date']
= $dbresult->fields['date'];
- if ($cat_id=='property')
- {
- $investment[$i]['entity_name'] =
$dbresult->fields['name'];
- }
- else
- {
- $investment[$i]['entity_name'] =
$dbresult->fields['entity_name'];
- }
-
- $investment[$i]['this_write_off'] =
round(($dbresult->fields['this_index'] * $dbresult->fields['initial_value']),2);
- $i++;
- $dbresult->MoveNext();
- }
-
-//html_print_r($investment);
- return $investment;
- }
-
- function save_investment($values)
- {
-//html_print_r($values);
-
- while (is_array($values['location']) &&
list($input_name,$value) = each($values['location']))
- {
- if($value)
- {
- $cols[] = $input_name;
- $vals[] = $value;
- }
- }
-
- while (is_array($values['extra']) &&
list($input_name,$value) = each($values['extra']))
- {
- if($value)
- {
- $cols[] = $input_name;
- $vals[] = $value;
- }
- }
-
- if($cols)
- {
- $cols = "," . implode(",", $cols);
- $vals = ",'" . implode("','", $vals) . "'";
- }
-
- if($values['street_name'])
- {
- $address[]= $values['street_name'];
- $address[]= $values['street_number'];
- $address = implode(" ", $address);
- }
-
- if(!$address)
- {
- $address = $values['location_name'];
- }
-
-
- $period = $values['period'];
- $type = $values['funding'];
- $initial_value = $values['initial_value'];
- $descr =
$this->db->db_addslashes($values['descr']);
- $date = $values['date'];
- $location_code = $values['location_code'];
- $entity_id = $values['entity_id'];
- $entity_type = $values['entity_type'];
-
-
- $dbresult = $GLOBALS['phpgw']->db->Execute("select
max(invest_id) as max_invest_id from fm_investment Where entity_id=
'$entity_id'");
-
- $next_invest_id = $dbresult->fields['max_invest_id']+1;
-
- $GLOBALS['phpgw']->db->begintrans();
-
- $GLOBALS['phpgw']->db->Execute("INSERT into
fm_investment (entity_id, invest_id,entity_type,location_code,writeoff_year,
descr $cols) "
- . " values ('$entity_id',
'$next_invest_id','$entity_type','$location_code','$period','$descr' $vals )");
-
- $GLOBALS['phpgw']->db->Execute("INSERT into
fm_investment_value (entity_id, invest_id, index_count, this_index,
current_index, value,initial_value, date) "
- . " values ('$entity_id', '$next_invest_id','1', '0',
'1','$initial_value','$initial_value','$date')");
-
-
- if($GLOBALS['phpgw']->db->committrans())
- {
- $receipt['message'][]=array('msg' =>
lang('Investment added !'));
- $receipt['message'][]=array('msg' =>
lang('Entity ID'). ' ' . $entity_id);
- $receipt['message'][]=array('msg' =>
lang('Investment ID:'). ' ' . $next_invest_id);
- }
- return $receipt;
- }
-
- function update_investment($values)
- {
- if (isSet($values) AND is_array($values))
- {
- $GLOBALS['phpgw']->db->begintrans();
- foreach($values as $entry)
- {
- $dbresult =
$GLOBALS['phpgw']->db->Execute("select max(index_count) as max_index_count from
fm_investment_value Where entity_id='" .$entry['entity_id'] . "' and
invest_id=" .$entry['invest_id']);
-
- $next_index_count =
$dbresult->fields['max_index_count']+1;
-
- $GLOBALS['phpgw']->db->Execute("UPDATE
fm_investment_value set current_index = Null"
- . " WHERE entity_id='" .
$entry['entity_id'] . "' and invest_id=" . $entry['invest_id']);
-
- $insert= array(
- $entry['entity_id'],
- $entry['invest_id'],
- $next_index_count,
- $entry['new_index'],
- $entry['new_value'],
- $entry['initial_value'],
- $entry['date'],
- 1
- );
-
- $insert =
$this->bocommon->validate_db_insert($insert);
-
-
- $GLOBALS['phpgw']->db->Execute("INSERT
into fm_investment_value (entity_id, invest_id, index_count, this_index,
value,initial_value, date,current_index) "
- . " values ($insert)");
- }
- $GLOBALS['phpgw']->db->committrans();
- }
- }
-
- function read_single($entity_id,$investment_id,$start,$allrows)
- {
- if (!$start)
- {
- $start=0;
- }
-
-
- $sql = "SELECT index_count,
this_index,current_index,value, initial_value, date "
- . " FROM fm_investment_value Where entity_id=
'$entity_id' and invest_id= '$investment_id' order by index_count";
-
- $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
- $this->total_records = $dbresult2->_numOfRows;
-
- $maxmatchs = 15;
-
- if(!$allrows)
- {
- $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
-
- }
- else
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
- }
-
- $i=0;
- while (!$dbresult->EOF)
- {
- $investment[$i]['descr']
= $dbresult->fields['descr'];
- $investment[$i]['initial_value'] =
$dbresult->fields['initial_value'];
- $investment[$i]['value']
= $dbresult->fields['value'];
- $investment[$i]['this_index'] =
$dbresult->fields['this_index'];
- $investment[$i]['current_index'] =
$dbresult->fields['current_index'];
- $investment[$i]['index_count'] =
$dbresult->fields['index_count'];
- $investment[$i]['date']
= $dbresult->fields['date'];
- $investment[$i]['this_write_off'] =
round(($dbresult->fields['this_index'] * $dbresult->fields['initial_value']),2);
- $i++;
- $dbresult->MoveNext();
- }
-
- return $investment;
- }
-
-
- function write_off_period_list()
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
writeoff_year FROM fm_investment GROUP BY writeoff_year ");
-
- while (!$dbresult->EOF)
- {
- $period_list[] = Array(
- 'period' =>
$dbresult->fields['writeoff_year']
- );
- $dbresult->MoveNext();
- }
-
- return $period_list;
-
- }
-
- function delete($entity_id,$invest_id,$index_count)
- {
- $GLOBALS['phpgw']->db->begintrans();
- if ($index_count==1)
- {
- $GLOBALS['phpgw']->db->Execute("UPDATE
fm_investment_value set current_index = '0', this_index=Null,
value=Null,initial_value=Null,date=Null where entity_id='$entity_id' and
invest_id= '$invest_id' and index_count= '1'");
- }
- else
- {
- $GLOBALS['phpgw']->db->Execute("DELETE from
fm_investment_value where entity_id='$entity_id' and invest_id= '$invest_id'
and index_count= '$index_count'");
-
- $new_current= $index_count -1;
-
- $GLOBALS['phpgw']->db->Execute("UPDATE
fm_investment_value set current_index = '1' where entity_id='$entity_id' and
invest_id= '$invest_id' and index_count= '$new_current'");
- }
-
- // $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_investment_value WHERE entity_id= '$entity_id' and invest_id='$invest_id'
and index_count='$index_count'");
- $GLOBALS['phpgw']->db->committrans();
- }
- }
-?>
+<?php
+
/**************************************************************************\
+ * phpGroupWare - property
*
+ * http://www.phpgroupware.org
*
+ *
*
+ * Facilities Management
*
+ * Written by Sigurd Nes [sigurdne at online.no]
*
+ *
------------------------------------------------------------------------ *
+ * Copyright 2000 - 2003 Free Software Foundation, Inc
*
+ * This program is part of the GNU project, see http://www.gnu.org/
*
+ *
------------------------------------------------------------------------ *
+ * 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.
*
+
\**************************************************************************/
+
+ class property_soinvestment
+ {
+
+ function property_soinvestment()
+ {
+ $this->currentapp = 'property';
//$GLOBALS['phpgw_info']['flags']['currentapp'];
+ $this->db = $GLOBALS['phpgw']->db;
+ $this->db2 = $this->db;
+ $this->account = $GLOBALS['phpgw_data']['user']['id'];
+ $this->bocommon =
CreateObject($this->currentapp.'_bocommon');
+
+ $this->join = $this->bocommon->join;
+ }
+
+ function get_type_list()
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
entity_type FROM fm_investment GROUP BY entity_type ");
+ while (!$dbresult->EOF)
+ {
+ $type_list[] = Array(
+ 'id' =>
$dbresult->fields['entity_type'],
+ 'num' =>
lang($dbresult->fields['entity_type'])
+ );
+ $dbresult->MoveNext();
+ }
+ return $type_list;
+ }
+
+
+ function read($data)
+ {
+ if(is_array($data))
+ {
+ if ($data['start'])
+ {
+ $start=$data['start'];
+ }
+ else
+ {
+ $start=0;
+ }
+ $filter =
(isset($data['filter'])?$data['filter']:'');
+ $query =
(isset($data['query'])?$data['query']:'');
+ $sort =
(isset($data['sort'])?$data['sort']:'DESC');
+ $order =
(isset($data['order'])?$data['order']:'');
+ $cat_id =
(isset($data['cat_id'])?$data['cat_id']:'');
+ $part_of_town_id =
(isset($data['part_of_town_id'])?$data['part_of_town_id']:'');
+ $allrows =
(isset($data['allrows'])?$data['allrows']:'');
+
+ }
+ if (!$cat_id)
+ {
+ return;
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+ }
+ else
+ {
+ if ($cat_id=='property')
+ {
+ $ordermethod = ' order by
fm_part_of_town.name ,fm_location1.loc1 DESC';
+ }
+ else
+ {
+ $ordermethod = ' order by
fm_investment.entity_id DESC';
+ }
+ }
+
+ if ($part_of_town_id)
+ {
+ $filtermethod = "and
fm_part_of_town.part_of_town_id ='$part_of_town_id'";
+ }
+
+ if ($filter=='investment')
+ {
+ $filtermethod .= "and initial_value > 0";
+ }
+ if ($filter=='funding')
+ {
+ $filtermethod .= "and initial_value < 0";
+ }
+
+ if ($cat_id=='property')
+ {
+ $sql = "SELECT fm_investment.entity_id as
entity_id, fm_investment.descr as descr,
fm_investment_value.invest_id,initial_value, fm_location1.loc1_name as name,
fm_part_of_town.district_id, fm_part_of_town.name as part_of_town,"
+ . " fm_investment_value.value,
fm_investment_value.date, fm_investment_value.this_index, "
+ . " fm_investment_value.index_count"
+ . " FROM (((fm_investment $this->join
fm_investment_value ON ( fm_investment.entity_id =
fm_investment_value.entity_id) AND "
+ . " (fm_investment.invest_id =
fm_investment_value.invest_id )) "
+ . " $this->join fm_location1 ON
(fm_investment.loc1 = fm_location1.loc1)) "
+ . " $this->join fm_part_of_town ON
(fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id)) "
+ . " WHERE ( current_index = '1' or (this_index
= NULL and index_count= '1')) AND entity_type ='$cat_id' $filtermethod ";
+
+ }
+ else
+ {
+ $sql = "SELECT
fm_investment.location_code,fm_investment.entity_id, fm_investment.descr as
descr, fm_investment_value.invest_id,initial_value,
fm_part_of_town.district_id, fm_part_of_town.name as part_of_town,"
+ . " fm_investment_value.value,
fm_investment_value.date,
fm_investment_value.this_index,fm_entity_category.name as entity_name, "
+ . " fm_investment_value.index_count "
+ . " FROM ((((fm_investment $this->join "
+ . " fm_entity_category ON
(fm_investment.p_entity_id = fm_entity_category.entity_id AND
fm_investment.p_cat_id = fm_entity_category.id)) $this->join "
+ . " fm_investment_value ON
(fm_investment_value.entity_id = fm_investment.entity_id) AND "
+ . " (fm_investment_value.invest_id =
fm_investment.invest_id)) "
+ . " $this->join fm_location1 ON
(fm_investment.loc1 = fm_location1.loc1)) "
+ . " $this->join fm_part_of_town ON
(fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id)) "
+ . " WHERE ( current_index = '1' or (this_index
= NULL and index_count= '1')) AND entity_type ='$cat_id' $filtermethod ";
+ }
+ if($sql)
+ {
+ $dbresult2 =
$GLOBALS['phpgw']->db->Execute($sql);
+ $this->total_records = $dbresult2->_numOfRows;
+
+
+ $maxmatchs = 15;
+
+ if(!$allrows)
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+
+ }
+ else
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->Execute($sql . $ordermethod);
+ }
+
+ }
+
+
+ $i=0;
+ while (!$dbresult->EOF)
+ {
+ $investment[$i]['counter']
= $i;
+ $investment[$i]['location_code'] =
$dbresult->fields['location_code'];
+ $investment[$i]['entity_id'] =
$dbresult->fields['entity_id'];
+ $investment[$i]['investment_id'] =
$dbresult->fields['invest_id'];
+ $investment[$i]['district_id'] =
$dbresult->fields['district_id'];
+ $investment[$i]['part_of_town'] =
$dbresult->fields['part_of_town'];
+ $investment[$i]['descr']
= $dbresult->fields['descr'];
+ $investment[$i]['initial_value'] =
$dbresult->fields['initial_value'];
+ $investment[$i]['value']
= $dbresult->fields['value'];
+ $investment[$i]['this_index'] =
$dbresult->fields['this_index'];
+ $investment[$i]['index_count'] =
$dbresult->fields['index_count'];
+ $investment[$i]['date']
= $dbresult->fields['date'];
+ if ($cat_id=='property')
+ {
+ $investment[$i]['entity_name'] =
$dbresult->fields['name'];
+ }
+ else
+ {
+ $investment[$i]['entity_name'] =
$dbresult->fields['entity_name'];
+ }
+
+ $investment[$i]['this_write_off'] =
round(($dbresult->fields['this_index'] * $dbresult->fields['initial_value']),2);
+ $i++;
+ $dbresult->MoveNext();
+ }
+
+//html_print_r($investment);
+ return $investment;
+ }
+
+ function save_investment($values)
+ {
+//html_print_r($values);
+
+ while (is_array($values['location']) &&
list($input_name,$value) = each($values['location']))
+ {
+ if($value)
+ {
+ $cols[] = $input_name;
+ $vals[] = $value;
+ }
+ }
+
+ while (is_array($values['extra']) &&
list($input_name,$value) = each($values['extra']))
+ {
+ if($value)
+ {
+ $cols[] = $input_name;
+ $vals[] = $value;
+ }
+ }
+
+ if($cols)
+ {
+ $cols = "," . implode(",", $cols);
+ $vals = ",'" . implode("','", $vals) . "'";
+ }
+
+ if($values['street_name'])
+ {
+ $address[]= $values['street_name'];
+ $address[]= $values['street_number'];
+ $address = implode(" ", $address);
+ }
+
+ if(!$address)
+ {
+ $address = $values['location_name'];
+ }
+
+
+ $period = $values['period'];
+ $type = $values['funding'];
+ $initial_value = $values['initial_value'];
+ $descr =
$this->db->db_addslashes($values['descr']);
+ $date = $values['date'];
+ $location_code = $values['location_code'];
+ $entity_id = $values['entity_id'];
+ $entity_type = $values['entity_type'];
+
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute("select
max(invest_id) as max_invest_id from fm_investment Where entity_id=
'$entity_id'");
+
+ $next_invest_id = $dbresult->fields['max_invest_id']+1;
+
+ $GLOBALS['phpgw']->db->begintrans();
+
+ $GLOBALS['phpgw']->db->Execute("INSERT into
fm_investment (entity_id, invest_id,entity_type,location_code,writeoff_year,
descr $cols) "
+ . " values ('$entity_id',
'$next_invest_id','$entity_type','$location_code','$period','$descr' $vals )");
+
+ $GLOBALS['phpgw']->db->Execute("INSERT into
fm_investment_value (entity_id, invest_id, index_count, this_index,
current_index, value,initial_value, date) "
+ . " values ('$entity_id', '$next_invest_id','1', '0',
'1','$initial_value','$initial_value','$date')");
+
+
+ if($GLOBALS['phpgw']->db->committrans())
+ {
+ $receipt['message'][]=array('msg' =>
lang('Investment added !'));
+ $receipt['message'][]=array('msg' =>
lang('Entity ID'). ' ' . $entity_id);
+ $receipt['message'][]=array('msg' =>
lang('Investment ID:'). ' ' . $next_invest_id);
+ }
+ return $receipt;
+ }
+
+ function update_investment($values)
+ {
+ if (isSet($values) AND is_array($values))
+ {
+ $GLOBALS['phpgw']->db->begintrans();
+ foreach($values as $entry)
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("select max(index_count) as max_index_count from
fm_investment_value Where entity_id='" .$entry['entity_id'] . "' and
invest_id=" .$entry['invest_id']);
+
+ $next_index_count =
$dbresult->fields['max_index_count']+1;
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE
fm_investment_value set current_index = Null"
+ . " WHERE entity_id='" .
$entry['entity_id'] . "' and invest_id=" . $entry['invest_id']);
+
+ $insert= array(
+ $entry['entity_id'],
+ $entry['invest_id'],
+ $next_index_count,
+ $entry['new_index'],
+ $entry['new_value'],
+ $entry['initial_value'],
+ $entry['date'],
+ 1
+ );
+
+ $insert =
$this->bocommon->validate_db_insert($insert);
+
+
+ $GLOBALS['phpgw']->db->Execute("INSERT
into fm_investment_value (entity_id, invest_id, index_count, this_index,
value,initial_value, date,current_index) "
+ . " values ($insert)");
+ }
+ $GLOBALS['phpgw']->db->committrans();
+ }
+ }
+
+ function read_single($entity_id,$investment_id,$start,$allrows)
+ {
+ if (!$start)
+ {
+ $start=0;
+ }
+
+
+ $sql = "SELECT index_count,
this_index,current_index,value, initial_value, date "
+ . " FROM fm_investment_value Where entity_id=
'$entity_id' and invest_id= '$investment_id' order by index_count";
+
+ $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+ $this->total_records = $dbresult2->_numOfRows;
+
+ $maxmatchs = 15;
+
+ if(!$allrows)
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+
+ }
+ else
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
+ }
+
+ $i=0;
+ while (!$dbresult->EOF)
+ {
+ $investment[$i]['descr']
= $dbresult->fields['descr'];
+ $investment[$i]['initial_value'] =
$dbresult->fields['initial_value'];
+ $investment[$i]['value']
= $dbresult->fields['value'];
+ $investment[$i]['this_index'] =
$dbresult->fields['this_index'];
+ $investment[$i]['current_index'] =
$dbresult->fields['current_index'];
+ $investment[$i]['index_count'] =
$dbresult->fields['index_count'];
+ $investment[$i]['date']
= $dbresult->fields['date'];
+ $investment[$i]['this_write_off'] =
round(($dbresult->fields['this_index'] * $dbresult->fields['initial_value']),2);
+ $i++;
+ $dbresult->MoveNext();
+ }
+
+ return $investment;
+ }
+
+
+ function write_off_period_list()
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
writeoff_year FROM fm_investment GROUP BY writeoff_year ");
+
+ while (!$dbresult->EOF)
+ {
+ $period_list[] = Array(
+ 'period' =>
$dbresult->fields['writeoff_year']
+ );
+ $dbresult->MoveNext();
+ }
+
+ return $period_list;
+
+ }
+
+ function delete($entity_id,$invest_id,$index_count)
+ {
+ $GLOBALS['phpgw']->db->begintrans();
+ if ($index_count==1)
+ {
+ $GLOBALS['phpgw']->db->Execute("UPDATE
fm_investment_value set current_index = '0', this_index=Null,
value=Null,initial_value=Null,date=Null where entity_id='$entity_id' and
invest_id= '$invest_id' and index_count= '1'");
+ }
+ else
+ {
+ $GLOBALS['phpgw']->db->Execute("DELETE from
fm_investment_value where entity_id='$entity_id' and invest_id= '$invest_id'
and index_count= '$index_count'");
+
+ $new_current= $index_count -1;
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE
fm_investment_value set current_index = '1' where entity_id='$entity_id' and
invest_id= '$invest_id' and index_count= '$new_current'");
+ }
+
+ // $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_investment_value WHERE entity_id= '$entity_id' and invest_id='$invest_id'
and index_count='$index_count'");
+ $GLOBALS['phpgw']->db->committrans();
+ }
+ }
+?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/class.soinvestment.php, 1.1.1.3,
nomail <=