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;








2















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










share|improve this question






























    2















    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










    share|improve this question


























      2












      2








      2








      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










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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




















          1 Answer
          1






          active

          oldest

          votes


















          3














          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






          share|improve this answer























          • Worked for me. Thanks :)

            – Shoaib Munir
            Jun 20 at 7:21













          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
          );



          );













          draft saved

          draft discarded


















          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









          3














          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






          share|improve this answer























          • Worked for me. Thanks :)

            – Shoaib Munir
            Jun 20 at 7:21















          3














          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






          share|improve this answer























          • Worked for me. Thanks :)

            – Shoaib Munir
            Jun 20 at 7:21













          3












          3








          3







          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






          share|improve this 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







          share|improve this answer












          share|improve this answer



          share|improve this 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

















          • 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

















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

          Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

          Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림