Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Split invoice based on...
Finance forum
Unanswered

Split invoice based on quantity in packing Slip

Posted on by 9
Hello,
 
I want to split an invoice based on qty in packing Slip using x++.
For Example if I have Qty= 2 in packing slip I should obtain 2 invoices instead of 1.
How to develop this fonctionality .
thanks in advance.
 
ps: the quantity of packing slip is the deliverNow qty in salesParmLine 
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,524 Super User 2024 Season 2 on at
    Split invoice based on quantity in packing Slip
    Hi,
     
    What is the exact behavior for the invoices after invoice number 1? Do you get an error message or are they just not posted?
  • YB-04071507-0 Profile Picture
    YB-04071507-0 9 on at
    Split invoice based on quantity in paching Slip
    Hello,
    I try to create records in salesParmTable and SalesParLine with deliverNow=1 . 
    invoices are created but cant't be posted, only the first invoice is posted .
    this is my code:
     
     
     
     protected void createAndPostJournal()
     {
            FormletterJournalPost     formletterJournalPost1;
            SalesParmLine                  salesParmLine,salesParmLine1;
            SalesQty                           salesQty ;
            SalesParmTable                salesParmTable =                         SalesParmTable::find(formletterParmTable.parmId,formletterParmTable.tableRefId);
            salesParmUpdate              salesParmUpdate;
            salesParmTable                  salesParmTable1;
            salesFormletterParmData   salesFormLetterParmData;
            TransDate                           PackingSlipDate ;
      
            
            
            ttsbegin;
            select  firstOnly Forupdate salesParmLine where salesParmLine.parmId == salesParmTable.ParmId;
       
            salesQty = salesParmLine.DeliverNow ;
            salesParmLine.deliverNow=UnitOfMeasureConverter::convert(1,
                                      UnitOfMeasure::unitOfMeasureIdBySymbol(salesParmLine.inventTable().inventUnitId()),
                                      UnitOfMeasure::unitOfMeasureIdBySymbol(salesParmLine.salesUnit()),
                                      NoYes::Yes,
                                      InventTable::itemProduct(salesParmLine.ItemId));
            salesParmLine.setInventDeliverNow();
            salesParmLine.setLineAmount();
            salesParmLine.update();
            ttscommit;
         
            next createAndPostJournal();
     
            if (salesParmTable.documentId(salesParmTable))
            {
                salesFormLetterParmData = salesFormletterParmData::newData(DocumentStatus::Invoice,             VersioningUpdateType::Initial);
                salesFormLetterParmData.parmOnlyCreateParmUpdate(true);
                salesFormLetterParmData.createData(false);
                salesParmUpdate = salesFormLetterParmData.parmParmUpdate();
                salesParmTable1.clear();
                salesParmTable1.TransDate                = salesParmTable.transdate;
                salesParmTable1.Ordering                 = DocumentStatus::Invoice;
                salesParmTable1.ParmJobStatus        = ParmJobStatus::Waiting;
                salesParmTable1.salesId                      = salesParmTable.salesId;
                salesParmTable1.salesName                = salesParmTable.salesName;
                salesParmTable1.DeliveryName             = salesParmTable.DeliveryName;
                salesParmTable1.DeliveryPostalAddress    = salesParmTable.DeliveryPostalAddress;
                salesParmTable1.CustAccount              = salesParmTable.CustAccount;
                salesParmTable1.CurrencyCode             = salesParmTable.CurrencyCode;
                salesParmTable1.InvoiceAccount           = salesParmTable.InvoiceAccount;
                salesParmTable1.ParmId                   = SalesParmTable.ParmId;
                salesParmTable1.insert();

                salesParmLine1.DeliverNow    = salesParmLINE.delivernow;
                salesParmLine1.setInventDeliverNow();
                salesParmLine1.setLineAmount();
                salesParmLine1.ParmId        = salesParmTable1.ParmId;
                salesParmLine1.TableRefId    = salesParmTable1.TableRefId;
                salesParmLine1.setQty(DocumentStatus::INVOICE, TRUE, true);
                //salesParmLine1.setLineAmount(salesParmLine.salesLine());
                salesParmLine1.InventDimId   = salesParmLine.InventDIMID;
                salesParmLine1.ItemId        = salesParmLine.ItemId;
                salesParmLine1.initFromSalesLine(salesParmLine.salesLine());
                salesParmLine1.calcPackingUnitQty();
                salesParmLine1.InventNow = salesParmLine.salesLine().ExpectedRetQty;
                salesParmLine1.insert();
     

                salesParmSubLine salesParmSubLine;
                salesParmSubLine.clear();
                salesParmSubLine.initValue();
                salesParmSubLine.initFromSalesParmLine(salesParmLine1);
                salesParmSubLine.InventNow              = salesParmLine.salesLine().SalesQty;
                salesParmSubLine.DeliverNow             = salesParmLine.salesLine().SalesQty;
                salesParmSubLine.insert();
                SalesLine salesline1 = salesParmLine.salesLine();
           
                this.createJournal(salesParmTable1); // CREATE Invoice
                if (journal.RecId)
                {
                    formletterJournalPost1 = this.postJournal(salesParmTable1); //Post Invoice : where the system throws multiple errors
                    this.addJournalToLists();
                }
                this.updateParmTableJobStatusExecuted(salesParmTable1);
                if ( journal.RecId && formletterJournalPost1)
                {
                    formletterJournalPost1.postJournalPost();
                    this.prepareProforma(formletterJournalPost1);
                }
              
            }
     
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,524 Super User 2024 Season 2 on at
    Split invoice based on quantity in paching Slip
    I wonder about the business reason for the split. It feels too cumbersome to send an invoice per unit. As a customer receiving these invoices, I would not be happy.
    Anyway, if you follow the logic to have tables SalesParmTable, SalesParmUpdate, and SalesParmLine filled like the user will create these invoices via the user experience, you can set the update quantity to one. You can create a loop based on the line quantity of the packing slip details. 
  • YB-04071507-0 Profile Picture
    YB-04071507-0 9 on at
    Split invoice based on quantity in paching Slip
    Yes, I need to create separate invoice for each unit.

     
    While posting Invoice with quantity equal to packing Slip with update = 10 (for exemple)
    I should create 10 invoices.
     
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,524 Super User 2024 Season 2 on at
    Split invoice based on quantity in paching Slip
    Hi,
     
    Can you tell us more about this requirement? What is the exact business process behind this? Were the goods also delivered on by one? In case you will have a quantity of 10, do you then need 10 invoices as well? 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans