Exemple #1
0
/**	Return next week
 *
 *  @param      int			$day     	Day
 *  @param      int			$week    	Week
 *  @param      int			$month   	Month
 *	@param		int			$year		Year
 *	@return		array					Next year,month,day
 */
function dol_get_next_week($day, $week, $month, $year)
{
    $tmparray = dol_get_first_day_week($day, $month, $year);
    $time = dol_mktime(12, 0, 0, $month, $tmparray['first_day'], $year, 1, 0);
    $time += 24 * 60 * 60 * 7;
    $tmparray = dol_getdate($time, true);
    return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
}
Exemple #2
0
    $param .= "&socid=" . $socid;
}
if ($showbirthday) {
    $param .= "&showbirthday=1";
}
if ($pid) {
    $param .= "&projectid=" . $pid;
}
if ($type) {
    $param .= "&type=" . $type;
}
if ($action == 'show_day' || $action == 'show_week' || $action == 'show_month' || $action != 'show_peruser') {
    $param .= '&action=' . $action;
}
$param .= "&maxprint=" . $maxprint;
$prev = dol_get_first_day_week($day, $month, $year);
//print "day=".$day." month=".$month." year=".$year;
//var_dump($prev); exit;
$prev_year = $prev['prev_year'];
$prev_month = $prev['prev_month'];
$prev_day = $prev['prev_day'];
$first_day = $prev['first_day'];
$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)
 /**
  *
  * 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);
     }
 }
Exemple #4
0
/**
 * Show box
 *
 * @param	string	$selectedDate	Date YYYMMDD
 * @param	int		$month			Month
 * @param 	int		$year			Year
 * @return	void
 */
function displayBox($selectedDate, $month, $year)
{
    global $langs, $conf;
    //print "$selectedDate,$month,$year";
    $thedate = dol_mktime(12, 0, 0, $month, 1, $year);
    //print "thedate=$thedate";
    $today = dol_now();
    $todayArray = dol_getdate($today);
    if ($selectedDate != "00000000") {
        $selDate = xyzToUnixTimestamp($selectedDate);
        $xyz = dol_print_date($selDate, "%Y%m%d");
    } else {
        $selDate = 0;
        $xyz = 0;
    }
    ?>
<table class="dp">
	<tr>
		<td colspan="6" class="dpHead"><?php 
    $selectMonth = dol_print_date($thedate, '%m');
    $selectYear = dol_print_date($thedate, '%Y');
    echo $langs->trans("Month" . $selectMonth) . ", " . $selectYear;
    ?>
</td>
		<td class="dpHead">
		<button type="button" class="dpInvisibleButtons" id="DPCancel"
			onClick="closeDPBox();">X</button>
		</td>
	</tr>
	<tr>
		<td class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    echo $month;
    ?>
','<?php 
    echo $year - 1;
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')">&lt;&lt;</td>
		<td class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    if ($month == 1) {
        echo "12";
    } else {
        echo $month - 1;
    }
    ?>
','<?php 
    if ($month == 1) {
        echo $year - 1;
    } else {
        echo $year;
    }
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')">&lt;</td>
		<td colspan="3" class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    echo (int) dol_print_date($today, '%m');
    ?>
','<?php 
    echo $todayArray["year"];
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')"><?php 
    echo '-';
    ?>
</td>
		<td class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    if ($month == 12) {
        echo "1";
    } else {
        echo $month + 1;
    }
    ?>
','<?php 
    if ($month == 12) {
        echo $year + 1;
    } else {
        echo $year;
    }
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')">&gt;</td>
		<td class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    echo $month;
    ?>
','<?php 
    echo $year + 1;
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')">&gt;&gt;</td>
	</tr>
	<tr class="dpDayNames">
	<?php 
    $startday = isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1;
    $day_names = array('ShortSunday', 'ShortMonday', 'ShortTuesday', 'ShortWednesday', 'ShortThursday', 'ShortFriday', 'ShortSaturday');
    for ($i = 0; $i < 7; $i++) {
        echo '<td width="', (int) (($i + 1) * 100 / 7) - (int) ($i * 100 / 7), '%">', $langs->trans($day_names[($i + $startday) % 7]), '</td>', "\n";
    }
    ?>
	
	</tr>
	<?php 
    //print "x ".$thedate." y";			// $thedate = first day of month
    $firstdate = dol_getdate($thedate);
    //var_dump($firstdateofweek);
    $mydate = dol_get_first_day_week(1, $month, $year, true);
    // mydate = cursor date
    // Loop on each day of month
    $stoploop = 0;
    $day = 1;
    $cols = 0;
    while (!$stoploop) {
        //print_r($mydate);
        if ($mydate < $firstdate) {
            echo "<TR class=\"dpWeek\">";
            //echo $conf->global->MAIN_START_WEEK.' '.$firstdate["wday"].' '.$startday;
            $cols = 0;
            for ($i = 0; $i < 7; $i++) {
                $w = ($i + $startday) % 7;
                if ($w == $firstdate["wday"]) {
                    $mydate = $firstdate;
                    break;
                }
                echo "<TD>&nbsp;</TD>";
                $cols++;
            }
        } else {
            if ($mydate["wday"] == $startday) {
                echo "<TR class=\"dpWeek\">";
                $cols = 0;
            }
        }
        $dayclass = "dpReg";
        if ($thedate == $selDate) {
            $dayclass = "dpSelected";
        } elseif ($thedate == $today) {
            $dayclass = "dpToday";
        }
        if ($langs->trans("FormatDateShortJavaInput") == "FormatDateShortJavaInput") {
            print "ERROR FormatDateShortJavaInput not defined for language " . $langs->defaultlang;
            exit;
        }
        // Sur click dans calendrier, appelle fonction dpClickDay
        echo "<TD class=\"" . $dayclass . "\"";
        echo " onMouseOver=\"dpHighlightDay(" . $mydate["year"] . ",parseInt('" . dol_print_date($thedate, "%m") . "',10)," . $mydate["mday"] . ",tradMonths)\"";
        echo " onClick=\"dpClickDay(" . $mydate["year"] . ",parseInt('" . dol_print_date($thedate, "%m") . "',10)," . $mydate["mday"] . ",'" . $langs->trans("FormatDateShortJavaInput") . "')\"";
        echo ">" . sprintf("%02s", $mydate["mday"]) . "</TD>";
        $cols++;
        if (($mydate["wday"] + 1) % 7 == $startday) {
            echo "</TR>\n";
        }
        //$thedate=strtotime("tomorrow",$thedate);
        $day++;
        $thedate = dol_mktime(12, 0, 0, $month, $day, $year);
        if ($thedate == '') {
            $stoploop = 1;
        } else {
            $mydate = dol_getdate($thedate);
            if ($firstdate["month"] != $mydate["month"]) {
                $stoploop = 1;
            }
        }
    }
    if ($cols < 7) {
        for ($i = 6; $i >= $cols; $i--) {
            echo "<TD>&nbsp;</TD>";
        }
        echo "</TR>\n";
    }
    ?>
	<tr>
		<td id="dpExp" class="dpExplanation" colspan="7"><?php 
    if ($selDate) {
        $tempDate = dol_getdate($selDate);
        print $langs->trans("Month" . $selectMonth) . " ";
        print sprintf("%02s", $tempDate["mday"]);
        print ", " . $selectYear;
    } else {
        print "Click a Date";
    }
    ?>
</td>
	</tr>
</table>
		<?php 
}
Exemple #5
0
$socid = 0;
if ($user->societe_id > 0) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'projet', $projectid);
$now = dol_now();
$nowtmp = dol_getdate($now);
$nowday = $nowtmp['mday'];
$nowmonth = $nowtmp['mon'];
$nowyear = $nowtmp['year'];
$year = GETPOST('reyear') ? GETPOST('reyear') : (GETPOST("year", "int") ? GETPOST("year", "int") : date("Y"));
$month = GETPOST('remonth') ? GETPOST('remonth') : (GETPOST("month", "int") ? GETPOST("month", "int") : date("m"));
$day = GETPOST('reday') ? GETPOST('reday') : (GETPOST("day", "int") ? GETPOST("day", "int") : date("d"));
$day = (int) $day;
$week = GETPOST("week", "int") ? GETPOST("week", "int") : date("W");
$startdayarray = dol_get_first_day_week($day, $month, $year);
$prev = $startdayarray;
$prev_year = $prev['prev_year'];
$prev_month = $prev['prev_month'];
$prev_day = $prev['prev_day'];
$first_day = $prev['first_day'];
$first_month = $prev['first_month'];
$first_year = $prev['first_year'];
$week = $prev['week'];
$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');
Exemple #6
0
 /**
  * testDolGetFirstDayWeek
  *
  * @return int
  */
 public function testDolGetFirstDayWeek()
 {
     global $conf;
     $day = 3;
     $month = 2;
     $year = 2015;
     $conf->global->MAIN_START_WEEK = 1;
     // start on monday
     $prev = dol_get_first_day_week($day, $month, $year);
     $this->assertEquals(2, (int) $prev['first_day']);
     // monday for month 2, year 2014 is the 2
     $day = 3;
     $month = 2;
     $year = 2015;
     $conf->global->MAIN_START_WEEK = 0;
     // start on sunday
     $prev = dol_get_first_day_week($day, $month, $year);
     $this->assertEquals(1, (int) $prev['first_day']);
     // sunday for month 2, year 2015 is the 1st
 }