Request help for last purchase cost

Discussion in 'Free Source Codes' started by panam, Apr 30, 2023.

    
  1. panam

    panam Member


    lastpurprice.jpg no purchaseprice.jpg Dear Experts,
    i want to get last purchase cost while entering a new purchase invoice in purchase voucher.
    but my code is not working in creation mode but working in alteration mode(saved purchase bill)

    [#Line: EI COLUMNONE]
    ADD:Right Field:At Beginning:LPURCOST

    Local:Field:LPURCOST:INFO:LPUR

    [#Line:EI invinfo]
    Add:Right Field:At Beginning:LPURCOST


    [Field:LPURCOST]
    Use:number field
    Set:$lastpurcprice:stockitem:$stockitem
    Width: 9
    Color: BLUE
    Style: NORMAL BOLD
    Skip : YES
    Set Always: Yes
     


  2. sattam

    sattam Active Member


    $LastPurcPrice:StockItem:$StockItemName
     
    panam likes this.


  3. panam

    panam Member


    thank you very sir for the help but still code is not working.

    [#Line: EI COLUMNONE]
    ADD:Right Field:At Beginning:LPURCOST

    Local:Field:LPURCOST:INFO:LPUR

    [#Line:EI invinfo]
    Add:Right Field:At Beginning:LPURCOST

    [Field:LPURCOST]
    Use:number field
    Set as:$LastPurcPrice:StockItem:$StockItemName
    Width: 9
    Color: BLUE
    Style: NORMAL BOLD
    Skip : YES
    Set Always: Yes
     


  4. panam

    panam Member


    dear experts,
    now my tdl is working fine but how to remove units field (/nos) in my udf.

    [#Line: EI COLUMNONE]
    ADD:Right Field:At Beginning:LPURCOST

    Local:Field:LPURCOST:INFO:LPUR

    [#Line:EI invinfo]
    Add:Right Field:At Beginning:LPURCOST

    [Field:LPURCOST]
    Use:rate field
    Set As:$LastpurcPrice:StockItem:$StockItemName
    Width: 14
    Color: red
    Style: NORMAL BOLD
    Skip : YES
    Set Always: Yes

    but if iuse number field, code is not working

    a.jpg
     


  5. love

    love Member


    try
    Use : Rate Price Field
     
    panam likes this.


  6. udaya

    udaya Active Member


    Field:LPURCOST]

    Use : Rate Field
    Set : $lastpurcprice:stockitem:$stockitem
    Skip : Yes
    Color : Red
    Style : Large Bold
    Width : 13
     
    panam likes this.


  7. udaya

    udaya Active Member


    upload_2023-5-1_7-25-44.png
     
    panam likes this.


  8. Mac

    Mac Member


    nice one sir , but what if we need avg purchase discount of item ? and avg sales margin
     
    Last edited: May 1, 2023


  9. panam

    panam Member


    Sir, how to remove units field (/nos) in my udf.
     


  10. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    [#Line: EI COLUMNONE]
    ADD:Right Field:At Beginning:LPURCOST, LPURCOST1
    Local:Field:LPURCOST:INFO:LPUR
    Local:Field:LPURCOST1:INFO:LPUR

    [#Line:EI invinfo]
    Add:Right Field:At Beginning:LPURCOST, LPURCOST1

    [Field:LPURCOST]
    Use:rate field
    Set As:$LastpurcPrice:StockItem:$StockItemName
    Width: 14
    Color: red
    Style: NORMAL BOLD
    Skip : YES
    Set Always: Yes
    Invisible : yes

    [Field:LPURCOST1]
    Use: number field
    Set As: $$Number:#LPURCOST
    Width: 14
    Color: red
    Style: NORMAL BOLD
    Skip : YES
    Set Always: Yes
     
    panam likes this.


  11. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    Make a new collection of purchase voucher........ do 2 things in that...
    Compute the number of items i.e. number of purchase vouchers.
    Aggregate compute the discount "as amount" in all purchase vouchers and divide this total by the number of purchase vouchers and you get your average.

    Show this value in a Field in your voucher.

    On a personal note - do not understand the requirement for a "avg purchase discount" as that computed value has no bearing to the reality of changing business deals.
     
    panam likes this.


  12. panam

    panam Member


    Thank u Amit sir for your valuable time and help. now code is working fine.
     


  13. Mac

    Mac Member


    si

    sir, party give discount on what they get from supplier...thats why they need , i had tried as you say , thats type work on report but on voucher not getting value
    below is the code.

    [Field:AVG_PUR_DIS]
    Inactive:Not @@IsOrder
    Use : Amount Field
    Width : 25 mm;@@VCHDiscountWidth
    Align : Center
    Style : Normal Bold
    Set as:$$Number:$Discount;/$$Number:$ActualQty
    Set always : Yes
    Border : Thin Right
    Storage: Avgpurdis




    [Collection : MySalesSummaryCollection]
    Title : "List of Sales vouchers"
    Type : Vouchers : VoucherType
    Child of : $$VchTypePurchase
    Belongs to : Yes


    [Collection : MySalesItems]

    Source Collection : MySalesSummaryCollection
    Walk : Inventory Entries
    By : StockItemName : $StockItemName:StockItem:#VCHStockItem
    Sort : StockItemName : $StockItemName:StockItem:#VCHStockItem
    Aggr Compute : ActualQty : Sum : $ActualQty
    Aggr Compute : Rate : Sum : $Rate
    Aggr Compute : Amount : Sum : $Amount
    Aggr Compute :Discount : Sum : $Discount;$Amount
    Keep Source : ().
     


  14. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    Define the computed values in Object: Voucher

    Object : Voucher
    myvalue1: thisone
    myvalue2 : thisone2 ...............

    Then use the above in your code.
     


  15. Mac

    Mac Member


    i try like this sir, but didn't work

    [Collection : MySalesItems]

    Source Collection : MySalesSummaryCollection
    Walk : Inventory Entries
    By : StockItemName : $StockItemName;:StockItem:#VCHStockItem
    Sort : StockItemName : $StockItemName;:StockItem:#VCHStockItem
    Object:Voucher
    Aggr Compute : ActualQty : Sum : $ActualQty
    Aggr Compute : Rate : Sum : $Rate
    Aggr Compute : Amount : Sum : $Amount
    Aggr Compute : Discount : Sum : $Discount;$Amount
    Keep Source : ().
     


  16. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    [#Object : voucher]
    myActQty : $$ReportObject:$$FilterAmtTotal:MySalesItems:StkItmExists:$ActualQty

    [System: Formulae]
    StkItmExists : $StockItemName = $$ReqObject:$Name

    In your explode collection....
    Compute : myActQty : $myActQty

    And so on............
     


  17. Mac

    Mac Member


    li

    like this sir ?


    [#Object : voucher]
    myActQty : $$ReportObject:$$FilterAmtTotal:MySalesItems:StkItmExists:$ActualQty

    [System: Formulae]
    StkItmExists : $StockItemName = $$ReqObject:$Name




    [Collection : MySalesItems]

    Source Collection : MySalesSummaryCollection
    Walk : Inventory Entries
    By : StockItemName : $StockItemName;:StockItem:#VCHStockItem
    Sort : StockItemName : $StockItemName;:StockItem:#VCHStockItem
    Aggr Compute : myActQty : Sum:$myActQty
    Aggr Compute : ActualQty : Sum : $ActualQty
    Aggr Compute : Rate : Sum : $Rate
    Aggr Compute : Amount : Sum : $Amount
    Aggr Compute : Discount : Sum : $Discount;$Amount
    Keep Source : ().
     


  18. Mac

    Mac Member


    SIR Still Not working, here i share the whole code ,kindly suggest

    [System:Formula]
    IsOrder: $$IsSalesOrder:##SVVoucherType



    [#Line: EI ColumnOne]


    Left Fields : VCH ItemTitle,Partcode_L,AVG_PUR_DIS_L



    Local : Field :partcode_L : Space Left : 18










    [Field:partcode_L]
    Use:Name Field
    Width: 25 mm
    Info:"Part Code"
    Align:Center
    Inactive:Not @@IsOrder

    [Field:AVG_PUR_DIS_L]
    Use:Name Field
    Width: 25 mm
    Info:"AVG PUR DISC"
    Align:Center
    Inactive:Not @@IsOrder


    [#Line : EI InvInfo]



    Left Fields : EI DeemedPos, VCH StockItem,PartCode,AVG_PUR_DIS




    [Field:partCode]
    Inactive:Not @@IsOrder
    Use : Name Field
    Width : 25 mm;@@VCHDiscountWidth
    Align : Center
    Style : Normal Bold
    ; Set always : Yes
    Border : Thin Right
    Storage:partcode
    Set as:$partno:StockItem:$StockItemName


    [Field:AVG_PUR_DIS]
    Inactive:Not @@IsOrder
    Use : Amount Field
    Width : 25 mm;@@VCHDiscountWidth
    Align : Center
    Style : Normal Bold
    Set as:$$Number:$myActQty;$Discount;/$$Number:$ActualQty
    Set always : Yes
    Border : Thin Right
    Storage: Avgpurdis



    [Collection:product ]

    Use : Alias Collection
    ;Title : $$LocaleString:"List of Stock Items"
    Type : Stock Item
    Fetch : Name
    Fetch:partNo
    ;Report : Stock Item
    ;Variable : SStockItem
    ;Trigger : SStockItem
    ;IsODBCTable : Yes


    [System:UDF]

    Partcode :String: 20001

    Avgpurdis :Amount: 28


    [Collection : MySalesSummaryCollection]
    Title : "List of Sales vouchers"
    Type : Vouchers : VoucherType
    Child of : $$VchTypePurchase
    Belongs to : Yes
    Format : $VoucherNumber, 20
    Fetch : VoucherNumber
    Fetch : Inventory Entries
    ;Filter : EBFIsOfSelectedVchNo
    ;Sort : @@InvoiceNumberIncr :$VoucherNumber


    ;[Collection : MySalesSummaryCollection]
    ;Title : "List of Sales vouchers"
    ;Type : Vouchers : Stock Item;VoucherType
    ;Child of :$$BaseOwner:#VchStockItem; $$VchTypePurchase
    ;Filter:pOnly
    ;Belongs to : Yes
    ;Format : $VoucherNumber, 20
    ;Fetch : VoucherNumber
    ;Fetch : Inventory Entries
    ;Filter : EBFIsOfSelectedVchNo
    ;Sort : @@InvoiceNumberIncr :$VoucherNumber

    [#Object : voucher]
    myActQty : $$ReportObject:$$FilterAmtTotal:MySalesItems:StkItmExists:$ActualQty

    [System: Formulae]
    StkItmExists : $StockItemName = $$ReqObject:$Name




    [Collection : MySalesItems]

    Source Collection : MySalesSummaryCollection
    Walk : Inventory Entries
    By : StockItemName : $StockItemName;:StockItem:#VCHStockItem
    Sort : StockItemName : $StockItemName;:StockItem:#VCHStockItem
    Aggr Compute : myActQty : Sum:$myActQty
    Aggr Compute : ActualQty : Sum : $ActualQty
    Aggr Compute : Rate : Sum : $Rate
    Aggr Compute : Amount : Sum : $Amount
    Aggr Compute : Discount : Sum : $Discount;$Amount
    Keep Source : ().
     


  19. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    i do not have relevant tally data to try the code.

    Post the same ... I will try it on weekend if possible.
     


  20. Mac

    Mac Member



    THANK YOU AMITBHAI , HERE I SHARE SAMPLE DATA
     


  21. Mac

    Mac Member


    DATA
     

    Attached Files:



  22. Mac

    Mac Member



  23. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    No not yet tried. Will check and let you know.
     


  24. Mac

    Mac Member


    Thank You Amitbhai For Your constant Guidance.
     


  25. Mac

    Mac Member



Share This Page