Esempio n. 1
0
    while ($i < $MAXAGENDA) {
        $i++;
        $source = 'AGENDA_EXT_SRC_' . $user->id . '_' . $i;
        $name = 'AGENDA_EXT_NAME_' . $user->id . '_' . $i;
        $offsettz = 'AGENDA_EXT_OFFSETTZ_' . $user->id . '_' . $i;
        $color = 'AGENDA_EXT_COLOR_' . $user->id . '_' . $i;
        $enabled = 'AGENDA_EXT_ENABLED_' . $user->id . '_' . $i;
        $buggedfile = 'AGENDA_EXT_BUGGEDFILE_' . $user->id . '_' . $i;
        if (!empty($user->conf->{$source}) && !empty($user->conf->{$name})) {
            // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
            $listofextcals[] = array('src' => $user->conf->{$source}, 'name' => $user->conf->{$name}, 'offsettz' => $user->conf->{$offsettz}, 'color' => $user->conf->{$color}, 'buggedfile' => isset($user->conf->buggedfile) ? $user->conf->buggedfile : 0);
        }
    }
}
if (empty($action) || $action == 'show_month') {
    $prev = dol_get_prev_month($month, $year);
    $prev_year = $prev['year'];
    $prev_month = $prev['month'];
    $next = dol_get_next_month($month, $year);
    $next_year = $next['year'];
    $next_month = $next['month'];
    $max_day_in_prev_month = date("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year));
    // Nb of days in previous month
    $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year));
    // Nb of days in next month
    // tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
    $tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, true)) + 2;
    // date('w') is 0 fo sunday
    $tmpday += (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1;
    if ($tmpday >= 1) {
        $tmpday -= 7;
 /**
  *
  * Count Facture history
  *
  */
 public static function countHistoricFac()
 {
     global $db, $conf, $user;
     $ret = -1;
     $function = "GetHistoric";
     $sql = 'SELECT (SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******" AND pf.fk_cash IN (";
         $sql2 .= "SELECT pu.fk_terminal FROM " . MAIN_DB_PREFIX . "pos_users as pu WHERE pu.fk_object = " . $_SESSION["uid"] . " AND pu.objtype = 'user'";
         $sql2 .= " UNION SELECT pu.fk_terminal FROM " . MAIN_DB_PREFIX . "pos_users as pu LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ug ON pu.fk_object = ug.fk_usergroup";
         $sql2 .= " WHERE ug.fk_user = "******"uid"] . " AND pu.objtype = 'group')";
     }
     $sql .= $sql2;
     $now = dol_now();
     $time = dol_getdate($now);
     $day = $time['mday'];
     $month = $time['mon'];
     $year = $time['year'];
     //Today
     $todayini = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 0, 0, 0);
     $todayfin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $todayini . "' AND '" . $todayfin . "' ) as today, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], $time['day'], 0, 0, 0);
     $yestfin = sprintf("%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], $time['day'], 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $yestini . "' AND '" . $yestfin . "' ) as yesterday, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], $time['first_day'], 0, 0, 0);
     $weekfin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $weekini . "' AND '" . $weekfin . "' ) as thisweek, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['prev_year'], $time['prev_month'], $time['prev_day'], 0, 0, 0);
     $lweekfin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $time['first_day'] - 1 == 0 ? $time['prev_month'] : $month, $time['first_day'] - 1 == 0 ? $time['prev_day'] + 6 : $time['first_day'] - 1, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $lweekini . "' AND '" . $lweekfin . "' ) as lastweek, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time2['year'], $time2['month'], $time2['day'], 0, 0, 0);
     $fin2week = sprintf("%04d%02d%02d%02d%02d%02d", $time['year'], $time['day'] - 1 == 0 ? $time2['month'] : $time['month'], $time['day'] - 1 == 0 ? $time2['day'] + 6 : $time['day'] - 1, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $ini2week . "' AND '" . $fin2week . "' ) as twoweek, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time2['year'], $time2['month'], $time2['day'], 0, 0, 0);
     $fin3week = sprintf("%04d%02d%02d%02d%02d%02d", $time['year'], $time['day'] - 1 == 0 ? $time2['month'] : $time['month'], $time['day'] - 1 == 0 ? $time2['day'] + 6 : $time['day'] - 1, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $ini3week . "' AND '" . $fin3week . "' ) as threeweek, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $year, $month, 01, 0, 0, 0);
     $monthfin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $monthini . "' AND '" . $monthfin . "' ) as thismonth, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], $day, 0, 0, 0);
     $monthagofin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $monthagoini . "' AND '" . $monthagofin . "' ) as monthago, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], 01, 0, 0, 0);
     $lmonthfin = sprintf("%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], 31, 0, 0, 0);
     $sql .= " AND f.datec BETWEEN '" . $lmonthini . "' AND '" . $lmonthfin . "' ) as lastmonth";
     $res = $db->query($sql);
     if ($res) {
         $obj = $db->fetch_object($res);
         $result["today"] = $obj->today;
         $result["yesterday"] = $obj->yesterday;
         $result["thisweek"] = $obj->thisweek;
         $result["lastweek"] = $obj->lastweek;
         $result["twoweek"] = $obj->twoweek;
         $result["threeweek"] = $obj->threeweek;
         $result["thismonth"] = $obj->thismonth;
         $result["monthago"] = $obj->monthago;
         $result["lastmonth"] = $obj->lastmonth;
         return ErrorControl($result, $function);
     } else {
         return ErrorControl($ret, $function);
     }
 }