Create Invoices using code...

thetallblokethetallbloke Member Posts: 66
Hi guys,

I need to create Sales Invoices (and eventually Purchase Invoices) for a customer but doing it automatically through C/Side code...

I have a dataport that imports a whole heap of data into our system and basically only want the user to enter a few details on the Dataport Options form and have the rest automated, to the point of posting to the GL, printing/email/faxing the invoice and finalising it all, as if they'd done it manually...

I know all the details for the Invoice, customer no., line items, etc.. my question is, do I just go and create the records in the Header/Line tables manually, or is there some pre-existing functions that I can call to do everything for me correctly...??

Any help would be very much appreciated..

Thanks
.
I'm not crazy !!! Just ask my toaster...
.

Answers

  • kinekine Member Posts: 12,562
    Do you mean posted Invoices or creating Sales Invoice, post it...?

    I hope that the second case.

    You need to create the header and lines in correct way and run the necessary codeunits to post it, print it etc.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • punossoundpunossound Member Posts: 35
    I already done the same thing as your scenario. The main thing you should consider is "validation of fields" and posting the transaction the right way (Just like Kine says).

    Cheers!
    ma
  • thetallblokethetallbloke Member Posts: 66
    Kine,

    Second case... I need to Create a Sales Invoice and then Post & Print the Sales Invoice..

    I was just hoping someone could point to the right code unit(s) and functions to create the invoice lines, etc...
    .
    I'm not crazy !!! Just ask my toaster...
    .
  • kinekine Member Posts: 12,562
    There is no "generic" function for that, but you can look at codeunit 99008504 function "CreatePurchaseDocument" which is creating purchase doc. from some external data. You can use this example for the raw structure how to do that. After you insert all the data and you validate the created document manually (just import it first, check if all is correctly created etc.), you can call the posting codeunit to this document to post it...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,307
    I'd probably design it in a commerce gateway type scenario. Import the data into staging tables, and process the information from there. That way you have a records of what was imported, and you can develop proper exception handling.
  • thetallblokethetallbloke Member Posts: 66
    Daniel,

    The data is actually coming into a staging area, I just chose not to mention that to reduce some of the complexity of the problem...


    Kine,

    I'll have a look at that code unit...

    Thanks
    .
    I'm not crazy !!! Just ask my toaster...
    .
  • DenSterDenSter Member Posts: 8,307
    The way I usually approach these 'automated tasks' scenarios is to do the task manually, and debug the process as I go along. I try not to get caught up in the details, but to see if I can discover already existing functions in the application that I can use to automate the task.

    The logical places to find order creation functions would be on requisition, planning, MRP type functionality, places like that. Maybe you can steal some logic from order creation routines from blanket orders.

    Then when you have a good idea about how it's done in the standard app, you can use similar logic to create your own system.
  • jlandeenjlandeen Member Posts: 524
    I'll second punossound's comment - field validiation and the order that fields are validated will probably be critical when you automate the tasks. I've automated this task several times in the past and I would recommend that you break the development down into 2 stages - order creation and everything else (posting, printing, etc.). This way you can create the Sales Headers & validate all of the fields and manually check order before it posts.

    Auto posing and printing is fairly straight forward - you just call codeunit 80 or 90 dependong on whether it's sales or purchases and pass it the Sales/Purchase header record.

    One word of caution here as you mentioned printing as well. Make sure that you commit or otherwise seperate things out so that your printing process DOES NOT keep locsk on those Sales & other ledger type tables. I've seen auto posting & printing scenarios where performance degrades significantly because the print part of the process is taking a while to complete and tying up other users from posting.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • thetallblokethetallbloke Member Posts: 66
    Thanks guys..

    You've been most helpful... I really appreciate the time you've taken to answer my question...

    Hopefully not too much more ](*,) for me now... :-)
    .
    I'm not crazy !!! Just ask my toaster...
    .
  • DenSterDenSter Member Posts: 8,307
    You're very welcome mate :mrgreen: and please do come back with any question you have, we're all happy to help out.
Sign In or Register to comment.