Topic: Moving tGrid Item on Save

Thanks to EHW's and Derek's kind help, I could do somethings with one and two table version of the sample project attached.


Now I'm trying 4 tables and 4 forms version. I could take it as far as moving purchase inv to sale inv tGrid. Currently, I can save sale invoice but cannot move the sold purchase item to sale inv tGrid.  I may be totally wrong but I'm guessing tGrid filters doesn't work in their current definitions because purchase and sale inv have their own tables. My one cell brain couldn't come up with a solution.
Reason for moving purchase inv item from purchase inv tGrid to sale inv tGrid is that the approach is based on single product items and using purchase tGrid as inventory same time.


Please see the attached sample project below:

Post's attachments

Attachment icon Moving tGrid Item on Save.zip 32.19 kb, 364 downloads since 2017-09-06 

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

Re: Moving tGrid Item on Save

Perhaps I couldn't explain the issue clearly on my post above that I wasn't able to solve. Here is another attempt with illustrations.....


https://s26.postimg.org/rbhqnnmnd/zzzzz_Temp54.png


https://s26.postimg.org/m1crwd2eh/zzzzz_Temp55.png


https://s26.postimg.org/xual0kyuh/zzzzz_Temp56.png


Could somebody help please...

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

Re: Moving tGrid Item on Save

I added to your filter on the purchase invoice grid setting.  If a purchase invoice is converted to a sale then the filter will exclude it from the purchase grid. Also, I placed a dbupdate after deleting a sale invoice so the purchase invoice will immediately show again in the purchase grid.

Post's attachments

Attachment icon Moving tGrid Item on Save Revised.zip 611.84 kb, 370 downloads since 2017-09-11 

Re: Moving tGrid Item on Save

Hi EHW,


Thank you very much for the magic filter.................
I also like to thank you for fixing the issue after deleting sale invoice, which I have failed to take into account................
Truly appreciated.......................................

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

Re: Moving tGrid Item on Save

Hi again EHW,


I wanted to apply on sale invoice delete moving record back to purchase inv tGrid for 1 table (sale and purchase) Invoice table and 1 form(sale and purchase) frmInvoice version.
Tried following but no success:

procedure Form1_btnSaleDelete_OnAfterClick (Sender: string);
begin
  frmInvoice.cbInvoiceDBCR.Text := 'Purchase';
  frmInvoice.edDBCR.Text := 'Purchase';
  Form1.tgMainPurchInvs.dbUpdate;
end;

On filters front I couldn't think of adding anything to existing one:

Invoice.DBCRvalue= "Purchase"
Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid Item on Save

Adam,

Yeah this won't work

procedure Form1_btnSaleDelete_OnAfterClick (Sender: string);
begin
  frmInvoice.cbInvoiceDBCR.Text := 'Purchase';
  frmInvoice.edDBCR.Text := 'Purchase';
  Form1.tgMainPurchInvs.dbUpdate;
end;

You can't really make a change like that on a delete. If it's just one table, then I think you are on the right track with making changes to the characteristics of the record depending on purchase or sale. Attach your project and I'll take a look at it and see what needs to be put in place.

7 (edited by AD1408 2017-09-13 01:06:34)

Re: Moving tGrid Item on Save

Hi EHW,


I did something using inv type DBCR value and it seems to be working excluding certain points I may have missed. However, I think it's bit messy. Most likely there is cleaner and simpler way to do it.


- Added "Convert to Purchase Invoice" btn (marked on properties as visible false) on frmInvoice under sale tab for changing DBCR value to Porvhase. Extra DBCR value field just for visual effect where I may hide actual DBCR field.  "Convert to Purchase Invoice" btn and additional filed with Clear btn visible only on edit of a sale inv
- Disabled  "Convert to Purchase Invoice" btn when sale inv with Cr (Refund) to be edited.
- It wasn't clearing customer details when purchase inv converted to sale then converted back to purchase and converting to sale inv again. So I added clear fields lines under invOnShow event


Please see the attached sample project:

Post's attachments

Attachment icon Moving tGrid Item on Save 1 table.zip 30.83 kb, 359 downloads since 2017-09-13 

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

Re: Moving tGrid Item on Save

Adam,

I took a different approach. On the Delete button I made the necessary changes to the record fields to make the record a purchase invoice. It really does not delete the record. I changed the button caption to "Remove Sale". Visually it mimics the delete button in your project from your previous post with two tables.

Post's attachments

Attachment icon Moving tGrid Item on Save 1 table Revised.zip 610.73 kb, 413 downloads since 2017-09-13 

9 (edited by AD1408 2017-09-13 11:06:00)

Re: Moving tGrid Item on Save

Hi EHW,


Thank you very much for much more cleaner version.............................


I wanted prevent removing sale invoice with refund (Cr) using a message dialog as follows:

procedure Form1_btnSaleDelete_OnClick (Sender: string; var Cancel: boolean);
begin
If (Form1.tgMainSaleInvs.Cells[1,Form1.tgMainSaleInvs.SelectedRow] = '') and
   (MessageBox('Are you sure you want to remove the selected sale','Confirm',MB_YESNO+MB_ICONQUESTION) = IDYES) then
   Begin
   SqlExecute('Update Invoice Set DBCRValue = "Purchase", Counter1 = "", SIPrice = 0 Where id = ' + Form1.tgMainSaleInvs.sqlValue);
   Form1.tgMainPurchInvs.dbUpdate;
   Form1.tgMainSaleInvs.dbUpdate;
   Exit;
   End;

   If Form1.tgMainSaleInvs.Cells[1,Form1.tgMainSaleInvs.SelectedRow] = 'Cr' then
   begin
   Cancel := true;
   MessageDlg ('Sale Invoice with Refund cannot be removed.',mtInformation,MB_OK,0);
   end;
end;

It seems to be working but not so sure it's the correct way of doing it tho...

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

Re: Moving tGrid Item on Save

That should work Adam. You do not need the "Cancel := True" though.