Cheque EFT payments - discount wont get saved  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Cheque EFT payments - discount wont get saved

Postby Riyaz » Thu Aug 11, 2016 5:57 pm

Hi There

Have created a plugin which automatically calculates the Home Discount Amount for invoices that are eligible for discount (considering paid within certain days as mentioned in the Creditor) ,

This discount processing triggers when the SELECT button is clicked on the Creditor Cheque/EFT payment screen.

Am facing two issues here

#1, After the discounts are auto populated in the respective Home Discount Amount grid cell , if I click SAVE button, the discount goes back to ZERO

#2, After the discounts are auto populated in the respective Home Discount Amount grid cell , if I DELETE any of the grid records prior to saving, the discount goes back to ZERO

What works is

if I manually enter a discount amount, that is perfectly retained under both the above cases.

Your help is highly appreciated, pls let me know on whats happening here. I've also tried to save the values in the database as it alters the gridlines to see if that matters, but apparently not.
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Cheque EFT payments - discount wont get saved

Postby Mike.Sheen » Thu Aug 11, 2016 7:47 pm

Hi Riyaz,

Can you provide the plugin you have which demonstrates the issue? We'll be able to troubleshoot this much quicker that way.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Cheque EFT payments - discount wont get saved

Postby Riyaz » Thu Aug 11, 2016 8:33 pm

Thanks for responding, pls find the plugin attached
Attachments
Plugin EFT Discount calculation.xml
Auto Discount calculator
(32.01 KiB) Downloaded 95 times
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Cheque EFT payments - discount wont get saved

Postby Riyaz » Tue Aug 16, 2016 1:07 pm

Hi there

Pls let me know on this, thanks
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Cheque EFT payments - discount wont get saved

Postby Riyaz » Fri Aug 19, 2016 3:10 pm

Hello Jiwa Admins

Can anyone pls kindly get back on this, I would really appreciate it. Thanks
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Cheque EFT payments - discount wont get saved

Postby Mike.Sheen » Wed Aug 24, 2016 9:48 pm

Riyaz wrote:Hello Jiwa Admins

Can anyone pls kindly get back on this, I would really appreciate it. Thanks


The problem you have is because you are looking at grid cell contents, and also setting those instead of the business logic properties. Pretty much everywhere in Jiwa the rule is to talk to the business logic properties when examining and setting values. Don't talk to the grid unless you want to simply alter the appearance. If you want to alter values, talk to the business logic.

If you set cell contents on a grid via code the business logic doesn't receive the new value and this saving it will cause it to go back to the prior value.

To give you a some guidance, I've looked at your plugin and can see in your SaveStart where you begin to iterate through the grid cell contents for each row and make decisions / calculations based on that - Don't do that - instead use the business logic attached to the form. In your plugin you already added a handler to the SaveStart of the business logic within the Form, so the sender argument is the business logic:

Code: Select all
private void SaveStart(object sender, System.EventArgs e)
{      
   var creditorChequePaymentBusinessLogic = (JiwaFinancials.Jiwa.JiwaCreditorChqPay.CreditorChequePayment)sender;
   
   foreach (JiwaFinancials.Jiwa.JiwaCreditorChqPay.Creditor creditor in creditorChequePaymentBusinessLogic.Creditors)
   {
      // read payment terms here for the creditor.  No sense doing it on the following inner loop as they're the same creditor.
      
      foreach (JiwaFinancials.Jiwa.JiwaCreditorChqPay.clsPayLineInvoice invoice in creditor.InvoicePaymentLines)
      {            
         // apply discount here: *** NOTE *** You might want to opt to only do this if creditorChequePamentBusinessLogic.InsertFlag == true,
         // as that is when it is first saved after being created
         //BUT wrap that condition around ALL the code in this handler not just this inner loop, otherwise you'd be hitting the database on every save, not just the initial save.
         invoice.DiscountAmount = ? ;
      }
   }
}


This should set you on your way.

Mike

PS: I insist you use parameters for your SQL queries - your building of a string is BAD. YOU MUST FIX THIS. A malicious user could create a creditor with account no. of '111; DELETE FROM CR_Main' and your query would happily delete all creditors from the database - this is a basic SQL Injection attack, and all your queries direct to the database should prevent against that - using parameters with your SQL command will guard against this.

You should also wrap all queries in a using statement to make sure everything is disposed of correctly.

Also, don't use GetNewConnection like you are. Use the current SQL connection or you're going to have serious integrity issues!

So instead of:

Code: Select all
SqlCommand cmd=new SqlCommand("select EarlyPayDisOnRemitDays,EarlyPayDisOnRemitAmt from CR_Main where AccountNo ='"+ AccountNo +"'",JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.GetNewConnection(JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.ConnectionString));
      SqlDataReader reader= JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.ExecuteReader(cmd);


use:

Code: Select all
int EarlyPayDisOnRemitDays = 0;
decimal EarlyPayDisOnRemitAmt = 0;

var db = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database;
System.Data.SqlClient.SqlParameter SQLParam = null;
System.Data.SqlClient.SqlDataReader SQLReader = null;
try
{
   string SQL = @"SELECT EarlyPayDisOnRemitDays, EarlyPayDisOnRemitAmt
         FROM CR_Main WHERE
         AccountNo = @AccountNo";

   using (SqlCommand SQLCmd = new SqlCommand(SQL, db.SQLConnection, db.SQLTransaction))
   {
      SQLParam = new SqlParameter("@AccountNo", System.Data.SqlDbType.VarChar);
      SQLParam.Value = AccountNo;
      SQLCmd.Parameters.Add(SQLParam);
      
      SQLReader = db.ExecuteReader(SQLCmd);

      if (SQLReader.Read() == true)
      {
         EarlyPayDisOnRemitDays = int.Parse(db.Sanitise(SQLReader, "EarlyPayDisOnRemitDays").ToString());
         EarlyPayDisOnRemitAmt = decimal.Parse(db.Sanitise(SQLReader, "EarlyPayDisOnRemitAmt").ToString());
      }
   }

   SQLReader.Close();
}
finally
{
   if (SQLReader != null)
   {
      SQLReader.Close();
   }
}


That way you will use the current connection and transaction. Not doing it as per above will cause very hard to troubleshoot issues (weird errors sometimes, but not always).
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Cheque EFT payments - discount wont get saved

Postby Riyaz » Mon Aug 29, 2016 1:37 pm

Hi Mike

Thanks very much for getting back, as advised by yourself I had moved the code under SaveStart of BusinessLogic region, BUT it wont trigger. I tried having a MessageBox in it it as well to see if it passes through the BusinessLogic section.

I then tried to create a simple plugin to just messagebox on save event under BusinessLogic region, still wont work. Not sure what I'm missing here. Pls see the plugin attached, if possible advise a sample coding in C# as well.

P.S: I also tried the SaveStart event of JiwaCreditorChqPay , instead of JiwaCreditorChqPayUI as used in the attached plugin. But still no luck.

thanks for helping
Attachments
Plugin Debtor EFT Discounts Calculate.xml
(29.53 KiB) Downloaded 77 times
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Cheque EFT payments - discount wont get saved

Postby Riyaz » Mon Sep 12, 2016 1:38 pm

Hi There

Pls let me know on this, I would really appreciate it
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Cheque EFT payments - discount wont get saved

Postby Riyaz » Thu Nov 10, 2016 8:20 pm

Hi There

Pls advise on this, thanks
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Cheque EFT payments - discount wont get saved  Topic is solved

Postby Mike.Sheen » Sun Nov 13, 2016 1:06 pm

Riyaz wrote:Hi Mike

Thanks very much for getting back, as advised by yourself I had moved the code under SaveStart of BusinessLogic region, BUT it wont trigger. I tried having a MessageBox in it it as well to see if it passes through the BusinessLogic section.

I then tried to create a simple plugin to just messagebox on save event under BusinessLogic region, still wont work. Not sure what I'm missing here. Pls see the plugin attached, if possible advise a sample coding in C# as well.

P.S: I also tried the SaveStart event of JiwaCreditorChqPay , instead of JiwaCreditorChqPayUI as used in the attached plugin. But still no luck.

thanks for helping


In your provided sample you've tried to hook into the form's tool click from within the business logic class - this won't work as the business logic doesn't know about the form.

If you want to perform actions based on a ribbon tool click, then you need to add those handlers in the FormPlugin class instead.

I've attached a modified version of your plugin which does this.

PS: Your plugin name is somewhat confusing - Creditor EFT payments has nothing to do with debtors!
Attachments
Plugin Debtor EFT Discounts Calculate.xml
Confusingly Named Plugin
(32.36 KiB) Downloaded 75 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 4 guests

cron