function fetchBillingInformation($year, $month, $mantis_project_id) { $mantisid = self::mantisIdToIdClient(); $dataparam = date_parse_from_format('d-m-Y', "01-{$month}-{$year}"); $startDate = mktime(0, 0, 0, $dataparam['month'], $dataparam['day'], $dataparam['year']); $endDate = strtotime("+1 month", $startDate); // Select the Mantis MySQL database if (!mysql_select_db(self::$_database)) { throw new Exception(mysql_error()); } $where_mantis_project_id = ''; if (isset($mantis_project_id)) { $where_mantis_project_id = "AND ( project.id = {$mantis_project_id} OR parent_project.id = {$mantis_project_id})"; } $req = "SELECT\n\t\t\t bug.id,\n\t\t\t bug.summary,\n\t\t\t user.realname AS client,\n\t\t\t IF(parent_project.name IS NULL, project.name, parent_project.name) AS project_name,\n\t\t\t IF(parent_project.name IS NULL, '', project.name) AS subproject_name,\n\t\t\t SUM(bugnote.time_tracking) AS time,\n\t\t\t bug.date_submitted,\n\t\t\t handler.realname AS handler,\n\t\t\t IF(parent_project.id IS NULL, project.id, parent_project.id) AS project_id,\n\t\t\t IF(custom_field_string.value IS NULL, 'Infogérance - Hors-périmètre', custom_field_string.value) AS support_type\n\t\t\tFROM mantis_bug_table bug\n\t\t\tJOIN mantis_bugnote_table bugnote ON bug.id = bugnote.bug_id\n\t\t\tJOIN mantis_project_table project ON bug.project_id = project.id\n\t\t\tJOIN mantis_user_table user ON user.id = bug.reporter_id\n\t\t\tLEFT JOIN mantis_user_table handler ON handler.id = bug.handler_id\n\t\t\tLEFT JOIN mantis_custom_field_string_table custom_field_string ON custom_field_string.bug_id = bug.id\n\t\t\tLEFT JOIN mantis_custom_field_table custom_field ON custom_field.id = custom_field_string.field_id\n\t\t\tLEFT JOIN mantis_project_hierarchy_table project_hierarchy ON project_hierarchy.child_id = project.id\n\t\t\tLEFT JOIN mantis_project_table parent_project ON project_hierarchy.parent_id = parent_project.id\n\t\t\tWHERE bugnote.date_submitted BETWEEN {$startDate} AND {$endDate}\n\t\t\t AND (custom_field.name = 'Support type' OR custom_field.name IS NULL)\n\t\t\t {$where_mantis_project_id}\n\t\t\tGROUP BY bugnote.bug_id\n\t\t\tORDER BY project.id, support_type"; $res = mysql_query($req) or die(mysql_error()); $billing = array(); setlocale(LC_TIME, 'fr_FR.UTF8'); $toggl = new WebfinanceToggl(); $toggl_time_tracking_per_ticket = $toggl->fetchBillingInformation($year, $month, 'Mantis'); // Prepare billing information while ($row = mysql_fetch_assoc($res)) { $webfinance_project_id = $mantisid[$row['project_id']]; if (!isset($webfinance_project_id)) { die("Unable to fetch information for project {$row['project_name']} " . "(Please add the mantis id: {$row['project_id']} to client: {$row['project_name']})"); } // Skip internal, non billable projects if ($webfinance_project_id == 0) { continue; } # Add time tracked by Toggl.com if (isset($toggl_time_tracking_per_ticket[$row['id']])) { $row['time'] += $toggl_time_tracking_per_ticket[$row['id']]; } $time = sprintf('%dh%02d', floor($row['time'] / 60), $row['time'] % 60); $description = sprintf("%s d'infogérance ponctuelle.\n" . "Traitement du ticket #%d ouvert le %s: %s", $time, $row['id'], strftime('%x', $row['date_submitted']), $row['summary']); if (!isset($billing[$webfinance_project_id])) { $billing[$webfinance_project_id] = array(); } $invoiced = FALSE; $price = 0; $invoiced_time = 0; if (isset($this->_support_type2price[$row['support_type']])) { $invoiced = TRUE; $price = $this->_support_type2price[$row['support_type']]; $invoiced_time = $row['time']; } $time_human_readable = sprintf('%dh%02d', floor(abs($row['time']) / 60), abs($row['time']) % 60); $billing[$webfinance_project_id][$row['id']] = array('description' => $description, 'quantity' => $row['time'] / 60, 'price' => $price, 'mantis_project_name' => $row['project_name'], 'id_client' => $webfinance_project_id, 'time' => $row['time'], 'time_human_readable' => $time_human_readable, 'invoiced_time' => $invoiced_time, 'mantis_ticket_summary' => $row['summary'], 'mantis_project_id' => $row['project_id'], 'support_type' => $row['support_type'], 'invoiced' => $invoiced, 'mantis_subproject_name' => $row['subproject_name']); // Process total price if (!isset($total_price[$webfinance_project_id])) { $total_price[$webfinance_project_id] = 0; } if ($invoiced) { $total_price[$webfinance_project_id] += $row['time'] / 60 * $price; } } // Process total price foreach ($total_price as $webfinance_project_id => $price) { # Deduce the time included in the contract from the support $price_to_deduce = self::supportHoursIncludedInContract($webfinance_project_id) * $this->_support_type2price['Infogérance - Hors-périmètre']; if ($price < $price_to_deduce) { $price_to_deduce = $price; } $description = "Déduction de l'infogérance ponctuelle comprise dans le contrat"; $billing[$webfinance_project_id][0] = array('description' => $description, 'mantis_ticket_summary' => $description, 'quantity' => -$price_to_deduce / $this->_support_type2price['Infogérance - Hors-périmètre'], 'time' => -$price_to_deduce / $this->_support_type2price['Infogérance - Hors-périmètre'] * 60, 'invoiced_time' => -$price_to_deduce / $this->_support_type2price['Infogérance - Hors-périmètre'] * 60, 'id_client' => $webfinance_project_id, 'price' => $this->_support_type2price['Infogérance - Hors-périmètre'], 'mantis_project_name' => '', 'mantis_project_id' => $row['project_id'], 'invoiced' => true); } // Select the Webfinance MySQL database if (!mysql_select_db(WF_SQL_BASE)) { throw new Exception(mysql_error()); } return $billing; }
$prenom = ""; if (isset($_POST['prenom'])) { $prenom = $_POST['prenom']; } $user_data = array("id_user" => $_POST['id_user'], "login" => $login, "first_name" => $prenom, "last_name" => $_POST['nom'], "password" => $_POST['password'], "email" => $emails, "role" => array("client"), "disabled" => "off", "admin" => "off"); if ($User->exists($id_user)) { $User->saveData($user_data); } else { $id_user = $User->createUser($user_data); } } $q = sprintf("UPDATE webfinance_clients SET " . "nom='%s',\n addr1='%s',\n addr2='%s',\n addr3='%s',\n cp='%s',\n\t ville='%s',\n rcs='%s',\n vat='%s',\n capital='%s',\n pays='%s',\n tel='%s',\n fax='%s',\n web='%s',\n\t email='%s',\n\t vat_number='%s',\n siren='%s',\n id_company_type='%d',\n id_user=%d,\n password='******',\n rib_titulaire='%s',\n id_mantis='%d',\n id_toggl='%d',\n supportHoursIncludedInContract='%s',\n language='%s',\n id_business_entity=%d,\n contract_signer = '%s',\n id_contract_signer_role = %d,\n invoice_delivery = '%s'\n WHERE id_client=%d", mysql_real_escape_string($nom), mysql_real_escape_string($addr1), mysql_real_escape_string($addr2), mysql_real_escape_string($addr3), mysql_real_escape_string($cp), mysql_real_escape_string($ville), mysql_real_escape_string($rcs), mysql_real_escape_string($vat), mysql_real_escape_string($capital), mysql_real_escape_string($pays), mysql_real_escape_string(removeSpace($tel)), mysql_real_escape_string(removeSpace($fax)), mysql_real_escape_string($web), mysql_real_escape_string($emails), mysql_real_escape_string($vat_number), mysql_real_escape_string($siren), mysql_real_escape_string($id_company_type), mysql_real_escape_string($_POST['id_user']), mysql_real_escape_string($password), mysql_real_escape_string($rib_titulaire), mysql_real_escape_string($id_mantis), mysql_real_escape_string($id_toggl), mysql_real_escape_string($supportHoursIncludedInContract), mysql_real_escape_string($clt_language), mysql_real_escape_string($id_business_entity), mysql_real_escape_string($contract_signer), mysql_real_escape_string($id_contract_signer_role), mysql_real_escape_string($invoice_delivery), mysql_real_escape_string($id_client)); mysql_query($q) or die(mysql_error()); // Check if we have to rename clients if ($_POST['nom'] != $Client->nom) { // Rename Mantis project $mantis_project = array('name' => $nom, 'view_state' => array('id' => 50)); $mantis = new WebfinanceMantis(); $mantis->updateProject($id_mantis, $mantis_project); // Rename Toggl client $toggl = new WebfinanceToggl(); $toggl->renameClient($id_client, $nom); } if (isset($_SESSION['message'])) { $_SESSION['message'] .= "<br/>" . _('Update customer'); } else { $_SESSION['message'] = _('Update customer'); } logmessage(_('Update customer') . " client:{$id_client} ({$nom})", $id_client); header("Location: /prospection/fiche_prospect.php?id={$id_client}&onglet=" . $focused_onglet); exit;
} catch (SoapFault $fault) { echo $fault; } exit; } // Create new client if (isset($_GET['action']) && $_GET['action'] == '_new') { $client_name = 'Nouvelle Entreprise_' . time(); mysql_query("INSERT INTO webfinance_clients (nom,date_created) VALUES('{$client_name}', now())") or die(mysql_error()); $_GET['id'] = mysql_insert_id(); // Create Mantis project $mantis_project = array('name' => $client_name, 'view_state' => array('id' => 50)); $mantis = new WebfinanceMantis(); $mantis->createProject($_GET['id'], $mantis_project); // Create Toggl client $toggl = new WebfinanceToggl(); $toggl->createClient($_GET['id'], $client_name); $_SESSION['message'] = _('New customer created'); logmessage(_('Create customer') . " client:" . $_GET['id'], $_GET['id']); } $Client = new Client($_GET['id']); $title = $Client->nom; array_push($extra_js, "/js/onglets.js"); if (!preg_match("/^[0-9]+\$/", $_GET['id'])) { header("Location: /prospection/"); die; } // Onglet affiché par défaut if (isset($_GET['onglet'])) { $shown_tab = $_GET['onglet']; } elseif (isset($User->prefs->default_onglet_fiche_contact)) {