Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date incorrect on pdf invoice #26675

Closed
devchris79 opened this issue Feb 3, 2020 · 59 comments
Closed

Date incorrect on pdf invoice #26675

devchris79 opened this issue Feb 3, 2020 · 59 comments
Assignees
Labels
Component: Sales Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Reported on 2.3.2 Indicates original Magento version for the Issue report.

Comments

@devchris79
Copy link

devchris79 commented Feb 3, 2020

Preconditions (*)

  1. Magento 2.4-develop

Steps to reproduce (*)

  1. Go to Sales->Orders, select an order and then try to "print invoices"

Expected result (*)

  1. Date to reflect purchase date

Actual result (*)

  1. Dates are incorrect, we have 2006 and 2008 for orders, before the website was developed....
  2. Dates were fine in 2.3.2.
    #26665issueInvoice.pdf
@magento-deployment-service
Copy link

Thanks for opening this issue!

@m2-assistant
Copy link

m2-assistant bot commented Feb 3, 2020

Hi @devchris79. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@devchris79 do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Feb 3, 2020
@anvanza
Copy link

anvanza commented Feb 3, 2020

Same issue here but my dates are way higher.
Screenshot 2020-02-03 at 14 01 43

Maybe a good thing to note is the settings below:
Timezone Sever: UTC
Locale Storeview: nl_NL

@engcom-Delta engcom-Delta self-assigned this Feb 4, 2020
@m2-assistant
Copy link

m2-assistant bot commented Feb 4, 2020

Hi @engcom-Delta. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@magento-deployment-service
Copy link

Thanks for opening this issue!

@engcom-Delta engcom-Delta added Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Component: Sales Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Feb 4, 2020
@ghost ghost unassigned engcom-Delta Feb 4, 2020
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Delta
Thank you for verifying the issue. Based on the provided information internal tickets MC-31082 were created

Issue Available: @engcom-Delta, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Feb 4, 2020
@devchris79
Copy link
Author

@engcom-Delta Why did you edit the post to include a precondition of Locale Storeview: nl_NL?
This is not a precondition that we used.....

It looks like the date is inserted in:
/vendor/magento/module-sales/Model/Order/Pdf/AbstractPdf.php

So this may affect other pdf documents like shipping, credit memo etc.

@devchris79
Copy link
Author

devchris79 commented Feb 4, 2020

Credit memos are also affected.

@devchris79
Copy link
Author

I think this may be because of the changes in #23693. @edenduong does that sound likely?

@magento-deployment-service
Copy link

Thanks for opening this issue!

@edenduong
Copy link
Contributor

edenduong commented Feb 4, 2020

Hi @devchris79 ,

Thank you for your issue report. I try to reproduce it on my local site but I can not reproduce in my site. In my commit, I try to change the logic of scopeDate similar to the date function. Before that, they are different and the scopeDate didn't support full type of interface.

@engcom-Delta
Copy link
Contributor

engcom-Delta commented Feb 4, 2020

@devchris79 According your steps as its are now, issue is not reproducible. comment adds more details to how reproduce issue and Locale=Dutch (Netherlands) is important thing to reproduce issue

@anvanza
Copy link

anvanza commented Feb 4, 2020

@magento give me 2.3-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @anvanza. Thank you for your request. I'm working on Magento 2.3-develop instance for you

@devchris79
Copy link
Author

Hi @edenduong

Why have you closed this issue? Its been seen by myself, @anvanza and @engcom-Delta

Here is our locale options:

locale

@edenduong edenduong reopened this Feb 4, 2020
@ghost ghost removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch labels Feb 4, 2020
@edenduong
Copy link
Contributor

@devchris79 : sorry for my mistake. I didn’t mean that. I reopened it.

@devchris79
Copy link
Author

@edenduong No problem :-) Maybe the issue is related to the locale option giving the strange results. It seems @engcom-Delta and @anvanza believe this to be pertinent.

@engcom-Delta
Copy link
Contributor

@magento give me 2.4-develop instance

@gwharton
Copy link
Contributor

I don't know what Magento's plan is for backporting to 2.3. Presumably they are still going to be releasing 2.3.5 etc... so I would assume they will be handling the backporting internally, as we are no longer able to generate backports outside of the magento organisation.

In the meantime....

For each issue I care about, that has been merged into 2.4, I create a diff and apply it using the cweagans patching process to my 2.3 installation. At each version release of 2.3, I check each one in turn and if it has been backported into 2.3 by magento, then I remove my local patch. This way, I should be covered in both scenareos.

@glastron174
Copy link

If you havent done so already, look into one of the composer patch management packages, then download the pull request as a diff, and apply via your main composer file. I think applying patches like this is preferred to editing core.

composer require cweagans/composer-patches
Add section to bottom of main composer.json file

    "extra": {
        "magento-force": "override",
        "composer-exit-on-patch-failure": true,
        "patches": {
            "magento/framework": {
                "1.0": "patches/composer/26701.diff"
            }
        }
    }

Download the patch from https://patch-diff.githubusercontent.com/raw/magento/magento2/pull/26701.diff and save into patches/composer folder

Edit the patch file and remove all "lib/internal/Magento/Framework/" from paths. so paths would be "a/Stdlib/DateTime/Timezone.php" and "b/Stdlib/DateTime/Timezone.php" etc.

Now just do a

composer install

When a new release is out which already incorporates the fix, then remove the patch from your composer file.

Hi, Should the /patches/composer folder created in the root?
I'm getting an error on the composer install

[Seld\JsonLint\ParsingException]
"./composer.json" does not contain valid JSON
Parse error on line 133:
}
--------------------^
Expected one of: '}', ','

Thanks in advanced, Edwin

@gwharton
Copy link
Contributor

gwharton commented Mar 9, 2020

Looks like there is some whitespace on the end of line 133 that it doesn't like. There shouldnt be any whitespace at the ends of the lines in a json file. Probably just copy and pasted across.

and yes, the patches folder goes in the root of magento

@gwharton
Copy link
Contributor

gwharton commented Mar 9, 2020

If it is working right, on composer install it should remove framework, reinstall framework and then apply the patch. Then you're good to go. Once the patch is integrated into mainline, you can remove it from your composer.json when you update.

@glastron174
Copy link

If it is working right, on composer install it should remove framework, reinstall framework and then apply the patch. Then you're good to go. Once the patch is integrated into mainline, you can remove it from your composer.json when you update.

Thanks, I had to add one } extra in the sjon file. The dates in PDFs are correct now.

@tushhan
Copy link

tushhan commented May 28, 2020

I am using Magento 2.3.4

I have applied @edenduong' code to the file located in; /vendor/magento/framework/Stdlib/DateTime/Timezone.php (line 196)

###############

public function scopeDate($scope = null, $date = null, $includeTime = false)
{
$timezone = new \DateTimeZone(
$this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType, $scope)
);
switch (true) {
case (empty($date)):
$date = new \DateTime('now', $timezone);
break;
case ($date instanceof \DateTime):
case ($date instanceof \DateTimeImmutable):
$date = $date->setTimezone($timezone);
break;
default:
$date = new \DateTime(is_numeric($date) ? '@' . $date : $date);
$date->setTimezone($timezone);
break;
}

    if (!$includeTime) {
        $date->setTime(0, 0, 0);
    }

    return $date;
}

###################

This corects dates on invoices.

@dudzio12
Copy link
Member

dudzio12 commented Jun 1, 2020

If you use Magento with composer, there is a diff for you:
https://pastebin.com/YtzX09gL

@ghost
Copy link

ghost commented Jun 4, 2020

@dudzio12
How can I apply this patch with composer?

If you use Magento with composer, there is a diff for you:
https://pastebin.com/YtzX09gL

@dudzio12
Copy link
Member

dudzio12 commented Jun 4, 2020

@JustICTNL:

  1. composer require cweagans/composer-patches
  2. Create root subdirectory called patches and create file `datetime_format_2_3_5.patch.
  3. Add pastebin content to this file
  4. Add to your composer.json:
(...)
 "extra": {
        "magento-force": "override",
        "enable-patching": true,
        "composer-exit-on-patch-failure": true,
        "patches": {
            "magento/framework": {
                "Datetime format": "patches/datetime_format_2_3_5.patch"
            }
        }
    }
}

@MarcusWolschon
Copy link

@JustICTNL:

1. `composer require cweagans/composer-patches`

2. Create root subdirectory called `patches` and create file `datetime_format_2_3_5.patch.

3. Add pastebin content to this file

4. Add to your composer.json:
(...)
 "extra": {
        "magento-force": "override",
        "enable-patching": true,
        "composer-exit-on-patch-failure": true,
        "patches": {
            "magento/framework": {
                "Datetime format": "patches/datetime_format_2_3_5.patch"
            }
        }
    }
}

Do we have to remove this again before upgrading to the next Magento release?
What steps are required (I have never worked with patches in Composer).

@dudzio12
Copy link
Member

dudzio12 commented Jun 4, 2020

You probably should delete it as soon as the new release implementing proper fix will be available.

It's good practise to name the patch with issue number just to not get lost in the future:

"magento/framework": {
  "Datetime format - Magento 2.3.5 - issue 26675": "patches/datetime_format_2_3_5_26675.patch"
 }

@ghost ghost mentioned this issue Jun 4, 2020
5 tasks
@hostep
Copy link
Contributor

hostep commented Jun 4, 2020

@MarcusWolschon: with composer-exit-on-patch-failure set to true, composer will complain if the patch is no longer applicable on a certain version of Magento, which is very handy.
But we always double check all our patches after every new Magento version anyways to make sure they are still needed or not (sometimes a fix is done in a completely different way than the patch and composer wouldn't complain in that case, but that's not happening very often)

@ghost
Copy link

ghost commented Jun 4, 2020

@dudzio12 and @MarcusWolschon
I did what you said, but it doesn't work for me :'(

Did I do something wrong, or is there another solution? I had the order date 9-11-2022. In magento is the correct order date.

@ghost
Copy link

ghost commented Jun 4, 2020

Magento directory/composer.json

"extra": {
        "magento-force": "override",
        "enable-patching": true,
        "composer-exit-on-patch-failure": true,
        "patches": {
            "magento/framework": {
                "Datetime format": "patches/datetime_format_2_3_5.patch"
            }
        },

DIFF file pasted in file:
Magento Directory/patches/datetime_format_2_3_5.patch

@ghost
Copy link

ghost commented Jun 8, 2020

I am using Magento 2.3.4

I have applied @edenduong' code to the file located in; /vendor/magento/framework/Stdlib/DateTime/Timezone.php (line 196)

###############

public function scopeDate($scope = null, $date = null, $includeTime = false)
{
$timezone = new \DateTimeZone(
$this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType, $scope)
);
switch (true) {
case (empty($date)):
$date = new \DateTime('now', $timezone);
break;
case ($date instanceof \DateTime):
case ($date instanceof \DateTimeImmutable):
$date = $date->setTimezone($timezone);
break;
default:
$date = new \DateTime(is_numeric($date) ? '@' . $date : $date);
$date->setTimezone($timezone);
break;
}

    if (!$includeTime) {
        $date->setTime(0, 0, 0);
    }

    return $date;
}

###################

This corects dates on invoices.

This works now for me. i updgraded to Magento 2.3.5-P1 and now it works.
FInd the file with command:
find . -name Timezone.php
Result: ./vendor/magento/framework/Stdlib/DateTime/Timezone.php

I changed above in ./vendor/magento/framework/Stdlib/DateTime/Timezone.php
And now it works :)

@IbrahimS2
Copy link

IbrahimS2 commented Aug 31, 2020

@magento-engcom-team It still persisting even on M2.3.5-p2, can we have this ported/merged to p3 maybe?

https://github.com/magento/magento2/blob/2.3.5-p2/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php

@VincentMarmiesse
Copy link
Contributor

This issue still exists in version 2.3.6.

@FredericMartinez
Copy link
Contributor

@magento-engcom-team magento-engcom-team added the Reported on 2.3.2 Indicates original Magento version for the Issue report. label Nov 13, 2020
@LaurensGoedel
Copy link

Just updated to 2.3.7 and issue still extists

@hostep
Copy link
Contributor

hostep commented Jun 7, 2021

@LaurensGoedel: the issue got fix in Magento 2.4.0 and above, it looks like Magento core devs didn't seem to think it was necessary to backport this fix to the 2.3.x release line. If you still need a fix for 2.3.x, please read through the entire thread, there are plenty of comments that tell you how to apply patches to resolve this issue.

@Aquive
Copy link

Aquive commented Jun 23, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Sales Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Reported on 2.3.2 Indicates original Magento version for the Issue report.
Projects
None yet
Development

No branches or pull requests