Topic: Receipts on sales mandate

Hello to all,
I would like to make a new project but I set my sights even before I started.
Beyond a typical registry table on which I have no doubts, a customer brings some things to sell, can be a single item or more on a certain day. The same customer can bring one or more items to sell on another day.
So in the end I should make a receipt for the first day and one for the second day, obviously on the first receipt there must be the list of items brought on the first day and on the second receipt instead the list of items brought on the second day, considering that the same customer can bring items to sell more than once a year.
In short, the same customer must receive receipts by automatically including only the objects of that particular situation.
I immediately insisted because I don't understand what structure of tables I should do for items to sell and any sales mandate.
I hope I managed to explain.
Someone who can give me some advice?
Thank you and greetings.

Re: Receipts on sales mandate

Hi,
I would use 3 tables as follows:
1.  Customer (basic information)
2.  ReceiptSummary
3.  ReceiptDetail
The relationship between Customer and ReceiptSummary is 1:many.
The relationship between ReceiptSummary and ReceiptDetail is 1:many
This allows one or a number of customers to sell one or a number of items on one or a number of different days.
Please have a look at the attached example and see if it helps.
Regards,
Derek.

Post's attachments

Attachment icon reteinformatica2.zip 342.58 kb, 398 downloads since 2019-04-26 

Re: Receipts on sales mandate

Hi derek,
as always thank you very much. I'm trying to understand your project to be able to apply it to mine.
For the moment I immediately had a doubt: in your project I tried to create a button to print a report with the list of all the articles of a receipt but I didn't understand anything.

Re: Receipts on sales mandate

Hi,
Perhaps try it like this (see attached).
Derek.

Post's attachments

Attachment icon reteinformatica2 with print.zip 344.95 kb, 426 downloads since 2019-04-26 

Re: Receipts on sales mandate

Bravo derek!
that's just what I wanted. Only now I have to study well because at the moment I haven't understood anything! yikes

Re: Receipts on sales mandate

reteinformatica wrote:

Bravo derek!
that's just what I wanted. Only now I have to study well because at the moment I haven't understood anything! yikes

Please check out this book
http://myvisualdatabase.com/forum/viewtopic.php?id=2694

Dmitry.

Re: Receipts on sales mandate

I'm reading. I Always forget it exists.

Re: Receipts on sales mandate

Hi Derek,
studying your project there are some things that I didn't understand.
I saw that it also performs calculations, but if I remove "scripts" the calculations are gone. In the scripts section, at least as far as I understand, there are no instructions for making calculations.
What interests me, is that it would have been one of the things I wanted to ask to do calculations.
Could you kindly explain this to me?
Thank you!

9 (edited by derek 2019-04-29 19:26:24)

Re: Receipts on sales mandate

Hi,
There are a couple of things to understand when using calculated fields.
Calculated fields only exist while your program is running - as soon as the program closes, the calculated fields are gone.  For example, you would save someone's date of birth but you wouldn't save their age - that would be data redundancy.  Instead, you calculate their age every time the program runs using a calculated field so it is always up to date, but as soon as the program closes, their 'age' is gone.
So you are correct when you say that there are no instructions DIRECTLY relating to calculated fields in the script.  But what the script does is
1)  run a search when the program starts so that all the columns in the tablegrid are populated - including calculating the calculated fields.
2)  when any data is saved, the calculated fields need to be 're-calculated' - this is what the 'dbupdate' statements are doing in the script.
So when you removed the script, the calculated fields didn't appear because you removed the instruction to calculate / re-calculate them.
I hope I've explained that okay.
I've attached the project again with some comments in the script that may help.
Regards,
Derek.

Post's attachments

Attachment icon reteinformatica2 with print.zip 345.05 kb, 411 downloads since 2019-04-29 

10 (edited by reteinformatica 2019-04-30 08:26:08)

Re: Receipts on sales mandate

Hi derek,
thanks as usual.
The instructions in the script section I had more or less understood, I didn't understand why removing the scripts the calculations disappeared too.
From what you tell me but above all from what I understand, if I want the results of the calculations to be saved in a record, I don't have to use calculated fields. Did I get it right?

Re: Receipts on sales mandate

Yes, you understand it correctly - calculated fields are temporary and only exist when the program is running.  Saved fields exist even when the program is closed.

Re: Receipts on sales mandate

Well, at least I know I'm understanding something.
What is the code to set a variable that is the value of a textbox?

Re: Receipts on sales mandate

Hi,
In your script, first declare your variable
var  variable1: string; 

and then
variable1 := form1.edit1.text;

Derek.

Re: Receipts on sales mandate

Thanks derek,
please teach me to do the calculations with Delphi. At school I studied Pascal and Visual Basic but we talk about it many years ago.
With these memories I managed to develop simple calculations such as subtractions, sums, multiplications and divisions but I stopped myself by not understanding the right code for expressions and percentages.
I enclose the project where I tried, you should understand what I tried to do, I also put a comment.
Thanks derek you are always very kind.

Post's attachments

Attachment icon calcoli.zip 334.46 kb, 392 downloads since 2019-05-02 

Re: Receipts on sales mandate

Hi,
I always try to keep things simple (LOL!) so in this example, I would use the percentage value that you enter in form1.edit4 directly - there is no need to create a separate variable.
procedure Form1_Edit4_OnChange (Sender: TObject);
begin
  Form1.Edit5.Value:=(Form1.Edit2.Value * Form1.Edit3.Value) - (form1.edit4.value / 100);
end;
Please see attached.
Derek.

Post's attachments

Attachment icon calcoli.zip 347.53 kb, 350 downloads since 2019-05-02 

Re: Receipts on sales mandate

Thanks derek,
is it correct to use "OnChange" event or is there better code?

Re: Receipts on sales mandate

Hi,
Yes, I would always use 'onchange' for something like this.
You might also think about putting an 'onchange' event against 'selling price' and 'quantity' as well because these are also used in your calculation and you could change these values but it wouldn't automatically recalculate until you changed (or re-entered) 'percentage gain'.
Rather than repeat the calculation on each 'onchange' event, I put it in my own procedure (because it's easier to maintain - if you change the calculation, you only have to change it in one place in the script).
Derek.

Post's attachments

Attachment icon calcoli.zip 347.68 kb, 372 downloads since 2019-05-02 

18 (edited by reteinformatica 2019-05-02 14:16:29)

Re: Receipts on sales mandate

And now, sorry for all these questions, I would like to close the previous form when you open a form.
I tried this but it all closes:

procedure frmInfo_OnShow (Sender: TObject; Action: string);
begin
  frmstart.close;
end;

Re: Receipts on sales mandate

Sorry, but I can't quite work out what you're trying to do.
Can you attach your program?

Re: Receipts on sales mandate

Sure, sorry!

Post's attachments

Attachment icon Closeform.zip 322.25 kb, 361 downloads since 2019-05-02 

21 (edited by derek 2019-05-02 19:38:52)

Re: Receipts on sales mandate

Hi,
If Form1 is your main form (the first 'tab' on the left of your form tabs - see attached screenshot), then all the other forms are called from Form1.  So if you try to close Form1, all the other forms that are called by Form1 will close as well.
Make Form2 the first tab (drag it to the left) and then open Form1 by script.
Derek.

Post's attachments

Attachment icon Closeform2.zip 445.65 kb, 354 downloads since 2019-05-02 

Re: Receipts on sales mandate

reteinformatica,
Another option would be to hide the first form rather than trying to close it. It gives the same result.


procedure Form2_OnShow (Sender: TObject; Action: string);
begin
  Form1.Hide;
end;

23 (edited by reteinformatica 2019-05-03 17:03:33)

Re: Receipts on sales mandate

Thanks very much to you too ehwagner and as always to you derek.
derek, I tried to translate most of your teachings into my project, I still have to finish. Unfortunately I am faced with a problem that I cannot solve. This is the modification of my first project that you already know well and on which you have already given me a great hand.
In practice I tried to make a copy of the "frmContratto" form on the "frmRicevuta" form. To save time I have copied and pasted the controls in the new form (frmRicevuta) but I don't know if it is a correct procedure, then I made the necessary changes but something I did wrong.
If you remember in the "frmContratto" form, selecting the first gridtable a name in the second gridtable gave me the list of contracts related to the user, then it was enough to click on the contract and the press would start.
In the copy form (frmRicevuta) this function has disappeared or the association of documents to the user.
In addition, if I click twice on the user name, the user search works, nothing happens while the "frmListaricevute" form should open, the "Modify" button has the same behavior. In any case I would ask you to take a look at the project I am attaching, by launching the executable you need to choose "Ricevuta" to see the behavior I described.
I don't know how to ask you any more thanks!  Sooner or later I will learn.

Post's attachments

Attachment icon Super.zip 345.24 kb, 355 downloads since 2019-05-03 

24 (edited by derek 2019-05-04 14:54:10)

Re: Receipts on sales mandate

Hi,
It took a while to remember what your project does and the things that are in it!
Sometimes when you copy and paste controls from one form to another, everything works fine.  Other times, it is easy to forget to change 1 or 2 elements and it causes more problems than it's worth!
There were a couple of things that I noticed;
1.  on a couple of forms, you had fields belonging to a table 'dettagliricevuta' that no longer exists.   When you make a lot of changes to your database structure, the definitions can very occasionally get out of synchronisation!
2.  your join between 'listaricevute' and articoliricevute' was the wrong way round.  Any data you had entered into these two tables will not be showing correctly so I suggest you clear these out and start fresh.
3.  there were 'edit' buttons which were set to 'showform' rather than 'showrecord'.
4.  one of the search buttons was pointing to the wrong table.
Please see the attachment.
Derek.

Post's attachments

Attachment icon Super.zip 364.57 kb, 408 downloads since 2019-05-04 

25 (edited by reteinformatica 2019-05-06 18:11:02)

Re: Receipts on sales mandate

Hi derek,
undoubtedly it is not easy to remember things from the past in this world for this I do not know how to thank you. The names are also written in Italian!
I spent almost 8 hours on this project without a pause, between names, properties, accounts, etc. by now I was breaking down.
However the program, thanks to you, works very well. I have only one last little problem: although I have set all the fields where the figures go as "Currency", in the report only the field "Articoliricevuta.prezzovendita" (frmArticoli) puts me two decimals and the symbol €
I meticulously checked the properties of the controls but they are, at least it seems to me, all the same.

EDIT:
OK, I find it in the format field properties of report.