예제 #1
0
파일: index.php 프로젝트: Albertopf/prueba
    $first_month = $prev['first_month'];
    $first_year = $prev['first_year'];
    $week = $prev['week'];
    $day = (int) $day;
    $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
    $next_year = $next['year'];
    $next_month = $next['month'];
    $next_day = $next['day'];
    // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
    $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year);
    $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
    $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year));
    $tmpday = $first_day;
}
if ($action == 'show_day') {
    $prev = dol_get_prev_day($day, $month, $year);
    $prev_year = $prev['year'];
    $prev_month = $prev['month'];
    $prev_day = $prev['day'];
    $next = dol_get_next_day($day, $month, $year);
    $next_year = $next['year'];
    $next_month = $next['month'];
    $next_day = $next['day'];
    // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
    $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $prev_day, $prev_year);
    $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year);
}
//print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
//print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
//print dol_print_date($firstdaytoshow,'day');
//print dol_print_date($lastdaytoshow,'day');
 /**
  *
  * 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);
     }
 }