Magento 2 - After invoice delete programatically can't create new invoice properlyProgrammatically create a credit memoHow to get invoice from order itemCan't generate invoice programmaticallyMagento Convert Quote to OrderEvent to observe invoice creation and get the invoiced item quantitiesCan't print invoice after edited Currency file on Magento 1.7Cancel non invoiced order item without cancelling orderMagento 2: Issue while Delete Invoice ProgrammaticallyIs possible create reorder after created invoice of the orderMagento 2.2.5: Idea about delete “Banner_Slide”
Can a nowhere continuous function have a connected graph?
Single level file directory
How to properly say asset/assets in German
Sharing referee/AE report online to point out a grievous error in refereeing
Can I travel from Germany to England alone as an unaccompanied minor?
Why was Mal so quick to drop Bester in favour of Kaylee?
Was it really unprofessional of me to leave without asking for a raise first?
Can European countries bypass the EU and make their own individual trade deal with the U.S.?
Why were the first airplanes "backwards"?
Bin Packing with Relational Penalization
What is "override advice"?
If two black hole event horizons overlap (touch) can they ever separate again?
Is Cyclic Ether oxidised by periodic acid
Are gliders susceptible to bird strikes?
Why would anyone even use a Portkey?
My colleague is constantly blaming me for his errors
Can SOCPs approximate better than LPs?
Is it okay to submit a paper from a master's thesis without informing the advisor?
I just started should I accept a farewell lunch for a coworker I don't know?
Why wasn't ASCII designed with a contiguous alphanumeric character order?
How can a valley surrounded by mountains be fertile and rainy?
Adjective for 'made of pus' or 'corrupted by pus' or something of something of pus
Can you actually break an FPGA by programming it wrong?
How do I organize members in a struct to waste the least space on alignment?
Magento 2 - After invoice delete programatically can't create new invoice properly
Programmatically create a credit memoHow to get invoice from order itemCan't generate invoice programmaticallyMagento Convert Quote to OrderEvent to observe invoice creation and get the invoiced item quantitiesCan't print invoice after edited Currency file on Magento 1.7Cancel non invoiced order item without cancelling orderMagento 2: Issue while Delete Invoice ProgrammaticallyIs possible create reorder after created invoice of the orderMagento 2.2.5: Idea about delete “Banner_Slide”
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have used the code
if ($order->getInvoiceCollection()->count())
$_invoices = $order->getInvoiceCollection();
if ($_invoices)
foreach ($_invoices as $invoice)
$invoice->delete();
This is deleting invoice, but invoice button was not reappearing although invoice is deleted.
So, I have go through the database table and turns out order_items has item_invoiced column, I have used this code to set item invoiced value to 0
$items = $order->getAllItems();
foreach ($items as $k => $item)
echo $item->getId() . "n";
$item->setQtyInvoiced(0);
$item->save();
After this code invoice button is appearing, but when I am creating invoice it is setting subtotal to negative like -1000
magento2 orders invoice order-items invoice-items
add a comment |
I have used the code
if ($order->getInvoiceCollection()->count())
$_invoices = $order->getInvoiceCollection();
if ($_invoices)
foreach ($_invoices as $invoice)
$invoice->delete();
This is deleting invoice, but invoice button was not reappearing although invoice is deleted.
So, I have go through the database table and turns out order_items has item_invoiced column, I have used this code to set item invoiced value to 0
$items = $order->getAllItems();
foreach ($items as $k => $item)
echo $item->getId() . "n";
$item->setQtyInvoiced(0);
$item->save();
After this code invoice button is appearing, but when I am creating invoice it is setting subtotal to negative like -1000
magento2 orders invoice order-items invoice-items
add a comment |
I have used the code
if ($order->getInvoiceCollection()->count())
$_invoices = $order->getInvoiceCollection();
if ($_invoices)
foreach ($_invoices as $invoice)
$invoice->delete();
This is deleting invoice, but invoice button was not reappearing although invoice is deleted.
So, I have go through the database table and turns out order_items has item_invoiced column, I have used this code to set item invoiced value to 0
$items = $order->getAllItems();
foreach ($items as $k => $item)
echo $item->getId() . "n";
$item->setQtyInvoiced(0);
$item->save();
After this code invoice button is appearing, but when I am creating invoice it is setting subtotal to negative like -1000
magento2 orders invoice order-items invoice-items
I have used the code
if ($order->getInvoiceCollection()->count())
$_invoices = $order->getInvoiceCollection();
if ($_invoices)
foreach ($_invoices as $invoice)
$invoice->delete();
This is deleting invoice, but invoice button was not reappearing although invoice is deleted.
So, I have go through the database table and turns out order_items has item_invoiced column, I have used this code to set item invoiced value to 0
$items = $order->getAllItems();
foreach ($items as $k => $item)
echo $item->getId() . "n";
$item->setQtyInvoiced(0);
$item->save();
After this code invoice button is appearing, but when I am creating invoice it is setting subtotal to negative like -1000
magento2 orders invoice order-items invoice-items
magento2 orders invoice order-items invoice-items
edited Jun 20 at 7:37
Muhammad Hasham
5,07210 gold badges28 silver badges78 bronze badges
5,07210 gold badges28 silver badges78 bronze badges
asked Jun 20 at 5:40
Shoaib MunirShoaib Munir
4,5796 gold badges22 silver badges67 bronze badges
4,5796 gold badges22 silver badges67 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Looking at your code, I guess you miss the trick. You have to set order items fields to 0 which are effected by creating invoice. Replace your item foreach with this.
$items = $order->getAllItems();
foreach ($items as $k => $item)
echo $item->getId() . "n";
$item->setBaseRowInvoiced(0);
$item->setRowInvoiced(0);
$item->setQtyInvoiced(0);
$item->setDiscountInvoiced(0);
$item->setBaseDiscountInvoiced(0);
$item->save();
You also have to add some order fields to 0 as well. for this you have to add following code in your script.
$order->setTotalPaid(0)
->setBaseTotalPaid(0)
->setBaseTotalInvoiced(0)
->setTotalInvoiced(0)
->setBaseSubtotalInvoiced(0)
->setSubtotalInvoiced(0)
->setBaseShippingInvoiced(0)
->setShippingInvoiced(0)
->setBaseDiscountInvoiced(0)
->setDiscountInvoiced(0);
I hope this will help, let me know once you tried my answer
Worked for me. Thanks :)
– Shoaib Munir
Jun 20 at 7:21
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f278962%2fmagento-2-after-invoice-delete-programatically-cant-create-new-invoice-proper%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Looking at your code, I guess you miss the trick. You have to set order items fields to 0 which are effected by creating invoice. Replace your item foreach with this.
$items = $order->getAllItems();
foreach ($items as $k => $item)
echo $item->getId() . "n";
$item->setBaseRowInvoiced(0);
$item->setRowInvoiced(0);
$item->setQtyInvoiced(0);
$item->setDiscountInvoiced(0);
$item->setBaseDiscountInvoiced(0);
$item->save();
You also have to add some order fields to 0 as well. for this you have to add following code in your script.
$order->setTotalPaid(0)
->setBaseTotalPaid(0)
->setBaseTotalInvoiced(0)
->setTotalInvoiced(0)
->setBaseSubtotalInvoiced(0)
->setSubtotalInvoiced(0)
->setBaseShippingInvoiced(0)
->setShippingInvoiced(0)
->setBaseDiscountInvoiced(0)
->setDiscountInvoiced(0);
I hope this will help, let me know once you tried my answer
Worked for me. Thanks :)
– Shoaib Munir
Jun 20 at 7:21
add a comment |
Looking at your code, I guess you miss the trick. You have to set order items fields to 0 which are effected by creating invoice. Replace your item foreach with this.
$items = $order->getAllItems();
foreach ($items as $k => $item)
echo $item->getId() . "n";
$item->setBaseRowInvoiced(0);
$item->setRowInvoiced(0);
$item->setQtyInvoiced(0);
$item->setDiscountInvoiced(0);
$item->setBaseDiscountInvoiced(0);
$item->save();
You also have to add some order fields to 0 as well. for this you have to add following code in your script.
$order->setTotalPaid(0)
->setBaseTotalPaid(0)
->setBaseTotalInvoiced(0)
->setTotalInvoiced(0)
->setBaseSubtotalInvoiced(0)
->setSubtotalInvoiced(0)
->setBaseShippingInvoiced(0)
->setShippingInvoiced(0)
->setBaseDiscountInvoiced(0)
->setDiscountInvoiced(0);
I hope this will help, let me know once you tried my answer
Worked for me. Thanks :)
– Shoaib Munir
Jun 20 at 7:21
add a comment |
Looking at your code, I guess you miss the trick. You have to set order items fields to 0 which are effected by creating invoice. Replace your item foreach with this.
$items = $order->getAllItems();
foreach ($items as $k => $item)
echo $item->getId() . "n";
$item->setBaseRowInvoiced(0);
$item->setRowInvoiced(0);
$item->setQtyInvoiced(0);
$item->setDiscountInvoiced(0);
$item->setBaseDiscountInvoiced(0);
$item->save();
You also have to add some order fields to 0 as well. for this you have to add following code in your script.
$order->setTotalPaid(0)
->setBaseTotalPaid(0)
->setBaseTotalInvoiced(0)
->setTotalInvoiced(0)
->setBaseSubtotalInvoiced(0)
->setSubtotalInvoiced(0)
->setBaseShippingInvoiced(0)
->setShippingInvoiced(0)
->setBaseDiscountInvoiced(0)
->setDiscountInvoiced(0);
I hope this will help, let me know once you tried my answer
Looking at your code, I guess you miss the trick. You have to set order items fields to 0 which are effected by creating invoice. Replace your item foreach with this.
$items = $order->getAllItems();
foreach ($items as $k => $item)
echo $item->getId() . "n";
$item->setBaseRowInvoiced(0);
$item->setRowInvoiced(0);
$item->setQtyInvoiced(0);
$item->setDiscountInvoiced(0);
$item->setBaseDiscountInvoiced(0);
$item->save();
You also have to add some order fields to 0 as well. for this you have to add following code in your script.
$order->setTotalPaid(0)
->setBaseTotalPaid(0)
->setBaseTotalInvoiced(0)
->setTotalInvoiced(0)
->setBaseSubtotalInvoiced(0)
->setSubtotalInvoiced(0)
->setBaseShippingInvoiced(0)
->setShippingInvoiced(0)
->setBaseDiscountInvoiced(0)
->setDiscountInvoiced(0);
I hope this will help, let me know once you tried my answer
answered Jun 20 at 5:52
Muhammad HashamMuhammad Hasham
5,07210 gold badges28 silver badges78 bronze badges
5,07210 gold badges28 silver badges78 bronze badges
Worked for me. Thanks :)
– Shoaib Munir
Jun 20 at 7:21
add a comment |
Worked for me. Thanks :)
– Shoaib Munir
Jun 20 at 7:21
Worked for me. Thanks :)
– Shoaib Munir
Jun 20 at 7:21
Worked for me. Thanks :)
– Shoaib Munir
Jun 20 at 7:21
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f278962%2fmagento-2-after-invoice-delete-programatically-cant-create-new-invoice-proper%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown