$datediff = floor(strtotime($frmdt) / (60 * 60 * 24)) - floor(strtotime($todt) / (60 * 60 * 24)); $leaveDays = abs($datediff) + 1; $totalLeave = $totalLeave + $leaveDays - isSunday($frmdt, $todt); //echo "Total Leave : ".$totalLeave."\n"; } else { if ($dateFrom === $month && $dateTo !== $month) { $leaveDays = date('t', strtotime($dta[$i]['leaveFrom'])) - date('j', strtotime($dta[$i]['leaveFrom'])); /*echo $leaveDays."\n"; echo "From Date : ".date('j', strtotime($dta[$i]['leaveFrom']))."-".$month." To Date : ".date('t', strtotime($dta[$i]['leaveFrom']))."-".$month." >>";*/ $totalLeave = $totalLeave + $leaveDays + 1 - isSunday(date('j', strtotime($dta[$i]['leaveFrom'])) . "-" . $month, date('t', strtotime($dta[$i]['leaveFrom'])) . "-" . $month); //echo "Total Leave : ".$totalLeave."\n"; } else { if ($dateFrom !== $month && $dateTo === $month) { $workingDays = date('t', strtotime($dta[$i]['leaveTo'])) - date('j', strtotime($dta[$i]['leaveTo'])); $leaveDays = date('t', strtotime($dta[$i]['leaveTo'])) - (int) $workingDays; $totalLeave = $totalLeave + $leaveDays - isSunday("01-" . $month, $dta[$i]['leaveTo']); } } } /*if ($dateRcvd === $month){ echo $dateRcvd ."=".$month."\n"; }*/ $i++; } $TotalDays = cal_days_in_month(CAL_GREGORIAN, date("d", strtotime($monthY)), date("Y", strtotime($monthY))); /*echo "var : ".$monthY." Month : ".date("d",strtotime($monthY))." And Year :".date("Y",strtotime($monthY)); echo "total Leave taken in this month ".$totalLeave."And total days :".$TotalDays;*/ if ($totalLeave > 2) { $totalLeave = $totalLeave - 2; } else { $totalLeave = 0;
session_start(); //p_array($_REQUEST); //p_array($_SESSION); $brokerId = $_REQUEST['brokerId']; $driverId = $_REQUEST['driverId']; $fromDate = to_YMD($_REQUEST['reportStartDate']); $toDate = $_REQUEST['reportEndDate'] != "" ? to_YMD($_REQUEST['reportEndDate']) : date('Y-m-d'); //$fromDate = '2012-11-05'; //$toDate = '2013-02-10'; //echo $fromDate; //echo "<br/>"; //echo $toDate; //echo "<br/>"; //$firstSunday = strtotime('last Sunday', strtotime($fromDate)); //echo date('Y-m-d',$firstSunday); $firstSunday = isSunday($fromDate) ? $fromDate : lastSunday($fromDate); //echo $firstSunday; $thisSunday = $firstSunday; $nextSaturday = getNextSaturday($fromDate); while (strtotime($thisSunday) <= strtotime($toDate)) { //echo $thisSunday." __ ".$nextSaturday."<br/>"; //check for tickets $queryTickets = "\r\n\t\tSELECT\r\n\t\t\t*\r\n\t\tFROM\r\n\t\t\tticket\r\n\t\t\tJOIN truck using (truckId)\r\n\t\t\tLEFT JOIN reportticket using (ticketId)\r\n\t\tWHERE\r\n\t\t\tticketDate BETWEEN '{$thisSunday}' AND '{$nextSaturday}'\r\n\t\t\tAND reportId is null\r\n\t\t\tAND brokerId = {$brokerId} \r\n\t\t\t" . ($driverId != 0 ? " AND driverId = " . $driverId : "") . "\r\n\t"; //echo $queryTickets."<br/>"; $ticketsForReport = mysql_query($queryTickets, $conexion); if (mysql_num_rows($ticketsForReport) >= 1) { //echo "si hay sueltos<br/>"; $queryInvoice = "\r\n\t\t\tINSERT INTO report (\r\n\t\t\t\treportDate,\r\n\t\t\t\tbrokerId,\r\n\t\t\t\treportStartDate,\r\n\t\t\t\treportEndDate,\r\n\t\t\t\treportType\r\n\t\t\t)\r\n\t\t\tvalues (\r\n\t\t\t\tCURDATE(),\r\n\t\t\t\t" . $_REQUEST['brokerId'] . ",\r\n\t\t\t\t'{$thisSunday}',\r\n\t\t\t\t'{$nextSaturday}',\r\n\t\t\t\t" . $_REQUEST['driverId'] . "\r\n\t\t\t)"; mysql_query($queryInvoice, $conexion); $reportId = mysql_insert_id(); $insertTickets = "\r\n\t\t\tINSERT INTO reportticket(\r\n\t\t\t\tticketId,\r\n\t\t\t\treportId\r\n\t\t\t)\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tticketId,\r\n\t\t\t\t\t" . $reportId . "\r\n\t\t\t\tFROM\r\n\t\t\t\t\tticket\r\n\t\t\t\t\tJOIN truck using (truckId)\r\n\t\t\t\t\tLEFT JOIN reportticket using (ticketId)\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tticketDate BETWEEN '{$thisSunday}' AND '{$nextSaturday}'\r\n\t\t\t\t\tAND reportId is null\r\n\t\t\t\t\tAND brokerId = {$brokerId} \r\n\t\t\t\t\t" . ($driverId != 0 ? " AND driverId = " . $driverId : "") . "\r\n\t\t";