1. Martha Weller
  2. Valentina Studio
  3. Friday, March 10 2023, 03:59 PM
  4.  Subscribe via email
I have related tables: Invoices and InvoiceItems. I have created a 1:M link between them. How do I add an invoice and then add the items? I have looked at the lesson for related tables, but it seems to deal only with editing, not adding. I know how to create a button and use the show dialog action to open a form, but how do I get the invoiceID of the record I just created? Is there an automatic way to do this? Help! thanks.
Comment
There are no comments made yet.
Sergey Pashkov Accepted Answer
Hello Martha,

What database is used? Returning an ID of just inserted record is not supported by all database engines.
An invoice record can be inserted via SQL, and then (after getting its ID) continue editing it in the form with the list of invoice items.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 1
Martha Weller Accepted Answer
Thanks for the quick reply. I've created a valentina database.


I was hoping to have a form where you could add a record, refresh the form so that it pointed to the last record. Then, I would have an "Add Invoice Item" button. This button would need to get the invoiceId of the record just added and use that value to pre-populate the invoiceId field of the Add_InvoiceItems form. I understand your suggestion to use SQL and I may do that. I may just enter the invoice, note the id number and then enter the items separately in the data editor.

I would prefer to know how to create a form to do this. My problem is that I don't know how to refer to the objects of the form and get their value and to pass that value to another form.

In one example in Form Editor - Scripts, you have

name = this.cboName.currentText;

Question: is there a way to see if the value is being read properly. I'm used to environments where you can debug, or use a "put" statement or something like that.

In another example in your Form Editor - Scripts section that hints at what to do, but isn't quite what I need.

Import Forms
It is possible to execute one form from another, get data from it:

import '/UserDetails' as dlg;
if( dlg.exec() )
this.cboUser.currentIndex = this.cboUser.ids.indexOf( dlg.getUserAddedId() );

I don't understand this example or what it does. There is no real explanation along with it.

To make it as simple as possible for me, I gave up on starting with adding an invoice. Instead, I have an edit form that has the invoice already entered. I want to click a button "Add Invoice Item" , get the current value in a line edit field called "fldInvoiceID", store that value in a variable, open the Add_InvoiceItem form and put that value into the form in the appropriate field.

The import example above looks promising. I just don't understand it.

Finally, is their any training offered beyond the few examples in the help sections? I used to program a lot in Microsoft Access, using visual basic for applications. I don't expect Valentina Studio Pro to be that robust, but I need to learn how to control objects to read from and write to them.

Thanks,

Marty
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 2
Sergey Pashkov Accepted Answer

Question: is there a way to see if the value is being read properly. I'm used to environments where you can debug, or use a "put" statement or something like that.



Usual for JavaScript console can be used, and the text is added to the log below the form layout area:
console.log( 'some text' );

Or a message box:
QMessageBox.information( 'Title', 'Information.' );
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 3
Sergey Pashkov Accepted Answer
Thank you, Kevin, I think we'll add an example with related records as it's more complicated.

In the current implementation I can see it can be done using the following forms:

Form 1 - "Add Invoice" - includes only information about the invoice without its items
Form 2 - "Edit Invoice" - includes information about the invoice and a list of invoice items
Form 3 - "Add Invoice Item"

So after filling in the main information in the "Add invoice" form, "Edit invoice" is shown where we can call the "Add Invoice Item" form to fill individual items.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 4
Sergey Pashkov Accepted Answer
I added an example, the start form is Invoices.

For Valentina DB, it was necessary to add sorting by the primary key (because it is sorted by RecID), so a new record is always the last with sequential keys.
For other database engines, records are sorted automatically.

Editing of a specific invoice item is implemented using filtering, so this approach can be used if the position of the target record is unknown.
Attachments (1)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 5
Martha Weller Accepted Answer
Thanks so much for all of the information and the sample project. I will work this in the next day or two and let you know how it goes. What wonderful support! Marty
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 6
Martha Weller Accepted Answer
I've looked over what you sent. I have a few questions:

1. Can you tell me where to find the car catalog project?

2. This is the code for the + button (to add an invoiceItem)
import '/Add_Invoice_Item' as dlg
dlg.setInvoiceID( this.records.getField( 'fldInvoiceID' ).value );
if( dlg.exec() )
this.TableView.scrollToBottom();

I understand what it is doing, but I would like to understand the mechanics better.

Ok. You are "importing" the Add_Invoice_Item form, giving it a reference of "dlg". What is "dlg.setInvoiceID"? I tried to locate some event or method and I don't know where it is. Also, is this javascript? I really need to brush up on javascript -- it's been a while. I've looked in the Valentina help and I found some information about creating events, but I don't know how you access the create event dialog that is shown.

this.records.getField('fldInvoiceID').value. -- is there a reference that goes through this type of operation for valentina? I probably just don't know what to call this.

I've searched the help for javascript and found this:

"You can consult the Qt QML documentation on the Qt website for more insight into how Valentina API calls work in JavaScript."

I've been to the QT website and have searched on things like tableview. I see some information but, unfortunately, it's at a much lower level than I know what to do with.

Anyway, this is great progress! Thanks for your time and patience,

Marty
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 7
Kevin Accepted Answer
Have you seen this example:

Car Catalog Project

It doesn't answer all of your questions.

It contains an "add" form. During the process of creating a form one is presented with several Data Mode options. I believe "Edit" is the default. "Add" is available. The "Add" form will automatically include an "Add" button with the underlying "add" script.
References
  1. https://valentina-db.com/docs/dokuwiki/v13/doku.php?id=valentina:products:vstudio:examples:forms:car_catalogs
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 8
Kevin Accepted Answer
Sergey, if you can delete all my posts in this thread except the last one ... go for it. I thought I was editing (so the URL would appear correctly), but I was quoting.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 9
Sergey Pashkov Accepted Answer
1. It's on the Start Page, the third column contains example projects along with the recent ones.
2. setInvoiceID - it is a custom method of the Add_Invoice_Item form, these methods can be found using the third button in the top-left corner of the form editor.

There is a brief built-in documentation (use the first button in the top-left corner of the form editor).
Description of Qt classes is generated automatically and some methods may not be used directly (if necessary, we extend the object model to support it)

this - FormAccessor - access to the current form object
3. this.records - records set of the current form
4. this.records.getField('fldInvoiceID') - returns the specified field from the base cursor
5. this.records.getField('fldInvoiceID').value - a value of this field for the current position

I attached screenshots for each number
Attachments (5)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 10
Kevin Accepted Answer
Valentina Studio Pro 13.1 (64-bit)
Valentina Studio Pro 13.3.1 (64-bit)

Windows 10

project_invoices.zip (the sample database above)

I was trying to understand the code and I was entering entries, deleting entries, and so on. I then realized the wrong entries were being deleted, even though the prompt displayed the correct invoice number.

So, I started with a fresh copy of the files and did the following:

Two customers exist: Customer 1 and Customer 2.

I add a new customer: Customer 3. I do not add any items related to the customer.

I delete Customer 2.

A prompt appears: Do you really want to delete invoice 24 [Customer 2]

I click on Yes.

Customer 3 is deleted.

If one creates more customers: Customer 4, Customer 5, Customer 6.

Delete Customer 4. Works.

Delete Customer 6. Customer 1 is deleted.

Delete Customer 5. Customer 2 is deleted.

In all cases the correct invoice number is displayed on the prompt.

I don't know if the problem exists in the code behind the forms, the program itself, or user error.

Thanks.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 11
Sergey Pashkov Accepted Answer
Thank you, we'll check it shortly
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 12
Sergey Pashkov Accepted Answer
Right, the issue is that TableView changes the current position in the cursor after showing the message box.
Restoring the position fixes it.
Attachments (1)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 13
Kevin Accepted Answer
Thank you.

What is the purpose of:

this.TableView.editTriggers = QTableView.NoEditTriggers;

Found in: Invoices, TableView, Signals, QObject, created.

I see this in the QTableView Class documentation (am I in the correct place?):

The QTableView class provides a default model/view implementation of a table view.

editTriggers -> Number
This property is a selection of EditTriggers flags combined using the OR operator. The view will only initiate the editing of an item if the action performed is set in this property.

EditTrigger
NoEditTriggers 0
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 14
Sergey Pashkov Accepted Answer
NoEditTriggers is set to disable inline editing in the table view.
There is a separate form, so it is not necessary.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 15
Kevin Accepted Answer
Thank you!
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 16
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Categories

Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 2 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories