/** * Gets VAT to collect for the given year (and given quarter or month) * The function gets the VAT in split results, as the VAT declaration asks * to report the amounts for different VAT rates as different lines. * This function also accounts recurrent invoices. * * @param DoliDB $db Database handler object * @param int $y Year * @param int $q Quarter * @param string $date_start Start date * @param string $date_end End date * @param int $modetax 0 or 1 (option vat on debit) * @param int $direction 'sell' (customer invoice) or 'buy' (supplier invoices) * @param int $m Month * @return array List of quarters with vat */ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $m = 0) { global $conf; $list = array(); if ($direction == 'sell') { $invoicetable = 'facture'; $invoicedettable = 'facturedet'; $fk_facture = 'fk_facture'; $fk_facture2 = 'fk_facture'; $fk_payment = 'fk_paiement'; $total_tva = 'total_tva'; $total_localtax1 = 'total_localtax1'; $total_localtax2 = 'total_localtax2'; $paymenttable = 'paiement'; $paymentfacturetable = 'paiement_facture'; $invoicefieldref = 'facnumber'; } if ($direction == 'buy') { $invoicetable = 'facture_fourn'; $invoicedettable = 'facture_fourn_det'; $fk_facture = 'fk_facture_fourn'; $fk_facture2 = 'fk_facturefourn'; $fk_payment = 'fk_paiementfourn'; $total_tva = 'tva'; $total_localtax1 = 'total_localtax1'; $total_localtax2 = 'total_localtax2'; $paymenttable = 'paiementfourn'; $paymentfacturetable = 'paiementfourn_facturefourn'; $invoicefieldref = 'ref'; } // CAS DES BIENS // Define sql request $sql = ''; if ($modetax == 1) { // Count on delivery date (use invoice date as delivery is unknown) $sql = "SELECT d.rowid, d.product_type as dtype, d." . $fk_facture . " as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d." . $total_tva . " as total_vat, d.description as descr,"; $sql .= " d." . $total_localtax1 . " as total_localtax1, d." . $total_localtax2 . " as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f." . $invoicefieldref . " as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " 0 as payment_id, 0 as payment_amount"; $sql .= " FROM " . MAIN_DB_PREFIX . $invoicetable . " as f,"; $sql .= " " . MAIN_DB_PREFIX . "societe as s,"; $sql .= " " . MAIN_DB_PREFIX . $invoicedettable . " as d"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity = " . $conf->entity; $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND f.type IN (0,1,2,5)"; } else { $sql .= " AND f.type IN (0,1,2,3,5)"; } $sql .= " AND f.rowid = d." . $fk_facture; $sql .= " AND s.rowid = f.fk_soc"; if ($y && $m) { $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, $m, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, $m, false)) . "'"; } else { if ($y) { $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; } } if ($q) { $sql .= " AND (date_format(f.datef,'%m') > " . ($q - 1) * 3 . " AND date_format(f.datef,'%m') <= " . $q * 3 . ")"; } if ($date_start && $date_end) { $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'"; } $sql .= " AND (d.product_type = 0"; // Limit to products $sql .= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of service $sql .= " ORDER BY d.rowid, d." . $fk_facture; } else { // Count on delivery date (use invoice date as delivery is unknown) $sql = "SELECT d.rowid, d.product_type as dtype, d." . $fk_facture . " as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d." . $total_tva . " as total_vat, d.description as descr,"; $sql .= " d." . $total_localtax1 . " as total_localtax1, d." . $total_localtax2 . " as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f." . $invoicefieldref . " as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef as date_f, s.nom as company_name, s.rowid as company_id,"; $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " 0 as payment_id, 0 as payment_amount"; $sql .= " FROM " . MAIN_DB_PREFIX . $invoicetable . " as f,"; $sql .= " " . MAIN_DB_PREFIX . "societe as s,"; $sql .= " " . MAIN_DB_PREFIX . $invoicedettable . " as d"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity = " . $conf->entity; $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND f.type IN (0,1,2,5)"; } else { $sql .= " AND f.type IN (0,1,2,3,5)"; } $sql .= " AND f.rowid = d." . $fk_facture; $sql .= " AND s.rowid = f.fk_soc"; if ($y && $m) { $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, $m, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, $m, false)) . "'"; } else { if ($y) { $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; } } if ($q) { $sql .= " AND (date_format(f.datef,'%m') > " . ($q - 1) * 3 . " AND date_format(f.datef,'%m') <= " . $q * 3 . ")"; } if ($date_start && $date_end) { $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'"; } $sql .= " AND (d.product_type = 0"; // Limit to products $sql .= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of service $sql .= " ORDER BY d.rowid, d." . $fk_facture; //print $sql; } //print $sql.'<br>'; if (!$sql) { return -1; } if ($sql == 'TODO') { return -2; } if ($sql != 'TODO') { dol_syslog("Tax.lib.php::vat_by_date", LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $rate = -1; $oldrowid = ''; while ($assoc = $db->fetch_array($resql)) { if (!isset($list[$assoc['rate']]['totalht'])) { $list[$assoc['rate']]['totalht'] = 0; } if (!isset($list[$assoc['rate']]['vat'])) { $list[$assoc['rate']]['vat'] = 0; } if (!isset($list[$assoc['rate']]['localtax1'])) { $list[$assoc['rate']]['localtax1'] = 0; } if (!isset($list[$assoc['rate']]['localtax2'])) { $list[$assoc['rate']]['localtax2'] = 0; } if ($assoc['rowid'] != $oldrowid) { $oldrowid = $assoc['rowid']; $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; $list[$assoc['rate']]['vat'] += $assoc['total_vat']; $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; } $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; $list[$assoc['rate']]['datef'][] = $assoc['datef']; $list[$assoc['rate']]['company_name'][] = $assoc['company_name']; $list[$assoc['rate']]['company_id'][] = $assoc['company_id']; $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); $list[$assoc['rate']]['facid'][] = $assoc['facid']; $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; $list[$assoc['rate']]['type'][] = $assoc['type']; $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; $list[$assoc['rate']]['descr'][] = $assoc['descr']; $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; $list[$assoc['rate']]['pid'][] = $assoc['pid']; $list[$assoc['rate']]['pref'][] = $assoc['pref']; $list[$assoc['rate']]['ptype'][] = $assoc['ptype']; $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; $rate = $assoc['rate']; } } else { dol_print_error($db); return -3; } } // CAS DES SERVICES // Define sql request $sql = ''; if ($modetax == 1) { // Count on invoice date $sql = "SELECT d.rowid, d.product_type as dtype, d." . $fk_facture . " as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d." . $total_tva . " as total_vat, d.description as descr,"; $sql .= " d." . $total_localtax1 . " as total_localtax1, d." . $total_localtax2 . " as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f." . $invoicefieldref . " as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " 0 as payment_id, 0 as payment_amount"; $sql .= " FROM " . MAIN_DB_PREFIX . $invoicetable . " as f,"; $sql .= " " . MAIN_DB_PREFIX . "societe as s,"; $sql .= " " . MAIN_DB_PREFIX . $invoicedettable . " as d"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity = " . $conf->entity; $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND f.type IN (0,1,2,5)"; } else { $sql .= " AND f.type IN (0,1,2,3,5)"; } $sql .= " AND f.rowid = d." . $fk_facture; $sql .= " AND s.rowid = f.fk_soc"; if ($y && $m) { $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, $m, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, $m, false)) . "'"; } else { if ($y) { $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; } } if ($q) { $sql .= " AND (date_format(f.datef,'%m') > " . ($q - 1) * 3 . " AND date_format(f.datef,'%m') <= " . $q * 3 . ")"; } if ($date_start && $date_end) { $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'"; } $sql .= " AND (d.product_type = 1"; // Limit to services $sql .= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service $sql .= " ORDER BY d.rowid, d." . $fk_facture; } else { // Count on payments date $sql = "SELECT d.rowid, d.product_type as dtype, d." . $fk_facture . " as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d." . $total_tva . " as total_vat, d.description as descr,"; $sql .= " d." . $total_localtax1 . " as total_localtax1, d." . $total_localtax2 . " as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f." . $invoicefieldref . " as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " pf." . $fk_payment . " as payment_id, pf.amount as payment_amount"; $sql .= " FROM " . MAIN_DB_PREFIX . $invoicetable . " as f,"; $sql .= " " . MAIN_DB_PREFIX . $paymentfacturetable . " as pf,"; $sql .= " " . MAIN_DB_PREFIX . $paymenttable . " as pa,"; $sql .= " " . MAIN_DB_PREFIX . "societe as s,"; $sql .= " " . MAIN_DB_PREFIX . $invoicedettable . " as d"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity = " . $conf->entity; $sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND f.type IN (0,1,2,5)"; } else { $sql .= " AND f.type IN (0,1,2,3,5)"; } $sql .= " AND f.rowid = d." . $fk_facture; $sql .= " AND s.rowid = f.fk_soc"; $sql .= " AND pf." . $fk_facture2 . " = f.rowid"; $sql .= " AND pa.rowid = pf." . $fk_payment; if ($y && $m) { $sql .= " AND pa.datep >= '" . $db->idate(dol_get_first_day($y, $m, false)) . "'"; $sql .= " AND pa.datep <= '" . $db->idate(dol_get_last_day($y, $m, false)) . "'"; } else { if ($y) { $sql .= " AND pa.datep >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND pa.datep <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; } } if ($q) { $sql .= " AND (date_format(pa.datep,'%m') > " . ($q - 1) * 3 . " AND date_format(pa.datep,'%m') <= " . $q * 3 . ")"; } if ($date_start && $date_end) { $sql .= " AND pa.datep >= '" . $db->idate($date_start) . "' AND pa.datep <= '" . $db->idate($date_end) . "'"; } $sql .= " AND (d.product_type = 1"; // Limit to services $sql .= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service $sql .= " ORDER BY d.rowid, d." . $fk_facture . ", pf.rowid"; } if (!$sql) { dol_syslog("Tax.lib.php::vat_by_date no accountancy module enabled" . $sql, LOG_ERR); return -1; // -1 = Not accountancy module enabled } if ($sql == 'TODO') { return -2; } // -2 = Feature not yet available if ($sql != 'TODO') { dol_syslog("Tax.lib.php::vat_by_date", LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $rate = -1; $oldrowid = ''; while ($assoc = $db->fetch_array($resql)) { if (!isset($list[$assoc['rate']]['totalht'])) { $list[$assoc['rate']]['totalht'] = 0; } if (!isset($list[$assoc['rate']]['vat'])) { $list[$assoc['rate']]['vat'] = 0; } if (!isset($list[$assoc['rate']]['localtax1'])) { $list[$assoc['rate']]['localtax1'] = 0; } if (!isset($list[$assoc['rate']]['localtax2'])) { $list[$assoc['rate']]['localtax2'] = 0; } if ($assoc['rowid'] != $oldrowid) { $oldrowid = $assoc['rowid']; $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; $list[$assoc['rate']]['vat'] += $assoc['total_vat']; $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; } $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; $list[$assoc['rate']]['datef'][] = $assoc['datef']; $list[$assoc['rate']]['company_name'][] = $assoc['company_name']; $list[$assoc['rate']]['company_id'][] = $assoc['company_id']; $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); $list[$assoc['rate']]['facid'][] = $assoc['facid']; $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; $list[$assoc['rate']]['type'][] = $assoc['type']; $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; $list[$assoc['rate']]['descr'][] = $assoc['descr']; $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; $list[$assoc['rate']]['pid'][] = $assoc['pid']; $list[$assoc['rate']]['pref'][] = $assoc['pref']; $list[$assoc['rate']]['ptype'][] = $assoc['ptype']; $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; $rate = $assoc['rate']; } } else { dol_print_error($db); return -3; } } return $list; }
/** * Return HTML table with list of projects and number of opened tasks * * @param DoliDB $db Database handler * @param Form $form Object form * @param int $socid Id thirdparty * @param int $projectsListId Id of project I have permission on * @param int $mytasks Limited to task I am contact to * @param int $statut -1=No filter on statut, 0 or 1 = Filter on status * @param array $listofoppstatus List of opportunity status * @param array $hiddenfields List of info to not show ('projectlabel', 'declaredprogress', '...', ) * @return void */ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $statut = -1, $listofoppstatus = array(), $hiddenfields = array()) { global $langs, $conf, $user, $bc; require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; $projectstatic = new Project($db); $thirdpartystatic = new Societe($db); $sortfield = ''; $sortorder = ''; $project_year_filter = 0; $title = $langs->trans("Projects"); if (strcmp($statut, '') && $statut >= 0) { $title = $langs->trans("Projects") . ' ' . $langs->trans($projectstatic->statuts_long[$statut]); } $arrayidtypeofcontact = array(); print '<table class="noborder" width="100%">'; $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p"; if ($mytasks) { $sql .= ", " . MAIN_DB_PREFIX . "projet_task as t"; $sql .= ", " . MAIN_DB_PREFIX . "element_contact as ec"; $sql .= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc"; } else { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as t ON p.rowid = t.fk_projet"; } $sql .= " WHERE p.entity = " . $conf->entity; $sql .= " AND p.rowid IN (" . $projectsListId . ")"; if ($socid) { $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")"; } if ($mytasks) { $sql .= " AND p.rowid = t.fk_projet"; $sql .= " AND ec.element_id = t.rowid"; $sql .= " AND ec.fk_socpeople = " . $user->id; $sql .= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact $sql .= " AND ctc.element = 'project_task'"; } if ($statut >= 0) { $sql .= " AND p.fk_statut = " . $statut; } if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { $project_year_filter = GETPOST("project_year_filter"); //Check if empty or invalid year. Wildcard ignores the sql check if ($project_year_filter != "*") { if (empty($project_year_filter) || !ctype_digit($project_year_filter)) { $project_year_filter = date("Y"); } $sql .= " AND (p.dateo IS NULL OR p.dateo <= " . $db->idate(dol_get_last_day($project_year_filter, 12, false)) . ")"; $sql .= " AND (p.datee IS NULL OR p.datee >= " . $db->idate(dol_get_first_day($project_year_filter, 1, false)) . ")"; } } // Get id of project we must show tasks $arrayidofprojects = array(); $sql1 = "SELECT p.rowid as projectid"; $sql1 .= $sql; $resql = $db->query($sql1); if ($resql) { $i = 0; $num = $db->num_rows($resql); while ($i < $num) { $objp = $db->fetch_object($resql); $arrayidofprojects[$objp->projectid] = $objp->projectid; $i++; } } else { dol_print_error($db); } if (empty($arrayidofprojects)) { $arrayidofprojects[0] = -1; } // Get list of project with calculation on tasks $sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc, s.nom as socname, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount,"; $sql2 .= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload"; $sql2 .= " FROM " . MAIN_DB_PREFIX . "projet as p"; $sql2 .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = p.fk_soc"; $sql2 .= " LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as t ON p.rowid = t.fk_projet"; $sql2 .= " WHERE p.rowid IN (" . join(',', $arrayidofprojects) . ")"; $sql2 .= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount"; $sql2 .= " ORDER BY p.title, p.ref"; $var = true; $resql = $db->query($sql2); if ($resql) { $total_task = 0; $total_opp_amount = 0; $ponderated_opp_amount = 0; $num = $db->num_rows($resql); $i = 0; print '<tr class="liste_titre">'; print_liste_field_titre($title . ' <span class="badge">' . $num . '</span>', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("ThirdParty"), $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder); if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print_liste_field_titre($langs->trans("OpportunityAmount"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("OpportunityStatus"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } if (empty($conf->global->PROJECT_HIDE_TASKS)) { print_liste_field_titre($langs->trans("Tasks"), "", "", "", "", 'align="right"', $sortfield, $sortorder); if (!in_array('plannedworkload', $hiddenfields)) { print_liste_field_titre($langs->trans("PlannedWorkload"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } if (!in_array('declaredprogress', $hiddenfields)) { print_liste_field_titre($langs->trans("ProgressDeclared"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } } print_liste_field_titre($langs->trans("Status"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print "</tr>\n"; while ($i < $num) { $objp = $db->fetch_object($resql); $projectstatic->id = $objp->projectid; $projectstatic->user_author_id = $objp->fk_user_creat; $projectstatic->public = $objp->public; // Check is user has read permission on project $userAccess = $projectstatic->restrictedProjectArea($user); if ($userAccess >= 0) { $var = !$var; print "<tr " . $bc[$var] . ">"; print '<td>'; $projectstatic->ref = $objp->ref; print $projectstatic->getNomUrl(1); if (!in_array('projectlabel', $hiddenfields)) { print ' - ' . dol_trunc($objp->title, 24); } print '</td>'; print '<td>'; if ($objp->fk_soc > 0) { $thirdpartystatic->id = $objp->fk_soc; $thirdpartystatic->ref = $objp->socname; $thirdpartystatic->name = $objp->socname; print $thirdpartystatic->getNomUrl(1); } print '</td>'; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print '<td align="right">'; if ($objp->opp_amount) { print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency); } print '</td>'; print '<td align="right">'; $code = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code'); if ($code) { print $langs->trans("OppStatus" . $code); } print '</td>'; } $projectstatic->statut = $objp->status; if (empty($conf->global->PROJECT_HIDE_TASKS)) { print '<td align="right">' . $objp->nb . '</td>'; $plannedworkload = $objp->planned_workload; $total_plannedworkload += $plannedworkload; if (!in_array('plannedworkload', $hiddenfields)) { print '<td align="right">' . ($plannedworkload ? convertSecondToTime($plannedworkload) : '') . '</td>'; } if (!in_array('declaredprogress', $hiddenfields)) { $declaredprogressworkload = $objp->declared_progess_workload; $total_declaredprogressworkload += $declaredprogressworkload; print '<td align="right">'; //print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>"; print $plannedworkload ? round(100 * $declaredprogressworkload / $plannedworkload, 0) . '%' : ''; print '</td>'; } } print '<td align="right">' . $projectstatic->getLibStatut(3) . '</td>'; print "</tr>\n"; $total_task = $total_task + $objp->nb; $total_opp_amount = $total_opp_amount + $objp->opp_amount; $ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$objp->opp_status] * $objp->opp_amount / 100); } $i++; } print '<tr class="liste_total">'; print '<td colspan="2">' . $langs->trans("Total") . "</td>"; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print '<td class="liste_total" align="right">' . price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency) . '</td>'; print '<td class="liste_total" align="right">' . $form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1) . '</td>'; } if (empty($conf->global->PROJECT_HIDE_TASKS)) { print '<td class="liste_total" align="right">' . $total_task . '</td>'; if (!in_array('plannedworkload', $hiddenfields)) { print '<td class="liste_total" align="right">' . ($total_plannedworkload ? convertSecondToTime($total_plannedworkload) : '') . '</td>'; } if (!in_array('declaredprogress', $hiddenfields)) { print '<td class="liste_total" align="right">' . ($total_plannedworkload ? round(100 * $total_declaredprogressworkload / $total_plannedworkload, 0) . '%' : '') . '</td>'; } } print '<td class="liste_total"></td>'; print '</tr>'; $db->free($resql); } else { dol_print_error($db); } print "</table>"; if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { //Add the year filter input print '<form method="get" action="' . $_SERVER["PHP_SELF"] . '">'; print '<table width="100%">'; print '<tr>'; print '<td>' . $langs->trans("Year") . '</td>'; print '<td style="text-align:right"><input type="text" size="4" class="flat" name="project_year_filter" value="' . $project_year_filter . '"/>'; print "</tr>\n"; print '</table></form>'; } }
/** * Add a notification * * @param DoliDB $db database handler * @param User $user notification user * @param string $action notification action * @return int 0 if OK, <0 if KO */ function AddNotification($db, $user, $action) { $result = 0; if ($this->DeleteNotification($user, $action) == 0) { $now = dol_now(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)"; $sql .= " VALUES (" . $db->idate($now) . "," . $user . ", 'NULL', 'NULL', '" . $action . "')"; dol_syslog("adnotiff: " . $sql); if ($this->db->query($sql)) { $result = 0; } else { $result = -1; dol_syslog(get_class($this) . "::AddNotification Error {$result}"); } } return $result; }
/** * Function to build a compiled PDF * * @param DoliDB $db Database handler * @param Translate $langs Object langs * @param Conf $conf Object conf * @param string $diroutputpdf Dir to output file * @param string $newlangid Lang id * @param array $filter Array with filters * @param date $dateafterdate Invoice after date * @param date $datebeforedate Invoice before date * @param date $paymentdateafter Payment after date (must includes hour) * @param date $paymentdatebefore Payment before date (must includes hour) * @param int $usestdout Add information onto standard output * @param int $regenerate ''=Use existing PDF files, 'nameofpdf'=Regenerate all PDF files using the template * @param string $filesuffix Suffix to add into file name of generated PDF * @param string $paymentbankid Only if payment on this bank account id * @param array $thirdpartiesid List of thirdparties id when using filter excludethirdpartiesid or onlythirdpartiesid * @param string $fileprefix Prefix to add into filename of generated PDF * @return int Error code */ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate = 0, $filesuffix = '', $paymentbankid = '', $thirdpartiesid = '', $fileprefix = 'mergedpdf') { $sql = "SELECT DISTINCT f.rowid, f.facnumber"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f"; $sqlwhere = ''; $sqlorder = ''; if (in_array('all', $filter)) { $sqlorder = " ORDER BY f.facnumber ASC"; } if (in_array('date', $filter)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= " f.fk_statut > 0"; $sqlwhere .= " AND f.datef >= '" . $db->idate($dateafterdate) . "'"; $sqlwhere .= " AND f.datef <= '" . $db->idate($datebeforedate) . "'"; $sqlorder = " ORDER BY f.datef ASC"; } if (in_array('nopayment', $filter)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "paiement_facture as pf ON f.rowid = pf.fk_facture"; if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= " f.fk_statut > 0"; $sqlwhere .= " AND pf.fk_paiement IS NULL"; } if (in_array('payments', $filter) || in_array('bank', $filter)) { $sql .= ", " . MAIN_DB_PREFIX . "paiement_facture as pf, " . MAIN_DB_PREFIX . "paiement as p"; if (in_array('bank', $filter)) { $sql .= ", " . MAIN_DB_PREFIX . "bank as b"; } if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= " f.fk_statut > 0"; $sqlwhere .= " AND f.rowid = pf.fk_facture"; $sqlwhere .= " AND pf.fk_paiement = p.rowid"; if (in_array('payments', $filter)) { $sqlwhere .= " AND p.datep >= '" . $db->idate($paymentdateafter) . "'"; $sqlwhere .= " AND p.datep <= '" . $db->idate($paymentdatebefore) . "'"; } if (in_array('bank', $filter)) { $sqlwhere .= " AND p.fk_bank = b.rowid"; $sqlwhere .= " AND b.fk_account = " . $paymentbankid; } $sqlorder = " ORDER BY p.datep ASC"; } if (in_array('nodeposit', $filter)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' type <> 3'; } if (in_array('noreplacement', $filter)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' type <> 1'; } if (in_array('nocreditnote', $filter)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' type <> 2'; } if (in_array('excludethirdparties', $filter) && is_array($thirdpartiesid)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' f.fk_soc NOT IN (' . join(',', $thirdpartiesid) . ')'; } if (in_array('onlythirdparties', $filter) && is_array($thirdpartiesid)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' f.fk_soc IN (' . join(',', $thirdpartiesid) . ')'; } if ($sqlwhere) { $sql .= $sqlwhere; } if ($sqlorder) { $sql .= $sqlorder; } //print $sql; exit; dol_syslog("scripts/invoices/rebuild_merge.php:", LOG_DEBUG); if ($usestdout) { print '--- start' . "\n"; } // Start of transaction //$db->begin(); $error = 0; $result = 0; $files = array(); // liste les fichiers dol_syslog("scripts/invoices/rebuild_merge.php", LOG_DEBUG); if ($resql = $db->query($sql)) { $num = $db->num_rows($resql); $cpt = 0; $oldemail = ''; $message = ''; $total = ''; if ($num) { // First loop on each resultset to build PDF // ----------------------------------------- while ($cpt < $num) { $obj = $db->fetch_object($resql); $fac = new Facture($db); $result = $fac->fetch($obj->rowid); if ($result > 0) { $outputlangs = $langs; if (!empty($newlangid)) { if ($outputlangs->defaultlang != $newlangid) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlangid); } } $filename = $conf->facture->dir_output . '/' . $fac->ref . '/' . $fac->ref . '.pdf'; if ($regenerate || !dol_is_file($filename)) { if ($usestdout) { print "Build PDF for invoice " . $obj->facnumber . " - Lang = " . $outputlangs->defaultlang . "\n"; } $result = $fac->generateDocument($regenerate ? $regenerate : $fac->modelpdf, $outputlangs); } else { if ($usestdout) { print "PDF for invoice " . $obj->facnumber . " already exists\n"; } } // Add file into files array $files[] = $filename; } if ($result <= 0) { $error++; if ($usestdout) { print "Error: Failed to build PDF for invoice " . ($fac->ref ? $fac->ref : ' id ' . $obj->rowid) . "\n"; } else { dol_syslog("Failed to build PDF for invoice " . ($fac->ref ? $fac->ref : ' id ' . $obj->rowid), LOG_ERR); } } $cpt++; } // Define format of output PDF $formatarray = pdf_getFormat($langs); $page_largeur = $formatarray['width']; $page_hauteur = $formatarray['height']; $format = array($page_largeur, $page_hauteur); if ($usestdout) { print "Using output PDF format " . join('x', $format) . "\n"; } else { dol_syslog("Using output PDF format " . join('x', $format), LOG_ERR); } // Now, build a merged files with all files in $files array //--------------------------------------------------------- // Create empty PDF $pdf = pdf_getInstance($format); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($langs)); if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) { $pdf->SetCompression(false); } //$pdf->SetCompression(false); // Add all others foreach ($files as $file) { if ($usestdout) { print "Merge PDF file for invoice " . $file . "\n"; } else { dol_syslog("Merge PDF file for invoice " . $file); } // Charge un document PDF depuis un fichier. $pagecount = $pdf->setSourceFile($file); for ($i = 1; $i <= $pagecount; $i++) { $tplidx = $pdf->importPage($i); $s = $pdf->getTemplatesize($tplidx); $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); $pdf->useTemplate($tplidx); } } // Create output dir if not exists dol_mkdir($diroutputpdf); // Save merged file $filename = $fileprefix; if (empty($filename)) { $filename = 'mergedpdf'; } if (!empty($filesuffix)) { $filename .= '_' . $filesuffix; } $file = $diroutputpdf . '/' . $filename . '.pdf'; if (!$error && $pagecount) { $pdf->Output($file, 'F'); if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } } if ($usestdout) { if (!$error) { print "Merged PDF has been built in " . $file . "\n"; } else { print "Can't build PDF " . $file . "\n"; } } $result = 1; } else { if ($usestdout) { print "No invoices found for criteria.\n"; } else { dol_syslog("No invoices found for criteria"); } $result = 0; } } else { dol_print_error($db); dol_syslog("scripts/invoices/rebuild_merge.php: Error"); $error++; } if ($error) { return -1; } else { return $result; } }
/** * Show html area with actions done * * @param Conf $conf Object conf * @param Translate $langs Object langs * @param DoliDB $db Object db * @param Object $object Object third party or member * @param Contact $objcon Object contact * @param int $noprint Return string but does not output it * @return mixed Return html part or void if noprint is 1 * TODO change function to be able to list event linked to an object. */ function show_actions_done($conf, $langs, $db, $object, $objcon = '', $noprint = 0) { global $bc, $user; // Check parameters if (!is_object($object)) { dol_print_error('', 'BadParameter'); } $out = ''; $histo = array(); $numaction = 0; $now = dol_now('tzuser'); if (!empty($conf->agenda->enabled)) { // Recherche histo sur actioncomm $sql = "SELECT a.id, a.label,"; $sql .= " a.datep as dp,"; $sql .= " a.datep2 as dp2,"; $sql .= " a.note, a.percent,"; $sql .= " a.fk_element, a.elementtype,"; $sql .= " a.fk_user_author, a.fk_contact,"; $sql .= " c.code as acode, c.libelle,"; $sql .= " u.login, u.rowid as user_id"; if (get_class($object) == 'Adherent') { $sql .= ", m.lastname, m.firstname"; } if (get_class($object) == 'Societe') { $sql .= ", sp.lastname, sp.firstname"; } $sql .= " FROM " . MAIN_DB_PREFIX . "c_actioncomm as c, " . MAIN_DB_PREFIX . "user as u, " . MAIN_DB_PREFIX . "actioncomm as a"; if (get_class($object) == 'Adherent') { $sql .= ", " . MAIN_DB_PREFIX . "adherent as m"; } if (get_class($object) == 'Societe') { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON a.fk_contact = sp.rowid"; } $sql .= " WHERE u.rowid = a.fk_user_author"; $sql .= " AND a.entity IN (" . getEntity('agenda', 1) . ")"; if (get_class($object) == 'Adherent') { $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'"; } if (get_class($object) == 'Adherent' && $object->id) { $sql .= " AND a.fk_element = " . $object->id; } if (get_class($object) == 'Societe' && $object->id) { $sql .= " AND a.fk_soc = " . $object->id; } if (is_object($objcon) && $objcon->id) { $sql .= " AND a.fk_contact = " . $objcon->id; } $sql .= " AND c.id=a.fk_action"; $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" . $db->idate($now) . "'))"; $sql .= " ORDER BY a.datep DESC, a.id DESC"; dol_syslog("company.lib::show_actions_done sql=" . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $i = 0; $num = $db->num_rows($resql); $var = true; while ($i < $num) { $obj = $db->fetch_object($resql); $histo[$numaction] = array('type' => 'action', 'id' => $obj->id, 'datestart' => $db->jdate($obj->dp), 'date' => $db->jdate($obj->dp2), 'note' => $obj->label, 'percent' => $obj->percent, 'acode' => $obj->acode, 'libelle' => $obj->libelle, 'userid' => $obj->user_id, 'login' => $obj->login, 'contact_id' => $obj->fk_contact, 'lastname' => $obj->lastname, 'firstname' => $obj->firstname, 'fk_element' => $obj->fk_element, 'elementtype' => $obj->elementtype); $numaction++; $i++; } } else { dol_print_error($db); } } if (!empty($conf->mailing->enabled) && !empty($objcon->email)) { $langs->load("mails"); // Recherche histo sur mailing $sql = "SELECT m.rowid as id, mc.date_envoi as da, m.titre as note, '100' as percentage,"; $sql .= " 'AC_EMAILING' as acode,"; $sql .= " u.rowid as user_id, u.login"; // User that valid action $sql .= " FROM " . MAIN_DB_PREFIX . "mailing as m, " . MAIN_DB_PREFIX . "mailing_cibles as mc, " . MAIN_DB_PREFIX . "user as u"; $sql .= " WHERE mc.email = '" . $db->escape($objcon->email) . "'"; // Search is done on email. $sql .= " AND mc.statut = 1"; $sql .= " AND u.rowid = m.fk_user_valid"; $sql .= " AND mc.fk_mailing=m.rowid"; $sql .= " ORDER BY mc.date_envoi DESC, m.rowid DESC"; dol_syslog("company.lib::show_actions_done sql=" . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $i = 0; $num = $db->num_rows($resql); $var = true; while ($i < $num) { $obj = $db->fetch_object($resql); $histo[$numaction] = array('type' => 'mailing', 'id' => $obj->id, 'date' => $db->jdate($obj->da), 'note' => $obj->note, 'percent' => $obj->percentage, 'acode' => $obj->acode, 'userid' => $obj->user_id, 'login' => $obj->login); $numaction++; $i++; } $db->free($resql); } else { dol_print_error($db); } } if (!empty($conf->agenda->enabled) || !empty($conf->mailing->enabled) && !empty($objcon->email)) { require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php'; require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; $actionstatic = new ActionComm($db); $userstatic = new User($db); $contactstatic = new Contact($db); // TODO uniformize $propalstatic = new Propal($db); $orderstatic = new Commande($db); $facturestatic = new Facture($db); $out .= "\n"; $out .= '<table class="noborder" width="100%">'; $out .= '<tr class="liste_titre">'; $out .= '<td colspan="2">'; if (get_class($object) == 'Societe') { $out .= '<a href="' . DOL_URL_ROOT . '/comm/action/listactions.php?socid=' . $object->id . '&status=done">'; } $out .= $langs->trans("ActionsDoneShort"); if (get_class($object) == 'Societe') { $out .= '</a>'; } $out .= '</td>'; $out .= '<td colspan="5" align="right">'; $permok = $user->rights->agenda->myactions->create; if ((!empty($object->id) || !empty($objcon->id)) && $permok) { $out .= '<a href="' . DOL_URL_ROOT . '/comm/action/fiche.php?action=create'; if (get_class($object) == 'Societe') { $out .= '&socid=' . $object->id; } $out .= (!empty($objcon->id) ? '&contactid=' . $objcon->id : '') . '&backtopage=1&percentage=-1">'; $out .= $langs->trans("AddAnAction") . ' '; $out .= img_picto($langs->trans("AddAnAction"), 'filenew'); $out .= "</a>"; } $out .= '</td>'; $out .= '</tr>'; foreach ($histo as $key => $value) { $var = !$var; $out .= "<tr " . $bc[$var] . ">"; // Champ date $out .= '<td width="120" class="nowrap">'; if ($histo[$key]['date']) { $out .= dol_print_date($histo[$key]['date'], 'dayhour'); } else { if ($histo[$key]['datestart']) { $out .= dol_print_date($histo[$key]['datestart'], 'dayhour'); } } $out .= "</td>\n"; // Picto $out .= '<td width="16"> </td>'; // Action $out .= '<td>'; if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') { $actionstatic->type_code = $histo[$key]['acode']; $transcode = $langs->trans("Action" . $histo[$key]['acode']); $libelle = $transcode != "Action" . $histo[$key]['acode'] ? $transcode : $histo[$key]['libelle']; //$actionstatic->libelle=$libelle; $actionstatic->libelle = $histo[$key]['note']; $actionstatic->id = $histo[$key]['id']; $out .= $actionstatic->getNomUrl(1, 40); } if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') { $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/fiche.php?id=' . $histo[$key]['id'] . '">' . img_object($langs->trans("ShowEMailing"), "email") . ' '; $transcode = $langs->trans("Action" . $histo[$key]['acode']); $libelle = $transcode != "Action" . $histo[$key]['acode'] ? $transcode : 'Send mass mailing'; $out .= dol_trunc($libelle, 40); } $out .= '</td>'; // Title of event //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>'; // Objet lie // TODO uniformize $out .= '<td>'; if (isset($histo[$key]['elementtype'])) { if ($histo[$key]['elementtype'] == 'propal' && !empty($conf->propal->enabled)) { $propalstatic->ref = $langs->trans("ProposalShort"); $propalstatic->id = $histo[$key]['fk_element']; $out .= $propalstatic->getNomUrl(1); } elseif ($histo[$key]['elementtype'] == 'commande' && !empty($conf->commande->enabled)) { $orderstatic->ref = $langs->trans("Order"); $orderstatic->id = $histo[$key]['fk_element']; $out .= $orderstatic->getNomUrl(1); } elseif ($histo[$key]['elementtype'] == 'facture' && !empty($conf->facture->enabled)) { $facturestatic->ref = $langs->trans("Invoice"); $facturestatic->id = $histo[$key]['fk_element']; $facturestatic->type = $histo[$key]['ftype']; $out .= $facturestatic->getNomUrl(1, 'compta'); } else { $out .= ' '; } } else { $out .= ' '; } $out .= '</td>'; // Contact pour cette action if (!empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) { $contactstatic->lastname = $histo[$key]['lastname']; $contactstatic->firstname = $histo[$key]['firstname']; $contactstatic->id = $histo[$key]['contact_id']; $out .= '<td width="120">' . $contactstatic->getNomUrl(1, '', 10) . '</td>'; } else { $out .= '<td> </td>'; } // Auteur $out .= '<td class="nowrap" width="80">'; $userstatic->id = $histo[$key]['userid']; $userstatic->login = $histo[$key]['login']; $out .= $userstatic->getLoginUrl(1); $out .= '</td>'; // Statut $out .= '<td class="nowrap" width="20">' . $actionstatic->LibStatut($histo[$key]['percent'], 3) . '</td>'; $out .= "</tr>\n"; $i++; } $out .= "</table>\n"; $out .= "<br>\n"; } if ($noprint) { return $out; } else { print $out; } }
/** * Migration de la table llx_projet_task_actors vers llx_element_contact * * @param DoliDB $db Database handler * @param Translate $langs Object langs * @param Conf $conf Object conf * @return void */ function migrate_project_task_actors($db, $langs, $conf) { dolibarr_install_syslog("upgrade2::migrate_project_task_actors"); print '<tr><td colspan="4">'; print '<br>'; print '<b>' . $langs->trans('MigrationProjectTaskActors') . "</b><br>\n"; if ($db->DDLInfoTable(MAIN_DB_PREFIX . "projet_task_actors")) { $error = 0; $db->begin(); $sql = "SELECT fk_projet_task, fk_user FROM " . MAIN_DB_PREFIX . "projet_task_actors"; $resql = $db->query($sql); if ($resql) { $i = 0; $num = $db->num_rows($resql); if ($num) { while ($i < $num) { $obj = $db->fetch_object($resql); $sql2 = "INSERT INTO " . MAIN_DB_PREFIX . "element_contact ("; $sql2 .= "datecreate"; $sql2 .= ", statut"; $sql2 .= ", element_id"; $sql2 .= ", fk_c_type_contact"; $sql2 .= ", fk_socpeople"; $sql2 .= ") VALUES ("; $sql2 .= "'" . $db->idate(dol_now()) . "'"; $sql2 .= ", '4'"; $sql2 .= ", " . $obj->fk_projet_task; $sql2 .= ", '180'"; $sql2 .= ", " . $obj->fk_user; $sql2 .= ")"; $resql2 = $db->query($sql2); if (!$resql2) { $error++; dol_print_error($db); } print ". "; $i++; } } if ($error == 0) { $sqlDrop = "DROP TABLE " . MAIN_DB_PREFIX . "projet_task_actors"; if ($db->query($sqlDrop)) { $db->commit(); } else { $db->rollback(); } } else { $db->rollback(); } } else { dol_print_error($db); $db->rollback(); } } else { print $langs->trans('AlreadyDone') . "<br>\n"; } print '</td></tr>'; }
/** * Return HTML table with list of projects and number of opened tasks * * @param DoliDB $db Database handler * @param Form $form Object form * @param int $socid Id thirdparty * @param int $projectsListId Id of project i have permission on * @param int $mytasks Limited to task i am contact to * @param int $statut -1=No filter on statut, 0 or 1 = Filter on status * @param array $listofoppstatus List of opportunity status * @return void */ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $statut = -1, $listofoppstatus = array()) { global $langs, $conf, $user, $bc; require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; $projectstatic = new Project($db); $sortfield = ''; $sortorder = ''; $project_year_filter = 0; $title = $langs->trans("Projects"); if (strcmp($statut, '') && $statut >= 0) { $title = $langs->trans("Projects") . ' ' . $langs->trans($projectstatic->statuts_long[$statut]); } print '<table class="noborder" width="100%">'; print '<tr class="liste_titre">'; print_liste_field_titre($title, "index.php", "", "", "", "", $sortfield, $sortorder); if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print_liste_field_titre($langs->trans("OpportunityAmount"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("OpportunityStatus"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } if (empty($conf->global->PROJECT_HIDE_TASKS)) { print_liste_field_titre($langs->trans("Tasks"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } print_liste_field_titre($langs->trans("Status"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print "</tr>\n"; $sql = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount, COUNT(DISTINCT t.rowid) as nb"; // We use DISTINCT here because line can be doubled if task has 2 links to same user $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p"; if ($mytasks) { $sql .= ", " . MAIN_DB_PREFIX . "projet_task as t"; $sql .= ", " . MAIN_DB_PREFIX . "element_contact as ec"; $sql .= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc"; } else { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as t ON p.rowid = t.fk_projet"; } $sql .= " WHERE p.entity = " . $conf->entity; $sql .= " AND p.rowid IN (" . $projectsListId . ")"; if ($socid) { $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")"; } if ($mytasks) { $sql .= " AND p.rowid = t.fk_projet"; $sql .= " AND ec.element_id = t.rowid"; $sql .= " AND ctc.rowid = ec.fk_c_type_contact"; $sql .= " AND ctc.element = 'project_task'"; $sql .= " AND ec.fk_socpeople = " . $user->id; } if ($statut >= 0) { $sql .= " AND p.fk_statut = " . $statut; } if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { $project_year_filter = GETPOST("project_year_filter"); //Check if empty or invalid year. Wildcard ignores the sql check if ($project_year_filter != "*") { if (empty($project_year_filter) || !ctype_digit($project_year_filter)) { $project_year_filter = date("Y"); } $sql .= " AND (p.dateo IS NULL OR p.dateo <= " . $db->idate(dol_get_last_day($project_year_filter, 12, false)) . ")"; $sql .= " AND (p.datee IS NULL OR p.datee >= " . $db->idate(dol_get_first_day($project_year_filter, 1, false)) . ")"; } } $sql .= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount"; $sql .= " ORDER BY p.title, p.ref"; $var = true; $resql = $db->query($sql); if ($resql) { $total_task = 0; $total_opp_amount = 0; $ponderated_opp_amount = 0; $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $objp = $db->fetch_object($resql); $projectstatic->id = $objp->projectid; $projectstatic->user_author_id = $objp->fk_user_creat; $projectstatic->public = $objp->public; // Check is user has read permission on project $userAccess = $projectstatic->restrictedProjectArea($user); if ($userAccess >= 0) { $var = !$var; print "<tr " . $bc[$var] . ">"; print '<td class="nowrap">'; $projectstatic->ref = $objp->ref; print $projectstatic->getNomUrl(1); print ' - ' . dol_trunc($objp->title, 24) . '</td>'; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print '<td align="right">'; if ($objp->opp_amount) { print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency); } print '</td>'; print '<td align="right">'; $code = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code'); if ($code) { print $langs->trans("OppStatus" . $code); } print '</td>'; } $projectstatic->statut = $objp->status; if (empty($conf->global->PROJECT_HIDE_TASKS)) { print '<td align="right">' . $objp->nb . '</td>'; } print '<td align="right">' . $projectstatic->getLibStatut(3) . '</td>'; print "</tr>\n"; $total_task = $total_task + $objp->nb; $total_opp_amount = $total_opp_amount + $objp->opp_amount; $ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$objp->opp_status] * $objp->opp_amount / 100); } $i++; } print '<tr><td>' . $langs->trans("Total") . "</td>"; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print '<td align="right">' . price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency) . '</td>'; print '<td align="right">' . $form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmount"), 1) . '</td>'; } if (empty($conf->global->PROJECT_HIDE_TASKS)) { print '<td align="right">' . $total_task . '</td>'; } $db->free($resql); } else { dol_print_error($db); } print "</table>"; if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { //Add the year filter input print '<form method="get" action="' . $_SERVER["PHP_SELF"] . '">'; print '<table width="100%">'; print '<tr>'; print '<td>' . $langs->trans("Year") . '</td>'; print '<td style="text-align:right"><input type="text" size="4" class="flat" name="project_year_filter" value="' . $project_year_filter . '"/>'; print "</tr>\n"; print '</table></form>'; } }
/** * Return HTML table with list of projects and number of opened tasks * * @param DoliDB $db Database handler * @param int $socid Id thirdparty * @param int $projectsListId Id of project i have permission on * @param int $mytasks Limited to task i am contact to * @param int $statut -1=No filter on statut, 0 or 1 = Filter on status * @return void */ function print_projecttasks_array($db, $socid, $projectsListId, $mytasks = 0, $statut = -1) { global $langs, $conf, $user, $bc; require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; $projectstatic = new Project($db); $sortfield = ''; $sortorder = ''; $project_year_filter = 0; $title = $langs->trans("Project"); if ($statut == 0) { $title = $langs->trans("ProjectDraft"); } if ($statut == 1) { $title = $langs->trans("Project") . ' (' . $langs->trans("Validated") . ')'; } print '<table class="noborder" width="100%">'; print '<tr class="liste_titre">'; print_liste_field_titre($title, "index.php", "", "", "", "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Tasks"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Status"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print "</tr>\n"; $sql = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut, COUNT(t.rowid) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p"; if ($mytasks) { $sql .= ", " . MAIN_DB_PREFIX . "projet_task as t"; $sql .= ", " . MAIN_DB_PREFIX . "element_contact as ec"; $sql .= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc"; } else { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as t ON p.rowid = t.fk_projet"; } $sql .= " WHERE p.entity = " . $conf->entity; $sql .= " AND p.rowid IN (" . $projectsListId . ")"; if ($socid) { $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")"; } if ($mytasks) { $sql .= " AND p.rowid = t.fk_projet"; $sql .= " AND ec.element_id = t.rowid"; $sql .= " AND ctc.rowid = ec.fk_c_type_contact"; $sql .= " AND ctc.element = 'project_task'"; $sql .= " AND ec.fk_socpeople = " . $user->id; } if ($statut >= 0) { $sql .= " AND p.fk_statut = " . $statut; } if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { $project_year_filter = GETPOST("project_year_filter"); //Check if empty or invalid year. Wildcard ignores the sql check if ($project_year_filter != "*") { if (empty($project_year_filter) || !ctype_digit($project_year_filter)) { // $project_year_filter = date("Y"); } $sql .= " AND (p.dateo IS NULL OR p.dateo <= " . $db->idate(dol_get_last_day($project_year_filter, 12, false)) . ")"; $sql .= " AND (p.datee IS NULL OR p.datee >= " . $db->idate(dol_get_first_day($project_year_filter, 1, false)) . ")"; } } $sql .= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut"; $sql .= " ORDER BY p.title, p.ref"; $var = true; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $objp = $db->fetch_object($resql); $projectstatic->id = $objp->projectid; $projectstatic->user_author_id = $objp->fk_user_creat; $projectstatic->public = $objp->public; // Check is user has read permission on project $userAccess = $projectstatic->restrictedProjectArea($user); if ($userAccess >= 0) { $var = !$var; print "<tr " . $bc[$var] . ">"; print '<td class="nowrap">'; $projectstatic->ref = $objp->ref; print $projectstatic->getNomUrl(1); print ' - ' . dol_trunc($objp->title, 24) . '</td>'; print '<td align="right">' . $objp->nb . '</td>'; $projectstatic->statut = $objp->fk_statut; print '<td align="right">' . $projectstatic->getLibStatut(3) . '</td>'; print "</tr>\n"; } $i++; } $db->free($resql); } else { dol_print_error($db); } print "</table>"; if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { //Add the year filter input print '<table width="100%">'; print '<tr>'; print '<td>' . $langs->trans("Year") . '</td>'; print '<form method="get" action="' . $_SERVER["PHP_SELF"] . '">'; print '<td style="text-align:right"><input type="text" size="4" class="flat" name="project_year_filter" value="' . $project_year_filter . '"/>'; print '</form>'; print "</tr>\n"; print '</table>'; } }