コード例 #1
0
 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" . " 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");
 }
コード例 #2
0
 /**
  * Add budget to project if missing.
  * @param integer $project_id
  * @param integer $year
  * @param boolean $force
  */
 public function check_and_update_project_budget($project_id, $year, $force = false)
 {
     $update_project_budget_from_order = isset($this->config->config_data['update_project_budget_from_order']) && $this->config->config_data['update_project_budget_from_order'] ? $this->config->config_data['update_project_budget_from_order'] : false;
     if (!$force && !$update_project_budget_from_order) {
         return;
     }
     $project_id = (int) $project_id;
     $year = $year ? (int) $year : date('Y');
     $current_year = date('Y');
     $activate = false;
     if ($year == $current_year) {
         $activate = true;
     }
     $ids = array();
     $this->db->query("SELECT id FROM fm_workorder WHERE project_id = {$project_id}", __LINE__, __FILE__);
     while ($this->db->next_record()) {
         $id = $this->db->f('id');
         $ids[] = $id;
         phpgwapi_cache::system_clear('property', "budget_order_{$id}");
     }
     if (!$ids) {
         return false;
     }
     $this->db->query("SELECT sum(budget) AS budget FROM fm_workorder_budget WHERE year = {$year} AND order_id IN (" . implode(',', $ids) . ')', __LINE__, __FILE__);
     $this->db->next_record();
     $workorder_budget = $this->db->f('budget');
     $this->db->query("SELECT sum(budget) AS budget FROM fm_project_budget WHERE project_id = {$project_id} AND year = {$year}", __LINE__, __FILE__);
     $this->db->next_record();
     $project_budget = $this->db->f('budget');
     $update = false;
     if ($project_budget < 0 && $workorder_budget < $project_budget) {
         $update = true;
     } else {
         if ($workorder_budget > $project_budget) {
             $update = true;
         }
     }
     if ($update) {
         $this->db->query("UPDATE fm_project_budget SET active = 0 WHERE project_id = {$project_id} AND year != {$current_year}", __LINE__, __FILE__);
         $this->db->query("SELECT id, periodization_id FROM fm_project WHERE id = {$project_id}", __LINE__, __FILE__);
         if ($this->db->next_record()) {
             $periodization_id = (int) $this->db->f('periodization_id');
             $this->update_budget($project_id, $year, $periodization_id, (int) $workorder_budget, true, 'update', $activate);
         }
     }
 }
コード例 #3
0
 /**
  * Set a message on bottom of home-screen
  *
  * @return void
  */
 function home_screen_message()
 {
     if (!$GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin')) {
         $GLOBALS['phpgw']->redirect_link('/admin/index.php');
     }
     if (phpgw::get_var('msg_title', 'string')) {
         $msg_title = phpgw::get_var('msg_title', 'string');
     } else {
         $msg_title = lang("important message");
     }
     if (phpgw::get_var('message', 'string')) {
         phpgwapi_cache::system_set('phpgwapi', 'phpgw_home_screen_message_title', $msg_title);
         phpgwapi_cache::system_set('phpgwapi', 'phpgw_home_screen_message', phpgw::get_var('message', 'html'));
     }
     if (phpgw::get_var('delete_message', 'bool')) {
         phpgwapi_cache::system_clear('phpgwapi', 'phpgw_home_screen_message_title');
         phpgwapi_cache::system_clear('phpgwapi', 'phpgw_home_screen_message');
     }
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('administration');
     $data = array('value_title' => phpgwapi_cache::system_get('phpgwapi', 'phpgw_home_screen_message_title'), 'value_message' => phpgwapi_cache::system_get('phpgwapi', 'phpgw_home_screen_message'), 'form_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'admin.uiaccounts.home_screen_message')), 'lang_cancel' => lang('cancel'), 'lang_submit' => lang('submit'));
     $GLOBALS['phpgw']->xslttpl->add_file('home_screen_message');
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('home_screen_message' => $data));
 }
コード例 #4
0
 /**
  * Delete an account
  *
  * @param integer $account_id the account to delete
  *
  * @return boolean was the account deleted?
  */
 public function delete($account_id)
 {
     $account_id = (int) $account_id;
     //TODO decide if we should silently allow deletion of non existent accounts
     $acct = $this->get($account_id);
     if (!is_object($acct)) {
         return false;
     }
     $this->db->transaction_begin();
     $deleted = !!$this->db->query("DELETE FROM phpgw_accounts WHERE account_id={$account_id}");
     if ($deleted) {
         // Delete all ACLs
         $GLOBALS['phpgw']->acl->delete_repository('%%', '%%', $account_id);
         if (get_class($acct) == phpgwapi_account::CLASS_TYPE_GROUP) {
             $sql = 'DELETE FROM phpgw_group_map' . " WHERE group_id = {$account_id}";
             $GLOBALS['phpgw']->hooks->process('deletegroup');
         } else {
             $GLOBALS['phpgw']->hooks->process('deleteaccount');
             $sql = 'DELETE FROM phpgw_group_map' . " WHERE account_id = {$account_id}";
         }
         // The cached object is needed for the hooks
         phpgwapi_cache::system_clear('phpgwapi', "account_{$account_id}");
         // delete the group mappings
         if (!!$this->db->query($sql)) {
             $this->db->transaction_commit();
             return true;
         }
     }
     $this->db->transaction_abort();
     return false;
 }
コード例 #5
0
 /**
  * Reassign and alter dimensions accordingly
  * @param int $line_id
  * @param bigint $order_id
  * @return boolean true on success
  */
 public function reassign_order($line_id, $order_id, $voucher_id)
 {
     $voucher_info = $this->get_single_line($line_id);
     if ($this->bo->reassign_order($line_id, $order_id)) {
         phpgwapi_cache::message_set(lang('voucher is updated'), 'message');
         phpgwapi_cache::system_clear('property', "budget_order_{$voucher_info['voucher'][0]['order_id']}");
         // target is cleared in the so-class
         $result = array('status' => 'updated');
     } else {
         $result = array('status' => 'error');
     }
     if (phpgw::get_var('phpgw_return_as') == 'json') {
         if ($receipt = phpgwapi_cache::session_get('phpgwapi', 'phpgw_messages')) {
             phpgwapi_cache::session_clear('phpgwapi', 'phpgw_messages');
             $result['receipt'] = $receipt;
         }
         return $result;
     } else {
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiinvoice2.index', 'voucher_id' => $voucher_id, 'line_id' => $line_id));
     }
 }
コード例 #6
0
 public function correct_actual_cost($order_id, $amount, $actual_cost_field, $operator)
 {
     phpgwapi_cache::system_clear('property', "budget_order_{$order_id}");
     $sql = "SELECT type FROM fm_orders WHERE id='{$order_id}'";
     $this->db->query($sql, __LINE__, __FILE__);
     $this->db->next_record();
     $table = '';
     $update_paid = '';
     switch ($this->db->f('type')) {
         case 'workorder':
             $table = 'fm_workorder';
             if ($operator == "-") {
                 $update_paid = ", paid = 1";
             } else {
                 $update_paid = ", paid = 2";
             }
             break;
         case 's_agreement':
             $table = 'fm_s_agreement';
             $actual_cost_field = 'actual_cost';
             break;
     }
     $amount = $amount / 100;
     if (!$table) {
         $message = 'property_soXport::correct_actual_cost() ERROR: the order id %1 seems to not correspond with any order type';
         $GLOBALS['phpgw']->log->error(array('text' => $message, 'p1' => $order_id, 'p2' => '', 'line' => __LINE__, 'file' => __FILE__));
         echo $message . "\n";
     } else {
         $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);
     }
 }
コード例 #7
0
 /**
  * Transfer budget and cost from one year to the next
  *
  * */
 public function transfer_budget($id, $budget, $year)
 {
     if ($this->db->get_transaction()) {
         $this->global_lock = true;
     } else {
         $this->db->transaction_begin();
     }
     $id = (int) $id;
     $year = (int) $year;
     $latest_year = (int) $budget['latest_year'];
     $sql = "SELECT periodization_id, project_type_id, continuous" . " FROM fm_workorder" . " {$this->join} fm_project ON fm_workorder.project_id = fm_project.id" . " WHERE fm_workorder.id = {$id}";
     $this->db->query($sql, __LINE__, __FILE__);
     $this->db->next_record();
     $periodization_id = $this->db->f('periodization_id');
     $project_type_id = $this->db->f('project_type_id');
     $continuous = $this->db->f('continuous');
     //~ * Løpende bestillinger settes til null via masseoppdatering, evt at nytt budsjett tastes inn i masseoppdatering (siste er ønskelig).
     //~ * For Driftsbestillinger settes Betalt til null, Budsjett settes til restforpliktelse (budsjett tidligere trekkes ned med restforpliktelse)
     //~ * For Investeringsbestillinger skal disse ikke se på år
     phpgwapi_cache::system_clear('property', "budget_order_{$id}");
     if ($continuous) {
         $this->db->query("UPDATE fm_workorder_budget SET active = 0 WHERE order_id = {$id} AND year = {$latest_year}", __LINE__, __FILE__);
         if ($budget['budget_amount']) {
             $this->_update_order_budget($id, $year, $periodization_id, (int) $budget['budget_amount'], (int) $budget['budget_amount'], (int) $budget['budget_amount'], $action = 'update', true);
         }
     } else {
         if ($project_type_id == 1) {
             /*
              if(abs($budget['obligation']) > 0)
              {
              $transferred = $this->_update_order_budget($id, $latest_year, $periodization_id, $budget['obligation'], $contract_sum, $combined_cost = 0, $action = 'update', $activate = 0);
              }
             */
             $this->db->query("SELECT sum(amount) as paid FROM fm_workorder" . " {$this->join} fm_orders_paid_or_pending_view ON fm_workorder.id = fm_orders_paid_or_pending_view.order_id" . " WHERE periode > {$latest_year}00 AND periode < {$latest_year}13 AND fm_workorder.id = {$id}", __LINE__, __FILE__);
             $this->db->next_record();
             $paid_last_year = $this->db->f('paid');
             $transferred = $this->_update_order_budget($id, $latest_year, $periodization_id, $paid_last_year, $paid_last_year, $paid_last_year, $action = 'update', $activate = 0);
             $this->_update_order_budget($id, $year, $periodization_id, (int) $budget['budget_amount'], (int) $budget['budget_amount'], (int) $budget['budget_amount'], $action = 'update', true);
             $this->db->query("UPDATE fm_workorder_budget SET active = 0 WHERE order_id = {$id} AND year = {$latest_year}", __LINE__, __FILE__);
             $last_day_of_year = mktime(13, 0, 0, 12, 31, date("Y"));
             $now = time();
             $this->db->query("UPDATE fm_workorder SET start_date = {$now}, end_date = {$last_day_of_year} WHERE id = {$id}", __LINE__, __FILE__);
         } else {
             if ($project_type_id == 2) {
                 // total budget
                 $this->db->query("SELECT sum(combined_cost) AS budget FROM fm_workorder_budget WHERE order_id = {$id} AND year = {$latest_year}", __LINE__, __FILE__);
                 $this->db->next_record();
                 $last_budget = $this->db->f('budget');
                 if (!abs($last_budget) > 0) {
                     $this->_update_order_budget($id, $year, $periodization_id, 0, 0, 0, 'update', true);
                     if (!$this->global_lock) {
                         $this->db->transaction_commit();
                     }
                     return;
                     //					throw new Exception('property_workorder::transfer_budget() - no budget to transfer for this investment order: ' . $id);
                 }
                 //paid last year
                 $this->db->query("SELECT sum(amount) as paid FROM fm_workorder" . " {$this->join} fm_orders_paid_or_pending_view ON fm_workorder.id = fm_orders_paid_or_pending_view.order_id" . " WHERE periode > {$latest_year}00 AND periode < {$latest_year}13 AND fm_workorder.id = {$id}", __LINE__, __FILE__);
                 $this->db->next_record();
                 $paid_last_year = $this->db->f('paid');
                 $subtract = $last_budget - $paid_last_year;
                 $_perform_subtraction = false;
                 if ($last_budget >= 0) {
                     if ($paid_last_year <= $last_budget) {
                         $_perform_subtraction = true;
                     }
                 } else {
                     if ($paid_last_year >= $last_budget) {
                         $_perform_subtraction = true;
                     }
                 }
                 if ($_perform_subtraction) {
                     $transferred = $this->_update_order_budget($id, $latest_year, $periodization_id, $paid_last_year, $paid_last_year, $paid_last_year, $action = 'update', true);
                     $new_budget = $last_budget - $paid_last_year;
                 } else {
                     $new_budget = 0;
                 }
                 $this->_update_order_budget($id, $year, $periodization_id, $new_budget, $new_budget, $new_budget, $action = 'update', true);
             }
         }
     }
     //die();
     if (!$this->global_lock) {
         $this->db->transaction_commit();
     }
 }
コード例 #8
0
 /**
  * Delete an account or group
  *
  * @param integer $id Id of group/account to delete
  * @return boolean True on success otherwise false
  */
 public function delete($id)
 {
     $id = (int) get_account_id($id);
     $type = $this->get_type($id);
     if ($type == 'g') {
         $sri = ldap_search($this->ds, $this->group_context, "(&(objectclass=phpgwGroup)(gidnumber={$id}))");
         $allValues = ldap_get_entries($this->ds, $sri);
     } else {
         $sri = ldap_search($this->ds, $this->user_context, "(&(objectclass=phpgwAccount)(uidnumber={$id}))");
         $allValues = ldap_get_entries($this->ds, $sri);
     }
     if (isset($allValues[0]['dn']) && $allValues[0]['dn']) {
         if (ldap_delete($this->ds, $allValues[0]['dn'])) {
             phpgwapi_cache::system_clear('phpgwapi', "account_{$id}");
             if ($type == 'g') {
                 $sql = "DELETE FROM phpgw_group_map WHERE group_id = {$id}";
             } else {
                 $sql = "DELETE FROM phpgw_group_map WHERE account_id = {$id}";
             }
             $sql_acl = "DELETE FROM phpgw_acl WHERE acl_account = {$id}";
             $sql_acl_grant = "DELETE FROM phpgw_acl WHERE acl_grantor = {$id}";
             $this->db->transaction_begin();
             $this->db->query($sql, __LINE__, __FILE__, true);
             $this->db->query($sql_acl, __LINE__, __FILE__, true);
             $this->db->query($sql_acl_grant, __LINE__, __FILE__, true);
             $this->db->transaction_commit();
             return true;
         }
     } else {
         return false;
     }
 }
コード例 #9
0
 /**
  *
  * @param array $data
  * @return boolean true on ok, false on error
  */
 function perform_bulk_split($data, $voucher_id)
 {
     if (!is_array($data)) {
         throw new Exception('soinvoice::perform_bulk_split() - Not a valid input');
     }
     $voucher_id = (int) $voucher_id;
     $voucher = $this->read_single_voucher($voucher_id);
     $voucher_line = $voucher[0];
     $amount = 0;
     foreach ($voucher as $entry) {
         $amount += $entry['amount'];
         phpgwapi_cache::system_clear('property', "budget_order_{$entry['order_id']}");
     }
     unset($entry);
     $split_amount = 0;
     foreach ($data as $entry) {
         $split_amount += (double) $entry[2];
         if (!$entry[0] || !$entry[0] || !$entry[0]) {
             throw new Exception('soinvoice::perform_bulk_split() - incomplete dataset in input');
         }
     }
     if ($split_amount != $amount) {
         throw new Exception('soinvoice::perform_bulk_split() - amount does not add up');
     }
     $this->db->transaction_begin();
     $this->db->query("DELETE FROM fm_ecobilag WHERE bilagsnr='{$voucher_id}'", __LINE__, __FILE__);
     $_last_line_id = 0;
     foreach ($data as $entry) {
         $value_set = array('bilagsnr' => $voucher_line['voucher_id'], 'bilagsnr_ut' => $voucher_line['voucher_out_id'], 'typeid' => $voucher_line['type'], 'kildeid' => 1, 'belop' => $entry[2], 'fakturadato' => $voucher_line['invoice_date'], 'merknad' => $voucher_line['merknad'], 'periode' => $voucher_line['period'], 'forfallsdato' => $voucher_line['payment_date'], 'fakturanr' => $voucher_line['invoice_id'], 'regtid' => $voucher_line['regtid'], 'artid' => $voucher_line['art'], 'godkjentbelop' => $entry[2], 'budsjettansvarligid' => $voucher_line['budget_responsible'], 'splitt' => $_last_line_id, 'kreditnota' => $voucher_line['parked'], 'item_type' => $voucher_line['item_type'], 'item_id' => $voucher_line['item_id'], 'spvend_code' => $voucher_line['vendor_id'], 'external_ref' => $voucher_line['external_ref'], 'external_voucher_id' => $voucher_line['external_voucher_id'], 'currency' => $voucher_line['currency'], 'process_log' => $voucher_line['process_log'], 'process_code' => $voucher_line['process_code'], 'periodization' => $voucher_line['periodization'], 'periodization_start' => $voucher_line['periodization_start'], 'line_text' => $voucher_line['line_text'], 'external_voucher_id' => $voucher_line['external_voucher_id'], 'spbudact_code' => $voucher_line['b_account_id'], 'kostra_id' => $voucher_line['kostra_id'], 'mvakode' => $voucher_line['tax_code']);
         $cols = implode(',', array_keys($value_set));
         $values = $this->db->validate_insert(array_values($value_set));
         $this->db->query("INSERT INTO fm_ecobilag ({$cols}) VALUES ({$values})", __LINE__, __FILE__);
         $_last_line_id = $this->db->get_last_insert_id('fm_ecobilag', 'id');
         if (!$this->reassign_order($_last_line_id, $entry[1])) {
             $this->db->transaction_abort();
             throw new Exception("soinvoice::perform_bulk_split() - assigning order {$entry[1]} failed");
         }
     }
     $this->db->transaction_commit();
     return $_last_line_id;
 }