[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [11568] Calculate fictive periods on continious worko
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [11568] Calculate fictive periods on continious workorders |
Date: |
Thu, 26 Dec 2013 11:39:00 +0000 |
Revision: 11568
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11568
Author: sigurdne
Date: 2013-12-26 11:39:00 +0000 (Thu, 26 Dec 2013)
Log Message:
-----------
Calculate fictive periods on continious workorders
Modified Paths:
--------------
trunk/property/inc/class.soworkorder.inc.php
trunk/property/inc/cron/default/import_oppdatering_av_bestilling_fra_agresso_bkb.php
Added Paths:
-----------
trunk/property/inc/cron/class.cron_parent.inc.php
trunk/property/inc/cron/default/reset_workorder_cached_budget.php
Property Changed:
----------------
trunk/property/inc/cron/default/import_oppdatering_av_bestilling_fra_agresso_bkb.php
Modified: trunk/property/inc/class.soworkorder.inc.php
===================================================================
--- trunk/property/inc/class.soworkorder.inc.php 2013-12-23 12:49:00 UTC
(rev 11567)
+++ trunk/property/inc/class.soworkorder.inc.php 2013-12-26 11:39:00 UTC
(rev 11568)
@@ -1748,12 +1748,17 @@
* @return array Array with budget information.
*/
- function get_budget($order_id)
+ function get_budget($order_id, $fictive_periods = true)
{
+ // Som før: Periodisering der det er definert
+ // Som før: Enkelt posteringer for gjeldende periode
der periodisering ikke er definert
+ // Ny: Fiktiv periodisering over 12 mnd med
startperiode for inneværende mnd for løpende som ikke er periodisert
+
if(!$order_id)
{
return array();
}
+ $continuous = false;
$cached_info = phpgwapi_cache::system_get('property',
"budget_order_{$order_id}");
@@ -1765,47 +1770,131 @@
$closed_period = array();
$active_period = array();
- $sql = "SELECT fm_workorder_budget.budget,
fm_workorder_budget.combined_cost, year, month, active, closed"
+ $sum_year_budget = array();
+ $sum_year_combined_cost = array();
+
+ $sql = "SELECT continuous, fm_workorder.start_date ,
fm_workorder_budget.budget, fm_workorder_budget.combined_cost, year, month,
active, closed"
. " FROM fm_workorder {$this->join} fm_workorder_status
ON fm_workorder.status = fm_workorder_status.id"
. " {$this->join} fm_workorder_budget ON
fm_workorder.id = fm_workorder_budget.order_id WHERE order_id = '{$order_id}'"
. " ORDER BY year, month";
$this->db->query($sql,__LINE__,__FILE__);
- $order_budget = array();
+ $_order_budget = array();
while ($this->db->next_record())
{
+ $year = (int)$this->db->f('year');
+ $month = (int)$this->db->f('month');
+ $continuous = !!$this->db->f('continuous');
$period = sprintf("%s%02d",
- $this->db->f('year'),
- $this->db->f('month')
+ $year,
+ $month
);
- $order_budget[$period] = array
+ $budget =
(int)$this->db->f('budget');
+ $combined_cost =
(int)$this->db->f('combined_cost');
+ $_order_budget[$period] = array
(
'order_id' =>
$order_id,
- 'budget' =>
(int)$this->db->f('budget'),
- 'combined_cost' =>
(int)$this->db->f('combined_cost'),
- 'year' =>
(int)$this->db->f('year'),
- 'month' =>
(int)$this->db->f('month'),
+ 'start_period' => date('Ym',
$this->db->f('start_date')), //bigint
+ 'budget' =>
$budget,
+ 'combined_cost' =>
$combined_cost,
+ 'year' =>
$year,
+ 'month' =>
$month,
'actual_cost' => 0, //for
now..
'closed_order' =>
(int)$this->db->f('closed'),
'active_period' =>
(int)$this->db->f('active'),
);
- $active_period[$period] =
$this->db->f('active');
+ $active_period[$period] =
$this->db->f('active');
+
+ if($continuous)
+ {
+ $sum_year_budget[$year]
+= $budget;
+ $sum_year_combined_cost[$year] +=
$combined_cost;
+ }
}
-//_debug_array($order_budget);die();
- foreach ($order_budget as $period => $_budget)
+
+ /**
+ * Fiktiv periodisering over 12 mnd med startperiode for
inneværende mnd for løpende som ikke er periodisert
+ * Hopper over historiske år.
+ * Start-periode blir måned for første betaling dersom
den er før inneværende måned
+ * ellers: Start-periode blir måned for start-dato for
bestilling dersom den ligger frem i tid
+ * ellers: Dersom start-dato for bestilling er passert -
blir start-periode inneværende måned.
+ **/
+
+ $order_budget = array();
+ if($continuous && $fictive_periods)
{
- $this->db->query("SELECT closed FROM
fm_workorder"
- . " {$this->join} fm_project ON
fm_workorder.project_id = fm_project.id"
- . " {$this->join} fm_project_budget ON
fm_project.id = fm_project_budget.project_id"
- . " WHERE fm_workorder.id =
'{$_budget['order_id']}'"
- . " AND fm_project_budget.year =
{$_budget['year']}"
- . " AND fm_project_budget.month =
{$_budget['month']}" ,__LINE__,__FILE__);
+ $sql = "SELECT periode"
+ . " FROM fm_workorder {$this->join}
fm_orders_paid_or_pending_view ON fm_workorder.id =
fm_orders_paid_or_pending_view.order_id"
+ . " WHERE order_id = '{$order_id}' AND periode
> " . date('Y') . '00'
+ . " ORDER BY periode ASC";
+
+ $this->db->query($sql,__LINE__,__FILE__);
$this->db->next_record();
- $closed_period[$period] =
(int)$this->db->f('closed');
+ $current_paid_period =
(int)$this->db->f('periode');
+
+ foreach ($_order_budget as $_period => $_budget)
+ {
+ if($_period == "{$_budget['year']}00"
&& $_budget['year'] == date('Y'))
+ {
+ $active_period[$_period] =
false;
+
+ if($current_paid_period <
(int)date('Ym'))
+ {
+ $_current_month =
(int)substr( $current_paid_period, -2 );
+ }
+ else
if((int)$_budget['start_period'] > (int)date('Ym'))
+ {
+ $_current_month =
(int)substr( $_budget['start_period'], -2 );
+ }
+ else
+ {
+ $_current_month =
date('n'); // Numeric representation of a month, without leading zeros 1
through 12
+ }
+
+ $distribution_key = 1/(13 -
$_current_month);
+
+ for ($i = $_current_month;
$i<13; $i++)
+ {
+ $period =
sprintf("%s%02d",
+
$_budget['year'],
+ $i
+ );
+
+ $active_period[$period]
= true;
+ $order_budget[$period]
= $_budget;
+
$order_budget[$period]['budget'] =
$sum_year_budget[$_budget['year']] * $distribution_key;
+
$order_budget[$period]['combined_cost'] =
$sum_year_combined_cost[$_budget['year']] * $distribution_key;
+
$order_budget[$period]['active_period'] = $_budget['active_period'];
+
$order_budget[$period]['month'] = $i;
+ $closed_period[$period]
= (int)$period < date('Ym');
+ }
+ }
+ else
+ {
+ $order_budget[$_period] =
$_budget;
+ }
+ unset($_budget);
+ }
}
+ else
+ {
+ $order_budget = $_order_budget;
+ foreach ($order_budget as $period => $_budget)
+ {
+ $this->db->query("SELECT closed FROM
fm_workorder"
+ . " {$this->join} fm_project ON
fm_workorder.project_id = fm_project.id"
+ . " {$this->join} fm_project_budget ON
fm_project.id = fm_project_budget.project_id"
+ . " WHERE fm_workorder.id =
'{$_budget['order_id']}'"
+ . " AND fm_project_budget.year =
{$_budget['year']}"
+ . " AND fm_project_budget.month =
{$_budget['month']}" ,__LINE__,__FILE__);
+ $this->db->next_record();
+ $closed_period[$period] =
(int)$this->db->f('closed');
+ }
+ }
+
$sql = "SELECT order_id, periode, amount AS actual_cost"
. " FROM fm_workorder {$this->join}
fm_orders_paid_or_pending_view ON fm_workorder.id =
fm_orders_paid_or_pending_view.order_id"
. " WHERE order_id = '{$order_id}' ORDER BY periode
ASC";
@@ -2327,7 +2416,7 @@
$incoming_budget = $budget;
$acc_partial = 0;
- $orig_budget = $this->get_budget($order_id);
+ $orig_budget =
$this->get_budget($order_id,false);
//_debug_array($orig_budget);
$hit = false;
foreach ($orig_budget as $entry)
Added: trunk/property/inc/cron/class.cron_parent.inc.php
===================================================================
--- trunk/property/inc/cron/class.cron_parent.inc.php
(rev 0)
+++ trunk/property/inc/cron/class.cron_parent.inc.php 2013-12-26 11:39:00 UTC
(rev 11568)
@@ -0,0 +1,157 @@
+<?php
+ /**
+ * phpGroupWare - property: a Facilities Management System.
+ *
+ * @author Sigurd Nes <address@hidden>
+ * @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software
Foundation, Inc. http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare 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.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/bbb_/ekstern/
+ * @package property
+ * @subpackage import
+ * @version $Id$
+ */
+
+ /**
+ * Filteret importerer rapporter fra Agresso som grunnlag for
oppdatering av øknomi og status på meldings_bestilling.
+ * @package property
+ */
+
+
+ abstract class property_cron_parent
+ {
+ protected $function_name;
+ protected $debug = true;
+ protected $receipt = array();
+ protected $sub_location = 'sub_location';
+ protected $function_msg = 'function_msg';
+
+ function __construct()
+ {
+ $this->db = & $GLOBALS['phpgw']->db;
+ }
+
+ function pre_run($data = array())
+ {
+ if(isset($data['enabled']) && $data['enabled']==1)
+ {
+ $confirm = true;
+ $cron = true;
+ }
+ else
+ {
+ $confirm = phpgw::get_var('confirm',
'bool', 'POST');
+ $execute = phpgw::get_var('execute',
'bool', 'GET');
+ }
+
+ if( isset($data['debug']) && $data['debug'] )
+ {
+ $this->debug = true;
+ }
+ else
+ {
+ $this->debug = phpgw::get_var('debug',
'bool');
+ }
+
+ if ($confirm)
+ {
+ $this->execute();
+ $this->cron_log($cron);
+ // initiated from ui
+ if(!$cron)
+ {
+ $this->confirm($execute=false);
+ }
+ }
+ else
+ {
+ $this->confirm($execute=false);
+ }
+ }
+
+ function confirm($execute='')
+ {
+ $link_data = array
+ (
+ 'menuaction' =>
'property.custom_functions.index',
+ 'function' => $this->function_name,
+ 'execute' => $execute,
+ 'debug' => $this->debug
+ );
+
+
+ if(!$execute)
+ {
+ $lang_confirm_msg = lang('do you want to
perform this action');
+ }
+
+ $lang_yes = lang('yes');
+
+
$GLOBALS['phpgw']->xslttpl->add_file(array('confirm_custom'));
+
+ $msgbox_data =
$GLOBALS['phpgw']->common->msgbox_data($this->receipt);
+
+ $data = array
+ (
+ 'msgbox_data' =>
$GLOBALS['phpgw']->common->msgbox($msgbox_data),
+ 'done_action' =>
$GLOBALS['phpgw']->link('/index.php',
array('menuaction'=>'property.uiasync.index')),
+ 'run_action' =>
$GLOBALS['phpgw']->link('/index.php',$link_data),
+ 'message' =>
$this->receipt['message'],
+ 'lang_confirm_msg' =>
$lang_confirm_msg,
+ 'lang_yes' =>
$lang_yes,
+ 'lang_yes_statustext' => $this->function_msg,
+ 'lang_no_statustext' => 'tilbake',
+ 'lang_no' =>
lang('no'),
+ 'lang_done' =>
'Avbryt',
+ 'lang_done_statustext' => 'tilbake'
+ );
+
+ $GLOBALS['phpgw_info']['flags']['app_header'] =
lang('property') . ' - ' . $this->sub_location . ': ' . $this->function_msg;
+
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('confirm' => $data));
+ $GLOBALS['phpgw']->xslttpl->pp();
+ }
+
+
+ abstract public function execute();
+
+
+ private function cron_log($cron)
+ {
+
+ if(!$this->receipt)
+ {
+ return;
+ }
+
+ $msgbox_data =
$GLOBALS['phpgw']->common->msgbox_data($this->receipt);
+
+ $insert_values= array
+ (
+ $cron,
+ date($this->db->datetime_format()),
+ $this->function_name,
+
$this->db->db_addslashes(implode(',',(array_keys($msgbox_data))))
+ );
+
+ $insert_values =
$this->db->validate_insert($insert_values);
+
+ $sql = "INSERT INTO fm_cron_log
(cron,cron_date,process,message) "
+ . "VALUES ($insert_values)";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ }
Property changes on: trunk/property/inc/cron/class.cron_parent.inc.php
___________________________________________________________________
Added: svn:keywords
+ Revision Author Id
Modified:
trunk/property/inc/cron/default/import_oppdatering_av_bestilling_fra_agresso_bkb.php
===================================================================
---
trunk/property/inc/cron/default/import_oppdatering_av_bestilling_fra_agresso_bkb.php
2013-12-23 12:49:00 UTC (rev 11567)
+++
trunk/property/inc/cron/default/import_oppdatering_av_bestilling_fra_agresso_bkb.php
2013-12-26 11:39:00 UTC (rev 11568)
@@ -24,7 +24,7 @@
* @internal Development of this application was funded by
http://www.bergen.kommune.no/bbb_/ekstern/
* @package property
* @subpackage import
- * @version $Id: import_oppdatering_av_bestilling_fra_agresso_bkb.php
11456 2013-11-13 17:34:50Z sigurdne $
+ * @version $Id$
*/
/**
Property changes on:
trunk/property/inc/cron/default/import_oppdatering_av_bestilling_fra_agresso_bkb.php
___________________________________________________________________
Added: svn:keywords
+ Revision Author Id
Added: trunk/property/inc/cron/default/reset_workorder_cached_budget.php
===================================================================
--- trunk/property/inc/cron/default/reset_workorder_cached_budget.php
(rev 0)
+++ trunk/property/inc/cron/default/reset_workorder_cached_budget.php
2013-12-26 11:39:00 UTC (rev 11568)
@@ -0,0 +1,81 @@
+<?php
+ /**
+ * phpGroupWare - property: a Facilities Management System.
+ *
+ * @author Sigurd Nes <address@hidden>
+ * @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software
Foundation, Inc. http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare 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.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/bbb_/ekstern/
+ * @package property
+ * @subpackage import
+ * @version $Id$
+ */
+
+ /**
+ * Filteret importerer rapporter fra Agresso som grunnlag for
oppdatering av øknomi og status på meldings_bestilling.
+ * @package property
+ */
+
+ include_class('property', 'cron_parent', 'inc/cron/');
+
+ class reset_workorder_cached_budget extends property_cron_parent
+ {
+
+ function __construct()
+ {
+ parent::__construct();
+
+ $this->function_name = 'reset_workorder_cached_budget';
+ $this->sub_location = lang('workorder');
+ $this->function_msg = 'reset workorder cached
budget';
+
+ $this->join = &
$this->db->join;
+ $this->left_join = &
$this->db->left_join;
+ $this->like = &
$this->db->like;
+ }
+
+
+ public function execute()
+ {
+ $orders = array();
+ $sql = "SELECT DISTINCT fm_workorder.id as order_id"
+ . " FROM fm_workorder "
+ . " {$this->join} fm_workorder_budget ON
fm_workorder.id = fm_workorder_budget.order_id"
+ . " WHERE continuous = 1 AND fm_workorder_budget.year >
" . (date('Y') -1)
+ . " ORDER BY fm_workorder.id";
+
+ $this->db->query($sql,__LINE__,__FILE__);
+ $_order_budget = array();
+ while ($this->db->next_record())
+ {
+ $orders[] = $this->db->f('order_id');
+ }
+
+ foreach ($orders as $order_id)
+ {
+ phpgwapi_cache::system_clear('property',
"budget_order_{$order_id}");
+
execMethod('property.soworkorder.get_budget',$order_id);
+ }
+
+ $count_orders = count($orders);
+
+ $this->receipt['message'][] = array('msg' =>
"Rekalkulert budsjett for {$count_orders} løpende bestillinger");
+
+ }
+ }
Property changes on:
trunk/property/inc/cron/default/reset_workorder_cached_budget.php
___________________________________________________________________
Added: svn:keywords
+ Revision Author Id
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [11568] Calculate fictive periods on continious workorders,
Sigurd Nes <=