Ver código fonte

fix for year number

Jad Meouchy 8 anos atrás
pai
commit
8789c558e1
2 arquivos alterados com 12 adições e 4 exclusões
  1. 4 1
      cron/ftpwriter.php
  2. 8 3
      db.php

+ 4 - 1
cron/ftpwriter.php

@@ -39,12 +39,14 @@ $stmt = $dbh->prepare(
 			SELECT id_file_row
 			FROM file_row_update
 			WHERE WEEK(date_modified) = WEEK(CURRENT_TIMESTAMP)
+			AND YEAR(date_modified) = YEAR(CURRENT_TIMESTAMP)
 		
 			UNION
 			
 			SELECT id_file_row
 			FROM file_row
 			WHERE WEEK(date_processed) = WEEK(CURRENT_TIMESTAMP)
+			AND YEAR(date_processed) = YEAR(CURRENT_TIMESTAMP)
 		)
 	)");
 
@@ -60,12 +62,13 @@ foreach($companies as $company)
 	echo "processing company $company[name]...";
 	
 	$id_company = $company['id_company'];
+	$year = date('Y');
 	$week_number = date('W');
 
 	//make the csv in memory
 	$f = fopen('php://temp/maxmemory:1048576', 'w');
 	
-	getRowsByCompanyCSV($id_company, $f, $week_number);
+	getRowsByCompanyCSV($id_company, $f, $year, $week_number);
 	
 	rewind($f);
 

+ 8 - 3
db.php

@@ -61,7 +61,7 @@ function getCompanyDirectories()
 	return $rows;
 }
 
-function getRowsByCompany($id_company, $week_number = null)
+function getRowsByCompany($id_company, $year = null, $week_number = null)
 {
 	global $dbh;
 	
@@ -161,12 +161,14 @@ function getRowsByCompany($id_company, $week_number = null)
 				SELECT id_file_row
 				FROM file_row_update
 				WHERE WEEK(date_modified) = :week_number
+				AND YEAR(date_modified) = :year
 			
 				UNION
 				
 				SELECT id_file_row
 				FROM file_row
 				WHERE WEEK(date_processed) = :week_number
+				WHERE YEAR(date_processed) = :year
 			)
 		) " : "") .
 		"ORDER BY file_row.date_processed DESC
@@ -175,7 +177,10 @@ function getRowsByCompany($id_company, $week_number = null)
 	$stmt = $dbh->prepare($sql);
 
 	if($week_number)
+	{
 		$stmt->bindValue(':week_number', $week_number);
+		$stmt->bindValue(':year', $year);
+	}
 	
 	$stmt->bindValue(':id_company', $id_company);
 	
@@ -212,9 +217,9 @@ function getRowUpdatesByCompany($id_company)
 	return $rows;
 }
 
-function getRowsByCompanyCSV($id_company, $f, $week_number = null)
+function getRowsByCompanyCSV($id_company, $f, $year, $week_number = null)
 {
-	$file_rows = getRowsByCompany($id_company, $week_number);
+	$file_rows = getRowsByCompany($id_company, $year, $week_number);
 
 	$headers = array('Division', 'Consignee', 'Called In', 'Dispatch #', 'Shipper', 'Ready', 'Address 1', 'Address 2', 'City', 'ST', 'Zip', 'Phone',
 						'', '', '', '',