fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11743] property: more on percent of used funding


From: Sigurd Nes
Subject: [Fmsystem-commits] [11743] property: more on percent of used funding
Date: Mon, 24 Feb 2014 13:22:37 +0000

Revision: 11743
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11743
Author:   sigurdne
Date:     2014-02-24 13:22:36 +0000 (Mon, 24 Feb 2014)
Log Message:
-----------
property: more on percent of used funding

Modified Paths:
--------------
    trunk/property/inc/class.boworkorder.inc.php
    trunk/property/inc/class.soXport.inc.php
    trunk/property/inc/class.soworkorder.inc.php

Modified: trunk/property/inc/class.boworkorder.inc.php
===================================================================
--- trunk/property/inc/class.boworkorder.inc.php        2014-02-23 19:43:30 UTC 
(rev 11742)
+++ trunk/property/inc/class.boworkorder.inc.php        2014-02-24 13:22:36 UTC 
(rev 11743)
@@ -855,4 +855,72 @@
                {
                        $this->so->recalculate();
                }
+
+               /**
+                * Check the consumption  on an order - and notify the 
coordinator
+                * @param integer $order_id
+                */
+               function notify_coordinator_on_consumption($order_id)
+               {
+                       $notify_coordinator = true;
+                       if(!$notify_coordinator)
+                       {
+                               return false;
+                       }
+                       $toarray = array();
+                       $workorder      = $this->so->read_single($order_id);
+                       $project        = 
ExecMethod('property.boproject.read_single_mini',$workorder['project_id']);
+                       $coordinator = $project['coordinator'];
+                       $prefs_coordinator = 
$this->bocommon->create_preferences('property',$coordinator);
+                       if(isset($prefs_coordinator['email']) && 
$prefs_coordinator['email'])
+                       {
+                               $toarray[] = $prefs_coordinator['email'];
+                       }
+
+                       if ($toarray)
+                       {
+                               $percent = 
$this->so->get_order_budget_percent($order_id);
+                               if($percent < 90)
+                               {
+                                       return false;
+                               }
+
+                               
if(isset($GLOBALS['phpgw_info']['user']['preferences']['property']['email']) && 
$GLOBALS['phpgw_info']['user']['preferences']['property']['email'])
+                               {
+                                       
$from_name=$GLOBALS['phpgw_info']['user']['fullname'];
+                                       
$from_email=$GLOBALS['phpgw_info']['user']['preferences']['property']['email'];
+                               }
+                               else
+                               {
+                                       $from_name       = 'noreply';
+                                       $from_email      = 
"{$from_name}<address@hidden>";
+                               }
+
+                               $subject         = "Bestilling # {$order_id} 
har disponert {$percent} prosent av budsjsett";
+
+                               $to = implode(';',$toarray);
+                               $body = '<a href ="' . 
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'property.uiworkorder.edit','id'=> $order_id),false,true).'">' . 
lang('workorder %1 has been edited',$order_id) .'</a>' . "\n";
+
+                               if (!is_object($GLOBALS['phpgw']->send))
+                               {
+                                       $GLOBALS['phpgw']->send = 
CreateObject('phpgwapi.send');
+                               }
+
+                               try
+                               {
+                                       $ok = 
$GLOBALS['phpgw']->send->msg('email',$to,$subject,$body, false,false,false, 
$from_email, $from_name, 'html');
+                               }
+                               catch (phpmailerException $e)
+                               {
+                                       phpgwapi_cache::message_set( 
$e->getMessage(), 'error' );
+                               }
+
+                               if($ok)
+                               {
+                                       $historylog     = 
CreateObject('property.historylog','workorder');
+                                       $historylog->add('ON', $order_id, 
lang('%1 is notified',$to));
+                                       return true;
+                               }
+                       }
+               }
        }

Modified: trunk/property/inc/class.soXport.inc.php
===================================================================
--- trunk/property/inc/class.soXport.inc.php    2014-02-23 19:43:30 UTC (rev 
11742)
+++ trunk/property/inc/class.soXport.inc.php    2014-02-24 13:22:36 UTC (rev 
11743)
@@ -769,6 +769,9 @@
                                        if(!$this->debug)
                                        {
                                                
$this->correct_actual_cost($line['order_id'],$amount, $actual_cost_field, 
$operator);
+
+                                               
execMethod('property.boworkorder.notify_coordinator_on_consumption', 
$line['order_id']);
+
                                        }
                                }
                        }
@@ -916,6 +919,8 @@
                        {
                                $sql="UPDATE {$table} SET 
{$actual_cost_field}={$actual_cost_field} {$operator} {$amount} {$update_paid} 
WHERE id='{$order_id}'";
                                $this->db->query($sql,__LINE__,__FILE__);
+
+                               
execMethod('property.boworkorder.notify_coordinator_on_consumption', $order_id);
                        }
                }
 

Modified: trunk/property/inc/class.soworkorder.inc.php
===================================================================
--- trunk/property/inc/class.soworkorder.inc.php        2014-02-23 19:43:30 UTC 
(rev 11742)
+++ trunk/property/inc/class.soworkorder.inc.php        2014-02-24 13:22:36 UTC 
(rev 11743)
@@ -1776,8 +1776,8 @@
                                        $_sub_actual_cost += 
$entry['actual_cost'];
                                        $_sub_oblications += 
$entry['sum_oblications'];
                                }
-                               $percent = round((($_sub_actual_cost + 
$_sub_oblications)/$_sub_budget)*100, 1);
-
+                               $budget = $_sub_budget == 0 ? 1 : $_sub_budget; 
// avoid zero-division
+                               $percent = round((($_sub_actual_cost + 
$_sub_oblications)/$budget)*100, 1);
                        }
 
                        return $percent;




reply via email to

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