Topic: Filters and tGrid Field Display

I couldn't get products and Inv numbers displayed on form1 refund tGrids.

Also I wanted to display refund numbers on sale and purch invs tGrids to highlight to see against which invoices refund issued.
Help would be appreciated......


Please see the attached sample project below:

Post's attachments

Attachment icon tGrid Field Display.zip 17.71 kb, 398 downloads since 2017-07-09 

Adam
God... please help me become the person my dog thinks I am.

Re: Filters and tGrid Field Display

Hi Adam,
Does this fix things? (I've only changed it for the purchases, not for the sales).
Derek.

Post's attachments

Attachment icon tGrid Field Display.zip 351.18 kb, 530 downloads since 2017-07-09 

Re: Filters and tGrid Field Display

Hi Derek,


Thank you very much................
Truly appreciated................


My thinking was linking refunds table to invoice table would do the job. In any case I don't think I could have come up with the combo usage.


I've only changed it for the purchases, not for the sales

I guess you wanted me to apply same to sales for me to learn bit more; not because you couldn't do it. I have applied your solution for purchase part to original sample project for learning purposes. However, failed to apply same method to sales.


Also, I couldn't get refund prices displayed with minus (-)

Post's attachments

Attachment icon tGrid Field Display 2.zip 18.51 kb, 415 downloads since 2017-07-10 

Adam
God... please help me become the person my dog thinks I am.

Re: Filters and tGrid Field Display

Hi Adam,
I don't imagine there's any reason why the same process I used for the PIR wouldn't work for the SIR (and the only reason I didn't do the SIR was I ran out of time at this end).
I'll try and have a look later on if no one's come back to you in the meantime.
Regards,
Derek.

Re: Filters and tGrid Field Display

Hi Adam,
I've added the bit that fills in the missing SIR information and it seems to work.
With regard to showing refund prices with minus(-), I don't believe it would ever work using your approach;  it looks like you perform a (0-value) instruction every time the refund record is edited - therefore every time you edit it, the value flips between positive and negative. Pretty confusing!
The way I'd do it is to simply put a message up to tell the user they have to enter a negative value;  trying to automate it seems overly complicated, at least within your current script.
In my opinion (for what it's worth - LOL!), I think there are things wrong, both from the data structure and from the coding.  But maybe this isn't a proper project and you're just trying various things out in which case, no problem.
Derek.

Post's attachments

Attachment icon tGrid Field Display 2.zip 351.74 kb, 423 downloads since 2017-07-10 

Re: Filters and tGrid Field Display

Thanks a lot Derek... Your kind help and advice are always appreciated...........


Why I didn't think putting sql line after if statement that I don't know.


I think there are things wrong, both from the data structure and from the coding.

Please tell me wrong things. It'd be a great help for me.

Adam
God... please help me become the person my dog thinks I am.

7 (edited by derek 2017-07-10 22:51:43)

Re: Filters and tGrid Field Display

Hi Adam,
Two things stood out when looking at the 'tgrid field display' project you attached in your latest post:
1.  I'm not sure why you need a separate 'refunds' table - isn't a refund just another transaction type (you already have purchase and sales transaction types on your 'invoices' table). 
Also, as the structure of the 2 tables is basically the same.  I think storing your different transaction types in 1 table would simplify things a lot;  I would probably rename 'invoice' to 'transaction' and create a related 'transactiontype' table (with fields 'type' and 'dbcr') and see if that approach streamlined things.
2.  I noticed that in your script, if you create more than 1 refund transaction against the same purchase or sales invoice, this actually creates a duplicate purchase or sales invoice record;  maybe you are already know this.
I am aware that you are probably just 'trying things out' at the moment so maybe that is why you are doing some things in a certain way.  At the end of the day, we all take different approaches;  hopefully, this might give you a couple of alternatives.
Derek.

Re: Filters and tGrid Field Display

Derek,

Thank you very much for the info that I consider is very helpful...................


if you create more than 1 refund transaction against the same purchase or sales invoice, this actually creates a duplicate purchase or sales invoice record;  maybe you are already know this.

No, I didn't notice creation of duplicate records and of course you are right. Could you possibly fix it please?


Originally, I have started the project one main table and 1 main form, both named same (Invoice).
In the the process I hit some issues those that I couldn't solve myself. Main issue was working out refunds.
What I wanted do is when issuing a refund against selected purchase and sale is to display original inv details in read only mode with their own unique record numbers. I was using show record action for refund buttons to get original inv details displayed on refund forms. It didn't work as it was saving over the original invoice. Thanks to EHW, he provided solution but I couldn't adopt his script to actual project. I posted for help under "Script help please" thread but I think EHW is away.
It would be simple to use new record action for refund button but I couldn't find a way to get original inv fields values to display on refund form. I guess I could use inv num combobox on refunds form to call original inv details but that's not a practical solution. When there are many invs it'd be not easy to locate correct inv num.
If you have time, It'd be great help for me to have your version of this sample project.

Adam
God... please help me become the person my dog thinks I am.

Re: Filters and tGrid Field Display

Adam, I had a few minutes to take a look at your project updated by Derek. Sorry, I have not had much time to get on the forum these days. The reason you are getting duplicates in the main invoice grids is as follows: The refunds table is a child of the invoice table. Since you are displaying refund fields (Specifically refund number in this case) in the main invoice grids, the tablegrids is doing what it is suppose to do by showing all the child refund data as well as the main invoice data in the grid. If you remove the PIRnum and SIRnum from the respective main invoice grids, then the duplicates will go away.

10 (edited by AD1408 2017-07-12 01:39:22)

Re: Filters and tGrid Field Display

Hi EHW,


I'm glad to see you around....
Thank you very much..................
Truly appreciated.......................


Solution seems simple but knowing the right one requires a knowledge, which I'm still lucking on that front a lot. Once again thanks for the nicely explained info.

Adam
God... please help me become the person my dog thinks I am.

Re: Filters and tGrid Field Display

EHW,


I hope you are around and have some free times...


I got the two tables version working the way I wanted thanks to your and Derek's help. Hopefully I won't have any further issues with it.


Now I'm trying one table version.
Main stumbling block for me here SQL script in order to save mostly same data as a different record (refunds). I Googled for sql script but couldn't find anything that I could learn and use.
Perhaps you could give me a quick info about items highlighted on the illustration below:
https://s13.postimg.org/uo1u29o87/zzzzz_Temp41.png


On attached one table sample project I couldn't get dbRef and crRef fields under PI and SI Ref columns. I may be wrong but I'm guessing I couldn't get sql script right. I like to use these columns for conditional codes such as row coloring, preventing delete action if item contains any refund etc.


They work OK on two tables version as you can see on the screen cap below:
https://s1.postimg.org/l84ttlpwv/zzzzz_Temp42.png


Also when refunds relating to Invoice record is/are deleted, Inv tGrid updates by changing color to original record color and takes out Db / Cb text under Ref column.

Post's attachments

Attachment icon tGrid Field Display 4 One Table.zip 20.68 kb, 400 downloads since 2017-07-13 

Adam
God... please help me become the person my dog thinks I am.

12 (edited by ehwagner 2017-07-14 03:32:04)

Re: Filters and tGrid Field Display

Adam, let me address the SQL statement first. I'll have to take a look at your project later. I might suggest you find some tutorials on SQL. Once you know the syntax of SQL statements, then you just need to be able to apply them inside MVD's SQLExecute command. Here is an online site which provides tutorials and examples of basic SQL statements: https://www.w3schools.com/sql/


The SqlExecute command is simply one big string of an SQL statement inside the parentheses. SQLExecute('Insert.....');  The entire SqlExecute line can actually be on one line, but then it would stretch way past the screen edge. I put line breaks in for readability purposes. It also makes it a little easier for debugging as well.


Since the entire Sql statement is a string, then if you have text string values inside the single quotes, then the strings are placed inside double quotes (quotation marks). Text fields should be inside quotation marks while numeric values typically do not need the quotes.


The Sql Insert command defines the fields you are inserting separated by commas. The actual values being inserted are also separated by commas. That's why you see commas between the field values. If you manually inserted a row, an example might look like this:


Insert into Invoice (Counter1,Counter2,Counter3,Counter4,DBCRvalue,product,PIprice,PIRprice,SIprice,SIRprice) Values ("00001","00002","00003","00004","Purchase","ABC Product",100,40,150,10)

I rewrote the SqlExecute statement to maybe make it a little more understandable and readable to you. It does exactly the same as the one you presented except I formatted it for better understanding of the position of the quotation marks around text fields. Hope this makes sense.


SqlExecute('Insert into Invoice (Counter1,Counter2,Counter3,Counter4,DBCRvalue,product,PIprice,PIRprice,'
       + 'SIprice,SIRprice) Values ('
       + '"' + frmRefund.EdCounter1.Text   + '",'
       + '"' + frmRefund.edCounter2.Text   + '",'
       + '"' + frmRefund.edCounter3.Text   + '",'
       + '"' + frmRefund.edCounter4.Text   + '",'
       + '"' + frmRefund.edDBCR.Text       + '",'
       + '"' + frmRefund.edInvProduct.Text + '",'
       + frmRefund.edPIRpricePI.sqlValue   + ','
       + frmRefund.edPIRprice.sqlValue     + ','
       + frmRefund.edSIRpriceSI.sqlValue   + ','
       + frmRefund.SIRprice.sqlValue       + ')' );

Sorry that I didn't annotate with pictures. Just didn't have time. I'll try to look at your project tomorrow.

13 (edited by AD1408 2017-07-14 14:49:44)

Re: Filters and tGrid Field Display

Thank you very much for the info and readable SQL script format EHW......................


Indeed, readable SQL script format you kindly put up makes better sense for me now.
I have updated SQL script with ref fields and it works find without errors. I noticed insert into... field order and values field order needs to be same.

SqlExecute('Insert into Invoice (Counter1,Counter2,Counter3,Counter4,DBCRvalue,product,crRef,dbRef,PIprice,PIRprice,'
    + 'SIprice,SIRprice) Values ('
       + '"' + frmRefund.EdCounter1.Text   + '",'
       + '"' + frmRefund.edCounter2.Text   + '",'
       + '"' + frmRefund.edCounter3.Text   + '",'
       + '"' + frmRefund.edCounter4.Text   + '",'
       + '"' + frmRefund.edDBCR.Text       + '",'
       + '"' + frmRefund.edInvProduct.Text + '",'
       + '"' + frmRefund.edCRref.Text      + '",'
       + '"' + frmRefund.edDBref.Text      + '",'
       + frmRefund.edPIRpricePI.sqlValue   + ','
       + frmRefund.edPIRprice.sqlValue     + ','
       + frmRefund.edSIRpriceSI.sqlValue   + ','
       + frmRefund.edSIRprice.sqlValue     + ')' );

Also what would be the field type syntax for image fields under values? I tried DBimage but didn't work.


My guess about  crRef and drRef not working seems wrong. Refunds SQL script is working OK but  crRef and drRef  are still not shown on their respective tGrids in spite of  DBupdate lines included?

Adam
God... please help me become the person my dog thinks I am.

Re: Filters and tGrid Field Display

Hi Adam, EHW,
Had a couple of spare hours so I thought I'd have a go at the single table approach that I suggested a while ago.
It's a bit rough and ready and doesn't do all the things that yours does (mainly because I ran out of time) but I think the core functionality is much the same.  But quite a different approach with a self-imposed brief to keep it simple, use as much basic MVD functionality and really cut down on the amount of scripting and see how close I could get it.
Anyway, it's attached if you want to have a look and maybe it will throw up a few ideas.
Regards,
Derek.

Post's attachments

Attachment icon adam refunds all.zip 347.85 kb, 417 downloads since 2017-07-15 

Re: Filters and tGrid Field Display

Hi Derek,


Thank you so much for taking time to for doing 1 table version................
Truly appreciated...........


Your approach deserves a laud applause. You did all that with minimal script.


On downside, at my end due to luck of proper understanding of MVD functionality, changing something breaks it. For instance I changed PI Grid "Show Refunds" button name and lost button functionality (clicking on a record on PI grid to display purchase refunds of selected purchase inv record) I could only find that button name referenced on script once. I changed that too but still couldn't make it work? I'm sure I'm missing something but in spite of trying and checking all the items I can think of, couldn't solve it.

Adam
God... please help me become the person my dog thinks I am.

Re: Filters and tGrid Field Display

Hi Adam,
No problem - it's an straightforward fix.
If you change the name of the 'Show Refunds' button you need to change it in the script (which you have found and done) but you also need to change form1.edit1.  This uses the 'Show Refunds' button to do an incremental search so have a look at the object properties for form1.edit1  (Increm.Search) and make the same change there (click the drop down on the Increm.Search property and you should see your renamed button in there.
Fingers crossed, you should be working again.
Derek.

17 (edited by AD1408 2017-07-16 13:03:54)

Re: Filters and tGrid Field Display

Thanks a lot Derek.................


I didn't notice edit1 was associated to the button with incremental search. It works fine now.
I noticed you have used two different filters on PR and SR tGrids. I guess you done them this way for teaching purposes as both works OK with same type of filters when both contains tparent field such as:
types.identifier="PR"
types.identifier="SR"


Edit: 16/07/2017 11:29:34
I have noticed one issue. In order to avoid orphan refund records it needs protection (foreign key restrain type) against deleting a SI and PI record with refunds with a message dialog something like "This record contains refund and cannot be delete. Refund record/s must be deleted first"
--
I have tried same approach as in sample project at post #11 by adding a text field (refund) to transactions table and put it with default value R on PR and SR forms then used them on PI and SI tGrids. However, I hit the same issue of getting refund field displayed on SI and PI tGrids.


I'd love to see from you sample project forcing limits of MVD, showing us all sorts of hat tricks with minimal script one day....


Looks like EHW is busy these days.
Derek, could you have a look at the issue with sample project at my post #11 please, when you have bit of a time?

Adam
God... please help me become the person my dog thinks I am.

Re: Filters and tGrid Field Display

Hi Adam,
Attached is the program with warning messages to prevent you from creating orphan refunds. 
Deleting invoices or refunds is not really something that would happen over here (UK) - for audit reasons you wouldn't be allowed to.  I'd probably ending up 'logically deleting' them with a flag and then add filters to exclude flagged transactions from the grids.
The reason for the different filters on the PR and SR grids that you spotted is that I was trying different ways and simply forgot to make them all consistent - me bad!.  But you're right - either way will work.
Derek.

Post's attachments

Attachment icon adam refunds all.zip 349.01 kb, 407 downloads since 2017-07-16 

Re: Filters and tGrid Field Display

Hi Derek,


Thank you very much for your kind update..........
Truly appreciated....................


The reason for the different filters on the PR and SR grids that you spotted is that I was trying different ways and simply forgot to make them all consistent - me bad!.

No, it's not your bad. Actually it's your good. It shows alternative ways doing same thing. I like alternatives. After all we all need Plan A, Plan B etc to complete tasks.


One thing still bugging me which I couldn't get it working. I wanted to add reference column (*) to form1 PI and SI tGrids via PR and SR forms. I used a text field with default value R
I like to use reference columns for conditional manipulation of those relevant tGrids, in this case PI and SI tGrids. Could you please help?

Post's attachments

Attachment icon adam refunds all 2 Work.zip 16.01 kb, 401 downloads since 2017-07-17 

Adam
God... please help me become the person my dog thinks I am.

20 (edited by derek 2017-07-17 23:52:02)

Re: Filters and tGrid Field Display

Hi Adam,
So something like a visual prompt on the purchase and sales invoice grids that there are refunds?
Adding this has also enabled me to simplify the orphaned refund problem - no need for messages or anything now so it's reduced the size of the script by a few lines - LOL!
Please find attached.
Derek.

Post's attachments

Attachment icon adam refunds all 2 Work.zip 349.2 kb, 397 downloads since 2017-07-18 

21 (edited by AD1408 2017-07-18 02:06:08)

Re: Filters and tGrid Field Display

Hi Derek,


Thank you very much for your kind update...........


There seems to be a strange update issue.
After deleting some refunds it correctly clears PI and SI reference column value. However, after re-run reference column value appears while there is no refund associated to particular invoice. Strange part is sometimes you need to run project multiple times to see the issue.Please see the screen cap below:


https://s2.postimg.org/eezztu1ex/zzzzz_Temp43.png


I have tried DBupdate for both save and delete buttons (onAfterClick) but no luck...


-----------------------
Edit: 18/07/2017 03:15:20
I have used the following on tGrids PR and SR onChange event. It seems to be working OK, but not sure it's correct tho?

if form1.tgMainPIR.rowcount = 0 then Form1.tgMainPI.Columns[1].Clear;

Edit2: Nope, the above doesn't seems to be working after multiple runs.



.. Adding this has also enabled me to simplify the orphaned refund problem...

Yes, with reference column we can manipulate the tGrid and it's items in certain degree.

Adam
God... please help me become the person my dog thinks I am.

Re: Filters and tGrid Field Display

Hi Adam,
The script looks okay to me (but that's not to say that it is - LOL!).
What I actually suspect is that it's because the condition where 'PR' or 'SR' is shown or removed was only coded to work on mouse clicks rather than for the keyboard as well.  I've added the appropriate lines so that it fires off on 'key-ups' as well as 'mouse-clicks' and I think that should now prevent it from happening.  But if you manage to re-create the problem, please let me know and I'll dig a little deeper
Derek.

Post's attachments

Attachment icon adam refunds all 2 Work.zip 349.99 kb, 375 downloads since 2017-07-18 

23 (edited by AD1408 2017-07-18 22:37:15)

Re: Filters and tGrid Field Display

Hi Derek,


Unfortunately, same issue remains.
I have deleted few refunds from PR tGrid, exit and re-run it from MVD and got extra SR value under * column on SR tGrid.


I may be totally wrong but I suspect issue originates from dbUpdate/refresh as it happens on start.

Adam
God... please help me become the person my dog thinks I am.

Re: Filters and tGrid Field Display

Hi Adam,
I was able to recreate the problem you found.
I think it was when a deletion was done from the 'all refunds' list rather than having first selected a PI or SI and then deleting. 
So the easiest fix is, when you're in 'all refunds' mode, to hide the 'delete' button and only re-show it when a specific PI or SI has been clicked.
I've done this and given it a good test and it seems to be fine now.
Apologies for missing that (school boy error - or in my case school grandad error - LOL!).
Derek.

Post's attachments

Attachment icon adam refunds all 2 Work.zip 350.35 kb, 422 downloads since 2017-07-19 

Re: Filters and tGrid Field Display

Hi Derek,


Unfortunately, same issue still remains.
This time, I've added product and issued a refund, exit then re-run the project.

Adam
God... please help me become the person my dog thinks I am.