Topic: Refunds again

Added customers and suppliers to working test project and start having various issues with refunds.
1. Cannot get refunds supplier and customer values displayed correctly on refunds edit.
2. Sale refund adding multiple sale refund records


If I include supplier and customers name comboboxes on refunds save button, then I can only add 1 purchase or sale refund.


Please see the attached sample project attached:

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2b.zip 32.93 kb, 380 downloads since 2017-08-16 

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

Re: Refunds again

Looks like I have sorted some issues except one.


I cannot get supplier and customers names plus country comboboxes values on frmRefund after clicking on issue refund buttons (both Purchase and sale refund) on Form1 as highlighted on the screen cap below:
https://s4.postimg.org/g8sj6v8n1/zzzzz_Temp44.png


Please see the updated sample project below.

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2c.zip 32.79 kb, 389 downloads since 2017-08-17 

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

Re: Refunds again

Adam,

I added a line to your purchase refund and a line to your sale refund. Look for "EHW - Added the following line". Also, I commented out a couple of lines on the refund buttons click event. They were not needed.

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2c Fixed.zip 611.91 kb, 391 downloads since 2017-08-17 

Re: Refunds again

Hi EHW,


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


If you and Derek weren't around, probably I'd have been forced to give up on MVD and most likely start with Java from zero.

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

Re: Refunds again

I have noticed that taxRate combobox value is not displaying tax rate value correctly on edit of a refund record. Refund edit form tax rate combobox shows last added refund record tax rate value on edit of a all refund records.


I have tried few things but couldn't get it working correctly.


EHW, it was unresolved issue at my end nothing to do with your fix. I just missed it.


Please see the sample project in post #3
tGrid Field Display 3 Two Tables Test2c Fixed.zip 611.91 kb,

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

6 (edited by derek 2017-08-18 17:05:45)

Re: Refunds again

Hi Adam, EHW,
I've added two lines to the script (234 and 305) which I think addresses the issue you were having.  Hopefully, it doesn't mess anything else up that you've been working on.
I haven't made the same changes for the cbpirtaxpi, cbpirtaxrate, cbsirtaxratesi and cbsirtaxrate fields on the amend purchase refunds and amend sales refunds form as I don't understand why you need to show them;  they aren't saved to the refund table, therefore presumably they must be the same as the cbpirtaxrate field which is already being displayed.  So wouldn't it just be 4 unnecessary calls that will slow things down a bit?
Maybe I'm missing something (wouldn't be the first time - LOL)!.
Regards,
Derek

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2c Fixed.zip 367.93 kb, 388 downloads since 2017-08-18 

Re: Refunds again

Hi Derek,


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


Unfortunately issue remains and there seems to be few others .
- Sometimes, All Refunds button doesn't work.
- Sometimes adding new refund doesn't show, on second try it does. This happens usually after start of the application.
- Sometimes adding second refund to another inv record moves "Ref" column cr / db to last refund issued inv record on inv tGrids.
I couldn't replicate all those above issues properly in order to identify the causes.


In essence there is only one tax rate that's under product field in invoice table and on invoice and refund forms.
I have tried copying tax rate combobox value under products field for all other refund form tax rates by adding link to tax rates from refund table and including cbPIRtaxRate and cbSIRtaxRate in frmRefund Save button but couldn't get it working.


https://s27.postimg.org/65uihgq43/zzzzz_Temp45.png


Please see the updated sample project below:

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2e.zip 33.49 kb, 385 downloads since 2017-08-18 

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

Re: Refunds again

Adam,

I'm in agreement with Derek. Not sure why you need to display the same field three times on the same form. Since there is only one tax field recorded, I basically put the same dbitemid, populated by Derek, into the other two tax fields on the refund form. The two lines follow Derek's lines.


As far as your other issues, I was not able to replicate them. I did notice that on one of your search buttons you were displaying the Tax.Id rather than the TaxRate. I changed that for you.

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2e Revised.zip 612.87 kb, 378 downloads since 2017-08-19 

Re: Refunds again

Hi EHW,


Thank you very much....... Now it works much better.


Tax rates on refund record edit works fine now, when invoice record selected then refund record belonging to selected invoice, clicking on refund edit button shows correct tax rate under refund prices.


However, if a refund record selected then clicked on refund edit after running application where all refunds are displayed, refund tax value is not displayed correctly. Please see reference screen cap below:
https://s27.postimg.org/9tev19noz/zzzzz_Temp46.png



- Sometimes, All Refunds button doesn't work.

I managed to replicate this issue I think.
1. Compile/run the project
2. All refunds will be displayed fine on refunds tGrids
3. Select an invoice record from PI Purchase Invs tGrid and click on refund tGrid edit button to show record.
4. Repeat num 3 with few otherPI Purchase Invs tGrid records.
5. Click on All refunds button of PIR Purchase Invs.
https://s27.postimg.org/rxhvlwldf/zzzzz_Temp47.png


I'm thinking that there may be some issue with All Refunds buttons?

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

10 (edited by derek 2017-08-19 00:14:18)

Re: Refunds again

Hi Adam, EHW,
With regard to your issue with the 'all refunds' button, it stops working once you've viewed or edited a refund (viewing and editing invoices is fine).  To get the 'all refunds button working again, you either have to restart the program OR click on an invoice that doesn't have any associated refunds, so something is not getting cleared properly.
But I'm not sure why you need a 'search' associated with the 'all refunds' button if you're displaying everything.  A 'quick and dirty' way that I could think of was simply to add a hidden grid that is displayed when you click on 'all refunds' and hidden again when you click back in the invoices tables (see attached).  But there's probably a 'proper' way to do it which I'll try and have a look at.
Just a word of caution, but with possibly 3 of us looking at it independently, you need to be careful that we don't end up overwriting each others' changes.
If I get time, I'll have a think about  the other 2 issues you mentioned as well.
Regards,
Derek.

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2e.zip 369.29 kb, 387 downloads since 2017-08-19 

11 (edited by AD1408 2017-08-19 09:07:29)

Re: Refunds again

Hi Derek,


Thank you very much......


I thought about using hidden tGrid too but it didn't solve out the issue of not displaying correct tax rate value under refund prices if a refund record on all refunds display state when refund edit button clicked. All I can think of having all refund tGrid displayed on a separate form without edit and delete buttons as a workaround to this approach.


Hopefully somebody (that includes you too Derek - lol) can offer proper solution.


But I'm not sure why you need a 'search' associated with the 'all refunds' button if you're displaying everything.

When displaying all refunds on same tGrid that was the only way I could think of.


If I get time, I'll have a think about  the other 2 issues you mentioned as well.

Thank you... In the meantime if and when I can replicate them, I'll update here.


Just a word of caution, but with possibly 3 of us looking at it independently, you need to be careful that we don't end up overwriting each others' changes.

No worries. I do not delete you guys changes or code. If I want to try something else I create a new copy of the sample project and work on that.

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

12 (edited by derek 2017-08-19 14:47:56)

Re: Refunds again

Hi Adam,
The problem with trying to edit a refund directly from the 'all refunds' grid is that it you haven't highlighted a record in the 'invoices' grid  in the first place (as you would normally do to see refunds for a specific invoice) and so you can't easily get the tax rate (which is only held on the invoice and not on the refund - sounds familiar!).  You'd need to do a double read - once of the refund record to get the associated invoice and then read the associated invoice to get the tax rate.
This problem largely goes away if you don't show the tax rate on the refunds form (and as stated before, I'm not sure why you need to, bearing in mind it can't ever be any different).
Given the above, I think the most straightforward option is the 'hidden grid' which is visible when you click 'all refunds' (and which also hides the 'edit' and 'delete' buttons);  in effect, it becomes a display only 'all refunds' grid.
Derek.

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2e.zip 369.8 kb, 425 downloads since 2017-08-19 

Re: Refunds again

Adam and Derek,

I may have the solution to both. Since I'm not sure how MVD constructs the sql when you have the same tablegrid also as the search. Its hard to say what its doing behind the scenes. So what I did was put together the query on the button. Doing this I know what its going to display.


I also fixed the tax rate problem. Derek was right. You have to get to the tax rate through the invoice.


My internet service had been going in and out so my fix is on my previous post. I wasn't able to get to Derek's solution.

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2e RevisedSQL.zip 614.65 kb, 410 downloads since 2017-08-19 

Re: Refunds again

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


Derek:
With your approach you missed hiding refund edit and delete buttons plus disabling double click for refund tGrids. I added them. Downside is that in order to edit refunds, user needs to click on edit button as disabling doubleclick applies to both all refunds and normal states. There may be a code using if etc so that double click disabled only when all refunds are displayed. I didn't try anything on this front yet.

There is one issue I noticed tho, All refunds displays more records then what's shown on invoice tGid. PI Invoice tGrid contains 5 refund records but PIR Refunds tGrid shows 8 refund records. Perhaps MVD search doing something that we cannot see as EHW pointed out?


EHW:
Nice one... It works fine without workarounds. I wish I could write SQL script like you can.

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

Re: Refunds again

1.  The 'edit' and 'delete' buttons are hidden when the 'all refunds' button is clicked and redisplayed when the user clicks back in the PI invoices tgrid (see attached screenshot).  Anyway, it's moot as EHW's sqlquery approach tackles the problem more at source rather than simply trying to side-step it and allows editing directly from the 'all refunds' grid which is more functional.
2.  Your design allows for multiple refunds against one invoice, therefore it is quite normal for the PIR refunds tgrid to contain more records than the PI invoices tgrid  - so I am struggling to understand why this is an issue?  And both suggestions (the 'display only' grid approach and the sqlquery approach) behave in the same way and show the correct number of refunds, as far as I can tell.

Post's attachments

Attachment icon refunds.jpg 164.16 kb, 266 downloads since 2017-08-20 

Re: Refunds again

Hi Derek,


2.  Your design allows for multiple refunds against one invoice, therefore it is quite normal for the PIR refunds tgrid to contain more records than the PI invoices tgrid  - so I am struggling to understand why this is an issue?...


If I'm not missing something, the following image may explain the issue better hopefully:
https://s29.postimg.org/66mmsbgef/zzzzz_Temp48.png


I agree EHW's solution is the proper one and I'll use it in this case.
I also like your workarounds too. It'll be useful for other projects not only mine but also other MVD users' too. That's why I highlighted the above issue.

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

17 (edited by derek 2017-08-20 13:24:30)

Re: Refunds again

Adam,
It's your project so I don't know the finer details of how it works but it seems to me that you can:
1.  add a purchase
2.  add a refund for that purchase
3.  sell that purchase
Selling the purchase deletes it from tgmainpurchinvs and adds it to the tgmainsalesinvs.  But it leaves the refund record behind in tgmainpir.
That's how you get more records in tgmainpir than in tgmainpurchinvs and that is going to happen irrespective of whether you use EHW's suggestion, my suggestion or anyone else's.  That's my point.
For what it's worth, in my opinion there are a number of design questions to be addressed before you need worry about any of the above coding issues, the MAIN one being the way in which you delete a purchase record when you sell it - you lose all traceability back to the purchase record which, from both a commercial and an audit point of view, could be a big problem. 
Derek.

Re: Refunds again

Hi Derek,


Selling the purchase deletes it from tgmainpurchinvs and adds it to the tgmainsalesinvs.  But it leaves the refund record behind in tgmainpir. That's how you get more records in tgmainpir than in tgmainpurchinvs...

... the MAIN one being the way in which you delete a purchase record when you sell it - you lose all traceability back to the purchase record which, from both a commercial and an audit point of view, could be a big problem.


You are absolutely right on both points. Thank you very much for taking time to look into my sample project.... Truly appreciated.............
If there are more design issues you spot please let me know.


Solutions I can think of...
1. Prevent moving purchase inv to sale inv if purchase inv contains refund/s. If purchase inv contains only partial refunds and user still wants to sell what's left then user needs to create a new purchase invoice for the same product.


2. Traceability; display purchase invoice details on sale and sale refund invs forms or on separate form via a buttons on sale and sale invs reforms.


I didn't commit any changes yet before having your view. Probably you have better solutions.


The reason I'm converting purchase inv to sale inv rather than having them separately is that this part of the project involves 1 product transactions hence there is no qty field. In and out.

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

Re: Refunds again

Hi Adam,

The reason I'm converting purchase inv to sale inv rather than having them separately is that this part of the project involves 1 product transactions hence there is no qty field. In and out.

I'm not sure if I understand this part of your post.  Ignoring the question of purchase refunds for the moment, do you mean that on this particular project, everything that comes in on 1 purchase invoice then goes out on one sales invoice?
Derek

Re: Refunds again

derek wrote:

... do you mean that on this particular project, everything that comes in on 1 purchase invoice then goes out on one sales invoice?

Yes.

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

Re: Refunds again

Check out the attached for a possible solution for the items of concern. No1, I don't think it's practical to have users put in new purchase invoices after a sale. No 2, the solution takes care of the traceability issue as Derek astutely pointed out. Basically a purchase invoice is maintained in play when a sale takes place. In other words, a sale will create a new sale invoice record while the purchase invoice remains in tact as is.

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2e Revised2.zip 614.83 kb, 404 downloads since 2017-08-21 

Re: Refunds again

Hi EHW,


Thanks for the alternative approach example......


On this project, I'm using single product invoicing. Purchases tGrid also acts as a inventory. So once a product sold it moves into sales invoices.
Derek was kind enough to highlight shortcomings in my design.


I have added a message box for the purchase invoice contains "Db" refunds to the btnSaleAdd with a cancel which stops user converting purch inv with refund/s to sale inv. If all refunds were full this would be it but sometimes there are partial refunds where product may be kept. Supplier may give some refund rather than having product returned and issuing full refun in some occasions. We end up with a product at new purchase price (original purchase price - refund). In accounting terms (as far as I know) we can sell it as a new product at discount, if we cannot then it has to be written off in order to balance the books, alternatively it may be kept as an asset depending on product nature. I'm not going into write offs, asset management etc with this project. Trying to keep it simple and basic.


On traceability front, having purchase inv key fields displayed on sale inv could solve the issue imho. When sale inv viewed, user can see the details of the original purch inv on sale inv form. I have done all these and they seems to be functioning ok so far. However, one thing I couldn't do. Instead of using combos and textboxes, for supplier name and address, I wanted display the in a read only memo field. Please see the reference image below:


https://s29.postimg.org/pijpmsxjb/zzzzz_Temp49.png

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

Re: Refunds again

Yes you can. Use the following:


frmInvoice.Memo1.Lines.add(.....);

Replace the dots with your data, either form fields or SqlExecute to retrieve the data. You need this line for each item (Name,Address,City, etc)

Re: Refunds again

Thanks a lot EHW..............


Unfortunately, I'm not there yet to construct proper SQL.

I tried followings under frmInvoice onShow but surely they didn't work as they are not correct:

frmInvoice.memSIsupplier.Lines.add(frmInvoice.name.id_Supplier);
frmInvoice.memSIsupplier.Lines.add(frmInvoice.Street.id_Supplier);
frmInvoice.memSIsupplier.Lines.add := SQLExecute('SELECT Name FROM Supplier WHERE id='+inttostr(form1.tgMainSaleInvs.dbitemid));
frmInvoice.memSIsupplier.Lines.add := SQLExecute('SELECT Street FROM Supplier WHERE id='+inttostr(form1.tgMainSaleInvs.dbitemid));
Adam
God... please help me become the person my dog thinks I am.

Re: Refunds again

Adam,
Since I don't have your most recent project, I used one of the previous projects to show how the memo field can be filled with the supplier fields which are already on the form but hidden.

Post's attachments

Attachment icon tGrid Field Display 3 Two Tables Test2e Memo.zip 615.43 kb, 412 downloads since 2017-08-23