Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Find the last purchase details of purchased items

Posted on by 1,835

Hello Experts,

Is there any possibilility to find the last purchase details of raw materials based on the posted purchase invoice.
I am trying with SQL server query but query is not 100% correct please give me some idea to resolve it.

My query is below.

select max(PIH.[Posting Date]),PIH.[Currency Code],[Direct Unit Cost]-([Line Discount Amount]/nullif(Quantity,0)) "Last Purchase Price",[Unit Cost (LCY)],PIL.No_ "Item No.",Description,[Document No_],
case PIH.[Incom Terms] when 0 then ' ' when 1 then 'Ex-Works' when 2 then 'FCA' when 3 then 'CPT' when 4 then 'CIP' when 5 then 'DAT' when 6 then 'DAP' when 7 then 'DDP'
when 8 then 'FAS' when 9 then 'FOB' when 10 then 'CFR' when 11 then 'CIF' when 12 then 'DAF'
when 13 then 'DES' when 14 then 'DEQ' when 15 then 'DDU' when 16 then 'FOR' end as [Incom Terms]
from [India Private Limited$Purch_ Inv_ Line] PIL
left outer join [India Private Limited$Purch_ Inv_ Header] PIH on PIH.No_ = PIL.[Document No_]
where PIL.No_<>'' and PIL.Type=2
group by PIH.[Currency Code],[Direct Unit Cost]-([Line Discount Amount]/nullif(Quantity,0)),[Unit Cost (LCY)],PIL.No_ ,Description,[Document No_],
PIH.[Incom Terms]

*This post is locked for comments

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Find the last purchase details of purchased items

    Check the Item Value Entries for the Document Type Purchase Invoice.

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: Find the last purchase details of purchased items

    You can write a code in NAV also.

    User Item table and Purchase Invoice Line table.

    ltPurchInvLine.SETRANGE(Type,ltPurchInvLine.Type::Item);

    ltPurchInvLine.SETRANGE("No.","No.");

    ltPurchInvLine.SETRANGE("Variant Code","Variant Code");

    IF ltPurchInvLine.FINDLast THEN

     //Write code to get details from that invoice line

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans