526

(6 replies, posted in General)

Hi EHW,


I'm glad to see you around...
Your kind help is truly appreciated, as always.............


Somehow it doesn't clear ref (*) columns on PI and SI after deleting refund/s belonging to Invs...
DBupdate after relevant delete/s script there but it doesn't clear.

527

(6 replies, posted in General)

Derek has been very kind helping me on similar matter in another thread by sharing Refunds sample project.


This one is similar but not same in respect of functionality and approach.


Issues I have are:
1 Getting crRef and dbRef fields displayed under ref (*) columns of PI and SI tGrids.
2. Selected PI or SI tGrids row is not displayed on PIR or SIR tGrids. I thought this one could be done with a search button but didn't work.


Please see the attached sample project below:

528

(15 replies, posted in General)

Hi Derek and Manixs,


I'm not sure that you would actually ever have both a deposit and a withdrawal against the same transaction (as per both layouts)...

My apologies for not making my layout clear. I should have added additional two columns (cost of deposit and cost of withdrawal)  in addition and show deposits and withdrawal in separate columns. At my end I wanted to use running balance in banking terms.


Manixs' calc field formula with printf("%.2f",... seems to be working OK. Thanks for sharing Manixs.


When formatting tGrid cell values with decimals and thousand separator;
the following works fine without printf("%.2f",...  calc fields and on form calcs:


procedure Form1_tgMain_OnChange (Sender: string);
begin
 if form1.tgMain.Columns[4] is TNxNumberColumn then
    begin
    TNxNumberColumn(form1.tgMain.Columns[4]).FormatMask := '#,###,##0.00'; //
    TNxNumberColumn(form1.tgMain.Columns[6]).FormatMask := '#,###,##0.00'; //
   end;
end;

However, the above didn't work with calc field containing printf("%.2f",...
I found out that old method below worked with calc field containing printf("%.2f",...

procedure Form1_tgMain_OnChange (Sender: string);
var i,c: integer;
begin
    Form1.tgMain.BeginUpdate;

    c := Form1.tgMain.RowCount - 1;
    for i := 0 to c do
    begin
        Form1.tgMain.Cells[8, i] := FormatFloat('#,##0.00', Form1.tgMain.Cell[8, i].AsFloat);
        Form1.tgMain.Cells[9, i] := FormatFloat('#,##0.00', Form1.tgMain.Cell[9, i].AsFloat);
    end;
    Form1.tgMain.EndUpdate;
end;

Just wanted to share in case others may encounter the same issue and also for correction if needed.

529

(26 replies, posted in General)

Hi Derek,


It seems to be working OK now. Looks like you have taken on stealth mode with the use of invisible tGrids.
Thank you very much for your kind help..................
Truly appreciated.....................

530

(26 replies, posted in General)

Hi Derek,


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

531

(26 replies, posted in General)

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.

532

(15 replies, posted in General)

I'm interested in running balance calc too.
At my end it'd be laid out like this:


Deposits   |   Withdrawals   |   Running Balance
                                                               100.00
100.00                     0.00                        200.00
100.00                   50.00                        250.00

533

(26 replies, posted in General)

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.

534

(26 replies, posted in General)

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?

535

(26 replies, posted in General)

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?

536

(26 replies, posted in General)

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.

537

(26 replies, posted in General)

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?

538

(26 replies, posted in General)

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.

539

(26 replies, posted in General)

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.

540

(26 replies, posted in General)

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.

541

(26 replies, posted in General)

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.

542

(26 replies, posted in General)

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 (-)

543

(26 replies, posted in General)

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:

544

(0 replies, posted in General)

I was trying to implement EHW's script for saving existing record as a new one.
I have one Invoice table that contains all sales, purchases, sale refunds, purchase refunds and products fields.


With the following script I get "Foreign key constraint" error?

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -------------------- >> SAVING REFUNDS as a NEW RECORD -------------------------------------------------------------------- >>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure frmInvoice_btnInvSave_OnClick (Sender: string; var Cancel: boolean);
begin
  If (Form1Button = 'Purchase Refund') or (Form1Button = 'Sale Refund') then
    Begin
     SqlExecute('Insert into Invoice (Counter1,Counter2,Counter3,Counter4,DBCRvalue,saleInvDate,saleInvRefundDate,purchInvDate,purchInvRefundDate,'
       + 'prodCode,prodName,prodDesc,prodPrice,prodNotes,id_TaxRates,'
       + 'SIprice,SIdiscount,SInetPrice,id_TaxRates1,SItaxAmt,SIgrossTotal,SIdelivIncTax,SIinvTotal,SIRprice,SIRdiscount,SIRnetPrice,SIRtaxAmt,SIRgrossTotal,SIRdelivIncTax,SIRinvTotal,SIRrefundTypeValues,'
       + 'PIprice,PIdiscount,PInetPrice,id_TaxRates2,PItaxAmt,PIgrossTotal,PIdelivIncTax,PIinvTotal,PIRprice,PIRdiscount,PIRnetPrice,PIRtaxAmt,PIRgrossTotal,PIRdelivIncTax,PIRinvTotal,PIRrefundTypeValues,'
       + 'SIpubNotes,SIprivNotes,SIRpubNotes,SIRprivNotes,PIpubNotes,PIprivNotes,PIRpubNotes,PIRprivNotes,'
       + 'id_Customer,id_Supplier,id_CoInfo,id_delivMethod,id_payMethod,id_Priority,id_returnReason,id_returnReason1) Values ("'

       + frmInvoice.EdCounter1.Text
       + '", "' + frmInvoice.edCounter2.Text
       + '", "' + frmInvoice.edCounter3.Text
       + '", "' + frmInvoice.edCounter4.Text
       + '", "' + frmInvoice.edDBCR.Text

       + '", "' + frmInvoice.edProdCode.Text
       + '", "' + frmInvoice.edProdName.Text
       + '", "' + frmInvoice.memProdDesc.Text
       + '", "' + frmInvoice.memProdNotes.Text

       + '", "' + frmInvoice.memSIpublicNotes.Text
       + '", "' + frmInvoice.memSIprivateNotes.Text
       + '", "' + frmInvoice.memSIRpublicNotes.Text
       + '", "' + frmInvoice.memSIRprivateNotes.Text
       + '", "' + frmInvoice.memPIpublicNotes.Text
       + '", "' + frmInvoice.memPIprivateNotes.Text
       + '", "' + frmInvoice.memPIRpublicNotes.Text
       + '", "' + frmInvoice.memPIRprivateNotes.Text

       + '", ' + frmInvoice.edProdUnitPrice.sqlValue
       + ', ' + frmInvoice.cbProdTaxRate.sqlValue
       //+ ', ' + frmInvoice.dbiProdImage01.sqlDBImage
       //+ ', ' + frmInvoice.dbiProdImage02.sqlDBImage

       + ', ' + frmInvoice.dtpSIdate.sqlDateTime
       + ', ' + frmInvoice.dtpSIRdate.sqlDateTime
       + ', ' + frmInvoice.dtpPIdate.sqlDateTime
       + ', ' + frmInvoice.dtpPIRdate.sqlDateTime

       + ', ' + frmInvoice.cbSIcustName.sqlValue
       + ', ' + frmInvoice.cbPIsuppName.sqlValue
       + ', ' + frmInvoice.cbInvCoName.sqlValue
       + ', ' + frmInvoice.cbInvDelivMethod.sqlValue
       + ', ' + frmInvoice.cbInvPayMethod.sqlValue
       + ', ' + frmInvoice.cbInvPriority.sqlValue
       + ', ' + frmInvoice.cbSIRrefundReason.sqlValue
       + ', ' + frmInvoice.cbPIRrefundReason.sqlValue

                // Sale and Sale refund Invs
       + ', ' + frmInvoice.edSIprice.sqlValue
       + ', ' + frmInvoice.edSIdiscount.sqlValue
       + ', ' + frmInvoice.edSInetPrice.sqlValue
       + ', ' + frmInvoice.cbSItaxRate.sqlValue
       + ', ' + frmInvoice.edSItaxAmt.sqlValue
       + ', ' + frmInvoice.edSIgrossTotal.sqlValue
       + ', ' + frmInvoice.edSIdelivIncTax.sqlValue
       + ', ' + frmInvoice.edSIinvTotal.sqlValue

       + ', ' + frmInvoice.edSIRprice.sqlValue
       + ', ' + frmInvoice.edSIRdiscount.sqlValue
       + ', ' + frmInvoice.edSIRnetPrice.sqlValue
       + ', ' + frmInvoice.cbSIRtaxRate.sqlValue
       + ', ' + frmInvoice.edSIRtaxAmt.sqlValue
       + ', ' + frmInvoice.edSIRgrossTotal.sqlValue
       + ', ' + frmInvoice.edSIRdelivIncTax.sqlValue
       + ', ' + frmInvoice.edSIRinvTotal.sqlValue

                // Purch and Purch refund Invs
       + ', ' + frmInvoice.edPIprice.sqlValue
       + ', ' + frmInvoice.edPIdiscount.sqlValue
       + ', ' + frmInvoice.edPInetPrice.sqlValue
       + ', ' + frmInvoice.cbPItaxRate.sqlValue
       + ', ' + frmInvoice.edPItaxAmt.sqlValue
       + ', ' + frmInvoice.edPIgrossTotal.sqlValue
       + ', ' + frmInvoice.edPIdelivIncTax.sqlValue
       + ', ' + frmInvoice.edPIinvTotal.sqlValue

       + ', ' + frmInvoice.edPIRprice.sqlValue
       + ', ' + frmInvoice.edPIRdiscount.sqlValue
       + ', ' + frmInvoice.edPIRnetPrice.sqlValue
       + ', ' + frmInvoice.cbPIRtaxRate.sqlValue
       + ', ' + frmInvoice.edPIRtaxAmt.sqlValue
       + ', ' + frmInvoice.edPIRgrossTotal.sqlValue
       + ', ' + frmInvoice.edPIRdelivIncTax.sqlValue
       + ', ' + frmInvoice.edPIRinvTotal.sqlValue

       + ')');
     Cancel := True;
     frmInvoice.Close;
     frmInvoice_btnInvSave_OnAfterClick('');
     Exit;
    End;
  If (frmInvoice.dbAction = 'ShowRecord') and (Form1Button = 'Add Sale') then frmInvoice.edCounter3.Value := 0;
end;

I'm not clear about use of single and double quotes in this script.
Also I couldn't find the correct type for DBImage field. Therefore they are commented out but I like to use DBImage fields too.


Hopefully EHW is around and not busy...

545

(5 replies, posted in General)

Hi Manixs,


See this thread if it offers any help...
http://myvisualdatabase.com/forum/viewtopic.php?id=3250

546

(3 replies, posted in General)

Hi Guys,


Thank you very much.................


What I was trying to do is disabling the click of tab itself in a multi tabs situation. User sees all available tabs but cannot click other than predefined tab with something like

Form2.pagecontrol1.ActivePageIndex := 1;
Form2.TabSheet0.Enabled  := False;
Form2.TabSheet2.Enabled  := False;
Form2.TabSheet3.Enabled  := False;

Perhaps it's not possible...


Derek, I added radio button simulation for the checkboxes so that only one can be selected.

procedure Form1_CheckBox1_OnClick (Sender: string);
begin
  if form1.checkbox1.checked = true then form1.tabsheet1.enabled := false else form1.tabsheet1.enabled := true;
     Form1.CheckBox2.Checked := False;
     Form1.CheckBox3.Checked := False;
end;

procedure Form1_CheckBox2_OnClick (Sender: string);
begin
  if form1.checkbox2.checked = true then form1.tabsheet1.tabvisible := false else form1.tabsheet1.tabvisible := true;
     Form1.CheckBox1.Checked := False;
     Form1.CheckBox3.Checked := False;
end;

procedure Form1_CheckBox3_OnClick (Sender: string);
begin
  if form1.checkbox3.checked = true then form1.tabsheet1.visible := false else form1.tabsheet1.visible := true;
     Form1.CheckBox2.Checked := False;
     Form1.CheckBox1.Checked := False;
end;


How can I use multiple statements with and in one line something like below which doesn't work:

procedure Form1_CheckBox1_OnClick (Sender: string);
begin
  if form1.checkbox1.checked = true then form1.tabsheet1.enabled := false else form1.tabsheet1.enabled := true;
     //Form1.CheckBox2.Checked := False;
     //Form1.CheckBox3.Checked := False;
     (Form1.CheckBox2.Checked) and (Form1.CheckBox3.Checked) := False;
end

Is it possible to use more than one and on same line?

547

(3 replies, posted in General)

Is it possible to disable a specific tab page on a PageControl?
If so, what's the script please?


This hides a tab page:

frmInvoice.tpSaleInv.TabVisible := False;

However this doesn't disable it:

frmInvoice.tpSaleInv.TabEnabled := False;

548

(15 replies, posted in General)

Hi EHW,


Agreed, using labels instead of fields in this case is definitely a better approach.
Thank you very much.................
Truly appreciated....................


I'm not sure what the advantage is in having a prefix at all since you identify the transaction with the "Type" field anyway. I assume it's the visual effect knowing what the transaction is when looking at the grid entries.

Indeed.

549

(15 replies, posted in General)

Hi EHW,


Thank you very much....................
Truly appreciated..........................
and extra thanks for the explanations.............


I wasn't sure if you intended to insert a new record for a sale or just change the type in the record.

In this part of the project intention was changing type to sale with it's own sale inv prefix and number. I think this part is working as intended thanks to your help.


I'm not sure I agree with your approach with this particular project. There is a lot of redundant data in the database, especially with all the prefixes stored in every record.

Which fields are redundant other than prefix fields?
I have tried hard coding them in script but failed.
I have tried adding new table "InvPrefix" with text fields "SI, Cr, PI, Db" and linked Invoice table to InvPrefix table but failed on this approach too.

550

(15 replies, posted in General)

You really do not need the "type" combobox since you are populating the exact value through script and disabling it on the form. And since it is not a user selected combobox field, you could just display the text field (which is hidden right now). I would remove the combobox and unhide, but disable, the text box for "type" and move it into it's place on the form.

Good point. Thanks. I think it's done.


I have tried to apply counters by script (thanks to Dmitry) in order to have multiple counters on same table with unique numbers that keeps their own count without a jump in count.


However, I couldn't resolve two issues:
1. After converting a purchase inv to sale inv, purch inv counter doesn't set the purch counter's last used count number. For instance, when a purch inv with number PI-1 to converted to sale inv, adding next purchase inv produces PI-3 number instead of PI-2. Additionally, product field becomes disabled. On re-run of of the app prod field becomes enabled as it should. I couldn't find a way to release of sale conditions after converting purch inv to sale inv.


2. I couldn't adopt the refund script to new counters.


Please see the attached sample project below: