Is there any example for an invoice???

Is there any example for an invoice???

PaucharanPaucharan Posts: 8Questions: 2Answers: 0

Hello,

I´m trying to make an invoicing datatables but I´m unable to find a solution for this problem. The question is that I need that when I change the price of an element (with inline editing) it should take the quantity of elements and with this two numbers should update the "TOTAL" cell.

The problem is that I don´t know how to get the cells reference and write in them...

Data is loaded also with the editor from a database.

Could anyone help or show me an example? Thank you in advance.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @Paucharan ,

    This example here should help - it's updating the office field with the contents of the name field. You could use similar logic to update the total cell.

    Hope that helps,

    Cheers,

    Colin

  • PaucharanPaucharan Posts: 8Questions: 2Answers: 0

    Hello Colin,

    I really thank you for your time. That solved my issue!

    Cheers,

    Paucharan

  • PaucharanPaucharan Posts: 8Questions: 2Answers: 0

    Hello Colin,

    To do it harder now I have this part solved with your code but now I´m trying to finish the form. Now i have the editor called "editor" which updates the lines of the invoice. Apart from this I have in the same page another editor, called "invoiceHeaderEditor", which is responsible for the part that is not a table (it is a standalone editot) and gets care of total vat, total price, discount... and stuff like that.

    When I call this code from "editor": editor.set('total', '123'); it works perfectly but when I call from "editor": invoiceHeaderEditor.set('totalWithVat', '123'); it does nothing. Keeping in mind that invoiceHeaderEditor is standalone I don´t know if I have to do something extra to accomplish this.

    Thank you again for your time.

    Paucharan

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @Paucharan ,

    As you say, there's no reason why it shouldn't work from your description. Would you be able to link to your page, or update this example to demonstrate the issue, please.

    Cheers,

    Colin

  • PaucharanPaucharan Posts: 8Questions: 2Answers: 0

    Hello @collin,

    This is my example: http://live.datatables.net/sohuyuwa/1/edit

    Originaly it has a ajax script to upload results on the database that I took off since it is not going to work on that example.

    Cheers,

    Paucharan.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @Paucharan ,

    It looks like there's no edit() or submit() on that second table, so it should be something like

    invoiceHeaderEditor.edit(YOUR_RECORD_HERE, false).set('totalConIva', editor.get('name')).submit();
    

    Note the false on the edit(), that stops the edit window from being displayed. Hope that does the trick,

    Cheers,

    Colin

  • PaucharanPaucharan Posts: 8Questions: 2Answers: 0

    Hello @colin ,

    I´m sorry for bothering you again. this code is hunging my code. In other hand I was able to update the totalConIva field when updating whatever field in the second table with the event initSubmit. The second editor is called invoiceHeaderEditor. Do you how can i trigger/simulate an initSubmit or edit action over this editor? Is there any way to accomplish this?

    Thank you in advance.

    Paucharan

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @Paucharan ,

    You should just be able to listen to the initSubmit on that Editor instance. Could you link to the page causing problem, or replicate it in your earlier test case.

    Cheers,

    Colin

  • PaucharanPaucharan Posts: 8Questions: 2Answers: 0
    edited July 2019

    Hello @colin ,

    Finally I got it working with:

    tablaTotalConIva.cell(0, 0, { order: 'index' }).data(sumatorio);
    

    But I realised that it only changes the table value but not the database value. Now I have to editors called editor and editor2. When i click on any field of editor it changes its values in datatable and database with online editing:

    $('#lineasFactura').on( 'click', 'tbody td:not(:first-child)', function (e) {
            editor.inline(this, {
              submit: 'all',    
            }),
    } );
    

    But now I don´t know how to trigger an inline submit event on editor2 from editor. I tried with this code:

    $('#lineasFactura').on( 'click', 'tbody td:not(:first-child)', function (e) {
            editor.inline(this, {
              submit: 'all',
            }),
            editor2.inline().submit();
        } );
    

    Which actually makes that when i click on any editor field it changes to submit IMMEDIATELY editor2 values and foucs on editor2 field, so it is not working because I cannot focus on editor fields because of this behaviour.

    It should be more like this (waiting for the editing on editor to submit editor2 fields):

    $('#lineasFactura').on( 'click', 'tbody td:not(:first-child)', function (e) {
            editor.inline(this, {
              submit: 'all',
              editor2.inline().submit();
            }),
        } );
    

    But this is obviously not working so my question is if you know how to call this editor2.inline().submit() only when i finished changed on editor field and not before.

    Thank you again for your time and patience.

    Paucharan.

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @Paucharan ,

    editor2.inline().submit();
    

    will do nothing, as you haven't specified what to edit, or what to set the value to be. In my earlier comment I had this code (note it is using edit() an not inine()) - you'll need to do something like this:

    invoiceHeaderEditor.edit(YOUR_RECORD_HERE, false).set('totalConIva', editor.get('name')).submit();
    

    In my previous comment I suggested putting the code in initSubmit, that's still the way to go.

    Cheers,

    Colin

This discussion has been closed.