$nodays = finddaysinFeb($mthend, $yearend);
    $dateto = "{$yearend}-{$mthend}-{$nodays}";
} else {
    $datefrom = $date1;
    $dateto = $date2;
}
################################################################
#	PROJECT REPORT
if ($proj) {
    $rptstr = "Project Report";
} elseif ($rsc) {
    $rptstr = "Resource Report";
}
$title = "{$rptstr} Period from {$datefrom} to {$dateto}";
if ($proj || $rsc) {
    reportline1($title);
    findmonthlist($datefrom, $dateto);
    for ($i = 0; $i < $mthno; $i++) {
        $podmthno = $mthno;
        $podmonthlist[$i] = $monthlist[$i];
    }
    $title0 = $email_name . "_" . ereg_replace(" ", "_", $title) . ".csv";
    $rptweburl = "/report/{$title0}";
    $rptserverfile = "/usr/local/apache/htdocs/report/{$title0}";
    //echo "<center><a href=\"$rptweburl\"><b>Download CSV file</b></a></center><br><br>";
    echo "<a href=\"{$rptweburl}\"><b>Download CSV file</b></a><br><br>";
    $csvfh = fopen($rptserverfile, "w");
    fputs($csvfh, $title . "\n");
}
//casethismth		caselastmth	caseyear	caseany
if ($proj && $caseany) {
         for ($j = 0; $j < $noprojsel; $j++) {
             if ($projectlist[$j] == $projcodelist[$i][0]) {
                 //echo $projectlist[$j].": ".$projcodelist[$projectlist[$j]][2]."<br>";
                 $selected = 1;
                 break;
             }
         }
         if (!$selected) {
             $projcodelist[$i][0] = 0;
         }
     }
 }
 if ($timeframe == "y") {
     echo reportline1("Order search for period from {$datefrom} to {$dateto}.");
 } else {
     echo reportline1("Order search result for all time.");
 }
 $totalorder = 0;
 $totalrec = 0;
 echo "<table border=1>";
 echo "<tr><th>Project</th><th>Ordered</th><th>Received</th><th>Not Received</tr>";
 for ($i = 0; $i < $noproj; $i++) {
     $rlaprojid = $projcodelist[$i][0];
     $brief_code = $projcodelist[$i][1];
     if ($rlaprojid) {
         //echo "$rlaprojid $brief_code<br>";
         $sql = "SELECT sum(t1.unit*t1.unit_price) as totcostreceived \n        \t\tFROM rlafinance.orderdetails as t1, rlafinance.orderid as t2\n        \t\tWHERE t1.rlaprojid='{$rlaprojid}'\n        \t\t\t\tand t1.order_id=t2.order_id and t2.ordercancelled='n' \n        \t\t\t\tand t2.updatestatus='f'";
         if ($timeframe == "y") {
             //search for all time
             $sql .= "and t2.orderdate>='{$datefrom}' and t2.orderdate<='{$dateto}'";
             //$datefrom to $dateto
                        $strarray[$k] = "&nbsp;";
                    }
                    echo "<th align=left>" . $strarray[$k] . "</th>";
                }
                echo "<td>" . $strarray[$colno] . "</td></tr>";
            }
        }
        echo "</table><p>";
        #echo "$budgetfile<br>";
        $sep = "<b>=============================================================================</b><p>";
        echo "{$sep}";
        $i++;
    }
} elseif ($thismonthexecution) {
    $thismonth = date("F Y");
    reportline1("Project Summary for {$thismonth}.");
    $todaydate = date("Y-m-d");
    if ($priv == "00" || $priv == "10") {
        $sql = "SELECT t1.email_name as ename, t1.projcode_id, t1.phaseno, \n            t1.budgetfile, t1.dateinrow, t1.budgetstart, t1.budgetend, \n            t1.actualstart, t1.actualend,\n            t2.brief_code\n        FROM timesheet.projbudgetfile as t1, timesheet.projcodes as t2\n        WHERE t1.budgetstart<='{$todaydate}' and t1.budgetend>='{$todaydate}' and t1.neworold='y'\n        \tand t1.projcode_id=t2.projcode_id \n        ORDER BY t2.brief_code;";
    } elseif ($priv == "50") {
        $sql = "SELECT t1.email_name as ename, t1.projcode_id, t1.phaseno, \n            t1.budgetfile, t1.dateinrow, t1.budgetstart, t1.budgetend, \n            t1.actualstart, t1.actualend,\n            t2.brief_code\n        FROM timesheet.projbudgetfile as t1, timesheet.projcodes as t2\n        WHERE t1.budgetstart<='{$todaydate}' and t1.budgetend>='{$todaydate}' and t1.neworold='y'\n        \tand t1.projcode_id=t2.projcode_id and t1.email_name='{$email_name}'\n        ORDER BY t2.brief_code;";
    }
    $result = mysql_query($sql);
    include "err_msg.inc";
    $no = mysql_num_rows($result);
    $i = 1;
    echo "<table border=1>";
    $projtotalmonthbudgeted = 0;
    $projtotalmonthreal = 0;
    while (list($ename, $projcode_id, $phaseno, $budgetfile, $dateinrow, $budgetstart, $budgetend, $actualstart, $actualend, $brief_code) = mysql_fetch_array($result)) {
        echo "<tr><th align=left colspan=7>Project {$i}: {$brief_code}, Phase {$phaseno}</th></tr>";