8
8
9
9
namespace Magento \Paypal \Model \Report ;
10
10
11
+ use DateTime ;
11
12
use Magento \Framework \Filesystem ;
12
13
use Magento \Framework \Filesystem \DirectoryList ;
13
14
@@ -162,6 +163,13 @@ class Settlement extends \Magento\Framework\Model\AbstractModel
162
163
*/
163
164
protected $ _scopeConfig ;
164
165
166
+ /**
167
+ * Columns with DateTime data type
168
+ *
169
+ * @var array
170
+ */
171
+ private $ dateTimeColumns = ['transaction_initiation_date ' , 'transaction_completion_date ' ];
172
+
165
173
/**
166
174
* @param \Magento\Framework\Model\Context $context
167
175
* @param \Magento\Framework\Registry $registry
@@ -249,7 +257,8 @@ public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection)
249
257
250
258
// Set last modified date, this value will be overwritten during parsing
251
259
if (isset ($ attributes ['mtime ' ])) {
252
- $ lastModified = new \DateTime ($ attributes ['mtime ' ]);
260
+ $ date = new \DateTime ();
261
+ $ lastModified = $ date ->setTimestamp ($ attributes ['mtime ' ]);
253
262
$ this ->setReportLastModified (
254
263
$ lastModified ->format ('Y-m-d H:i:s ' )
255
264
);
@@ -324,7 +333,7 @@ public function parseCsv($localCsv, $format = 'new')
324
333
$ rowMap = $ this ->_csvColumns [$ format ]['rowmap ' ];
325
334
326
335
$ flippedSectionColumns = array_flip ($ sectionColumns );
327
- $ stream = $ this ->_tmpDirectory ->openFile ($ localCsv );
336
+ $ stream = $ this ->_tmpDirectory ->openFile ($ localCsv, ' r ' );
328
337
while ($ line = $ stream ->readCsv ()) {
329
338
if (empty ($ line )) {
330
339
// The line was empty, so skip it.
@@ -360,11 +369,7 @@ public function parseCsv($localCsv, $format = 'new')
360
369
break ;
361
370
case 'SB ' :
362
371
// Section body.
363
- $ bodyItem = [];
364
- for ($ i = 1 ; $ i < count ($ line ); $ i ++) {
365
- $ bodyItem [$ rowMap [$ flippedSectionColumns [$ i ]]] = $ line [$ i ];
366
- }
367
- $ this ->_rows [] = $ bodyItem ;
372
+ $ this ->_rows [] = $ this ->getBodyItems ($ line , $ flippedSectionColumns , $ rowMap );
368
373
break ;
369
374
case 'SC ' :
370
375
// Section records count.
@@ -385,6 +390,41 @@ public function parseCsv($localCsv, $format = 'new')
385
390
return $ this ;
386
391
}
387
392
393
+ /**
394
+ * Parse columns from line of csv file
395
+ *
396
+ * @param array $line
397
+ * @param array $sectionColumns
398
+ * @param array $rowMap
399
+ * @return array
400
+ */
401
+ private function getBodyItems (array $ line , array $ sectionColumns , array $ rowMap )
402
+ {
403
+ $ bodyItem = [];
404
+ for ($ i = 1 , $ count = count ($ line ); $ i < $ count ; $ i ++) {
405
+ if (isset ($ rowMap [$ sectionColumns [$ i ]])) {
406
+ if (in_array ($ rowMap [$ sectionColumns [$ i ]], $ this ->dateTimeColumns )) {
407
+ $ line [$ i ] = $ this ->formatDateTimeColumns ($ line [$ i ]);
408
+ }
409
+ $ bodyItem [$ rowMap [$ sectionColumns [$ i ]]] = $ line [$ i ];
410
+ }
411
+ }
412
+ return $ bodyItem ;
413
+ }
414
+
415
+ /**
416
+ * Format date columns in UTC
417
+ *
418
+ * @param string $lineItem
419
+ * @return string
420
+ */
421
+ private function formatDateTimeColumns ($ lineItem )
422
+ {
423
+ /** @var DateTime $date */
424
+ $ date = new DateTime ($ lineItem , new \DateTimeZone ('UTC ' ));
425
+ return $ date ->format (\Magento \Framework \Stdlib \DateTime::DATETIME_PHP_FORMAT );
426
+ }
427
+
388
428
/**
389
429
* Load report by unique key (accoutn + report date)
390
430
*
0 commit comments