0

Duplicate information from one table to another table depending of the status selected

Hello :), 

I have created a parent Table for the quotations I send to my clients. I called it 'Quotation'

What I'm trying to do is once the quotation has been accepted by my client, I would like by clicking on a button for example to transform my quotation to an invoice with a unique invoice number (Basically just changing the quotation number by the invoice number).  

I understand I will need to create a Parent table for my invoices. How do I copy my initial quotation from my parent table 'Quotation' to my parent table 'Invoice'without having to enter all the information again? Also I want the initial quotation to stay in my parent table 'Quotation' even after being invoiced. 

I hope it makes sense ... :) 

4 replies

null
    • Nick
    • 4 yrs ago
    • Reported - view

    Hi!

    I'm using this code to convert Sales Order to Invoice with a button:

    ---

    "//--------Define Order ID in variable";
    let myId := Id;
    "//--------Get customer info";
    let cli := Customer;
    let disc := 'Discount %';
    let tax := Customer.'Tax Rate';
    "//--------Create new invoice";
    let c := (create Invoice);
    "//--------Transfer the customer info in the new invoice";
    c.(Customer := cli);
    c.('Discount %' := disc);
    c.('Tax Rate' := tax);
    "//--------Select order items correspond to the order";
    for i in select 'Order items' where Order.Id = myId do
    "//--------Create invoice items";
    let ilt := (create 'Invoice Items');
    "//--------Give the ID of the new invoice to invoice items";
    ilt.(Invoice := c.Id);
    "//--------Get ref field item in order";
    let item := i.Product;
    "//--------Give ref field item in new invoice";
    ilt.(Item := item);
    "//--------Get other info";
    let myQ := i.Qty;
    ilt.(Qty := myQ);
    let myP := i.Price;
    ilt.(Price := myP);
    let myD := i.'Disc %';
    ilt.('Disc %' := myD);
    openRecord(c)
    end;
    alert("Invoice created succesfully")

    ---

    Please study the code, change the names of the fields and tables, and also remove any commands you don't need.
    The above code does not delete the order.

    Don't hesitate to ask...

    Happy Ninoxing!

    • maroon_banana
    • 4 yrs ago
    • Reported - view

    Hi Nick, 

    Thank you so much for your help. 

    I'm still pretty new to Ninox, so my question might sound stupid... 

    Did you create a new Parent table for your invoices and where did you write your formula please? 

    Thank you :)

    • Nick
    • 4 yrs ago
    • Reported - view

    No problem!

    My model is:

    - Order table with subtable Order Lines

    - Invoice table with subtable Invoice Lines

    - Button "Create Invoice" with the above code in Order form

    - Customers and products tables (ofcourse)

     

    The button sets variables with all info and creates a new record in the Invoice table and new record(s) in the Invoice Lines table.

    Example: Sales Order for customer A with 10 line items will create an Invoice for customer A with 10 line invoice items.

     

    I hope it's clear...

    • maroon_banana
    • 4 yrs ago
    • Reported - view

    Thank you Nick,

    I have tried to work around your formula but I gave up for the moment. 

    But thank you :)

Content aside

  • 4 yrs agoLast active
  • 4Replies
  • 1388Views