|
@@ -6,6 +6,7 @@ include 'db.inc.php';
|
|
|
ini_set('memory_limit', '256M');
|
|
ini_set('memory_limit', '256M');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+//for reference!
|
|
|
$columns_to_fields = array(
|
|
$columns_to_fields = array(
|
|
|
'Division' => 'division',
|
|
'Division' => 'division',
|
|
|
'Consignee' => 'consignee',
|
|
'Consignee' => 'consignee',
|
|
@@ -37,10 +38,12 @@ $columns_to_fields = array(
|
|
|
$fields_by_col = array();
|
|
$fields_by_col = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
-processFile('../test.xls', $columns_to_fields);
|
|
|
|
|
|
|
+$id_company = 1;
|
|
|
|
|
|
|
|
|
|
+processFile('../test.xls', $id_company);
|
|
|
|
|
|
|
|
-function processFile($filename_report, $columns_to_fields)
|
|
|
|
|
|
|
+
|
|
|
|
|
+function processFile($filename_report, $id_company)
|
|
|
{
|
|
{
|
|
|
global $dbh;
|
|
global $dbh;
|
|
|
|
|
|
|
@@ -48,7 +51,7 @@ function processFile($filename_report, $columns_to_fields)
|
|
|
//TODO: check if we already processed this file
|
|
//TODO: check if we already processed this file
|
|
|
|
|
|
|
|
|
|
|
|
|
- $stmt = $dbh->prepare('INSERT INTO records (
|
|
|
|
|
|
|
+ $stmt = $dbh->prepare("INSERT INTO records (
|
|
|
id_company,
|
|
id_company,
|
|
|
division, consignee, date_called_in, dispatch_number, shipper, date_ready,
|
|
division, consignee, date_called_in, dispatch_number, shipper, date_ready,
|
|
|
address_1, address_2, city, state, zip, phone,
|
|
address_1, address_2, city, state, zip, phone,
|
|
@@ -57,12 +60,12 @@ function processFile($filename_report, $columns_to_fields)
|
|
|
ctns, weight, cube
|
|
ctns, weight, cube
|
|
|
) VALUES (
|
|
) VALUES (
|
|
|
:id_company,
|
|
:id_company,
|
|
|
- :division, :consignee, :date_called_in, :dispatch_number, :shipper, :date_ready,
|
|
|
|
|
|
|
+ :division, :consignee, STR_TO_DATE(:date_called_in, '%m/%d/%Y'), :dispatch_number, :shipper, STR_TO_DATE(:date_ready, '%m/%d/%Y'),
|
|
|
:address_1, :address_2, :city, :state, :zip, :phone,
|
|
:address_1, :address_2, :city, :state, :zip, :phone,
|
|
|
:time_ready, :time_close, :time_pickup, :time_depart, :bol_delivered,
|
|
:time_ready, :time_close, :time_pickup, :time_depart, :bol_delivered,
|
|
|
:dispatch_reference,
|
|
:dispatch_reference,
|
|
|
:ctns, :weight, :cube
|
|
:ctns, :weight, :cube
|
|
|
- )');
|
|
|
|
|
|
|
+ )");
|
|
|
|
|
|
|
|
if(!$stmt)
|
|
if(!$stmt)
|
|
|
{
|
|
{
|
|
@@ -112,20 +115,6 @@ function processFile($filename_report, $columns_to_fields)
|
|
|
$columns_by_names = array();
|
|
$columns_by_names = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
- //make sure all found columns are mapped
|
|
|
|
|
- for($i = 0; $i < count($column_names[0]); $i++)
|
|
|
|
|
- {
|
|
|
|
|
- $name = trim($column_names[0][$i]);
|
|
|
|
|
-
|
|
|
|
|
- if(!$name && !strlen($name))
|
|
|
|
|
- continue;
|
|
|
|
|
-
|
|
|
|
|
- if(!isset($columns_to_fields[$name]))
|
|
|
|
|
- echo "column not mapped: $name\n";
|
|
|
|
|
-
|
|
|
|
|
- $fields_by_col[$i] = $columns_to_fields[$name];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
//flip the column names to reflect the indexes
|
|
//flip the column names to reflect the indexes
|
|
|
foreach($column_names[0] as $index => $name)
|
|
foreach($column_names[0] as $index => $name)
|
|
@@ -140,7 +129,7 @@ function processFile($filename_report, $columns_to_fields)
|
|
|
echo "processing row #$r...";
|
|
echo "processing row #$r...";
|
|
|
|
|
|
|
|
// read row of data into array
|
|
// read row of data into array
|
|
|
- $row_array = $sheet->rangeToArray($range, NULL, TRUE, FALSE);
|
|
|
|
|
|
|
+ $row_array = $sheet->rangeToArray($range, NULL, TRUE, TRUE);
|
|
|
|
|
|
|
|
if(!count($row_array))
|
|
if(!count($row_array))
|
|
|
{
|
|
{
|
|
@@ -148,40 +137,50 @@ function processFile($filename_report, $columns_to_fields)
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //pull the row out and format the nulls as needed
|
|
|
$row = $row_array[0];
|
|
$row = $row_array[0];
|
|
|
-
|
|
|
|
|
|
|
+ for($c = 0; $c < count($row); $c++)
|
|
|
|
|
+ $row[$c] = $row[$c] && strlen(trim($row[$c])) ? trim($row[$c]) : null;
|
|
|
|
|
+
|
|
|
|
|
+ //skip if no data for first three columns
|
|
|
|
|
+ if(!$row[0] && !$row[1] && !$row[2])
|
|
|
|
|
+ {
|
|
|
|
|
+ echo "SKIP\n";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//bind appropriate values
|
|
//bind appropriate values
|
|
|
- $params = array(
|
|
|
|
|
- ':id_company' => 1
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- $EXCEL_DATE = $row[2];
|
|
|
|
|
- $UNIX_DATE = round(($EXCEL_DATE - 25569) * 86400);
|
|
|
|
|
- echo gmdate("d-m-Y H:i:s", $UNIX_DATE) . "\n";
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ $params = array();
|
|
|
|
|
|
|
|
- for($c = 0; $c < count($row); $c++)
|
|
|
|
|
- if(isset($fields_by_col[$c]))
|
|
|
|
|
- {
|
|
|
|
|
- $cell = $sheet->getCellByColumnAndRow($c, $r);
|
|
|
|
|
-
|
|
|
|
|
- //if column is a date, then calculate the timestamp and pass that
|
|
|
|
|
- if(PHPExcel_Shared_Date::isDateTime($cell))
|
|
|
|
|
- {
|
|
|
|
|
- $value = PHPExcel_Shared_Date::ExcelToPHP($cell->getValue());
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- $value = trim($cell->getValue());
|
|
|
|
|
-
|
|
|
|
|
- if(!strlen($value))
|
|
|
|
|
- $value = null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $params[':' . $fields_by_col[$c]] = $value;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $params[':id_company'] = $id_company;
|
|
|
|
|
+
|
|
|
|
|
+ $params[':division'] = $row[0];
|
|
|
|
|
+ $params[':consignee'] = $row[1];
|
|
|
|
|
+ $params[':date_called_in'] = $row[2];
|
|
|
|
|
+ $params[':dispatch_number'] = $row[3];
|
|
|
|
|
+ $params[':shipper'] = $row[4];
|
|
|
|
|
+ $params[':date_ready'] = $row[5];
|
|
|
|
|
+
|
|
|
|
|
+ $params[':address_1'] = $row[6];
|
|
|
|
|
+ $params[':address_2'] = $row[7];
|
|
|
|
|
+ $params[':city'] = $row[8];
|
|
|
|
|
+ $params[':state'] = $row[9];
|
|
|
|
|
+ $params[':zip'] = $row[10];
|
|
|
|
|
+ $params[':phone'] = $row[11];
|
|
|
|
|
+
|
|
|
|
|
+ $params[':time_ready'] = $row[14] ? DateTime::createFromFormat('H:i A', $row[14])->format('H:i:s') : null;
|
|
|
|
|
+ $params[':time_close'] = $row[15] ? DateTime::createFromFormat('H:i A', $row[15])->format('H:i:s') : null;
|
|
|
|
|
+ $params[':time_pickup'] = $row[16] ? DateTime::createFromFormat('H:i A', $row[16])->format('H:i:s') : null;
|
|
|
|
|
+ $params[':time_depart'] = $row[17] ? DateTime::createFromFormat('H:i A', $row[17])->format('H:i:s') : null;
|
|
|
|
|
+ $params[':bol_delivered'] = $row[18];
|
|
|
|
|
+
|
|
|
|
|
+ $params[':dispatch_reference'] = $row[35];
|
|
|
|
|
+
|
|
|
|
|
+ $params[':ctns'] = $row[44];
|
|
|
|
|
+ $params[':weight'] = $row[45];
|
|
|
|
|
+ $params[':cube'] = $row[46];
|
|
|
|
|
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
$stmt->execute($params);
|
|
$stmt->execute($params);
|