C# help - GL Side effect AP Invoice

Hi all,


Hope everyone is having a great Holiday Season!  I'm struggling with some C# code and need some help. In AP Invoice Entry I need to put the invoice on hold for a review process if any of the following conditions are met: Received Qty > PO Qty, Invoice Unit cost > PO Unit Cost, Invoice Ext Cost > PO Ext cost. I wrote the following C# code which works and will put the invoice on hold. The problem is I am having an unanticipated side effect. When I use this code I am unable to change, view or maintain the GL Account under the GL Analysis Tab.  If I enter a misc line, I just get a gray box, that doesn't show anything and doesn't allow any updates. Any thoughts or help would be greatly appreciated, I'm by no means a programmer, so forgive me if my function isn't written properly! - Bobby


private void baseToolbarsManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)

{

//  MessageBox.Show("Got Here1");

if(args.Tool.Key.ToString()=="SaveTool") // Action will only run when the save button is clicked

{

bool holdInvoice = false; //Set holdinvoice variable to false. the program will set to true if any of the conditions are met

EpiDataView edvInvHed = ((EpiDataView)(oTrans.EpiDataViews["APInvHed"]));

if (!edvInvHed.HasRow) //Check to see if there is a row in the Epi Dataview, if not then return, nothing to do until data is present.

{ return;}

if ((bool)edvInvHed.dataView[edvInvHed.Row]["InvoiceHeld"] ){

return; //Invoice is already on hold don't need to show message again

}


int PONum = Convert.ToInt32(edvInvHed.dataView[edvInvHed.Row]["REFPONum"]); //Get PO Number from invoice header

if(PONum != null && PONum != 0) // Check to see if PO number is legit

{

EpiDataView edvInvDtl = ((EpiDataView)(oTrans.EpiDataViews["APInvDtl"]));

foreach(DataRow row in edvInvDtl.dataView.Table.Rows) 

{

//declare variables to use in calculations

double poRelQty = Convert.ToDouble(row["PORelQty"].ToString());

double scrVendorQty = Convert.ToDouble(row["ScrVendorQty"].ToString());

double scrUnitCost = Convert.ToDouble(row["ScrUnitCost"].ToString());

double poUnitCost = Convert.ToDouble(row["POUnitCost"].ToString());

double scrExtCost = Convert.ToDouble(row["ScrExtCost"].ToString());

double poReceivedQty = Convert.ToDouble(row["POReceivedQty"].ToString());

string partnum = Convert.ToString(row["PartNum"].ToString());

if((poReceivedQty > poRelQty) && partnum != "Sales Tax")

{

holdInvoice = true;

}

else if((scrUnitCost > (poUnitCost + 0.50)) && partnum != "Sales Tax")

{

holdInvoice = true;

}

else if((scrExtCost > Math.Round(((poRelQty * poUnitCost) + 0.50),2)) && partnum != "Sales Tax")

{

holdInvoice = true;

}

}

}

else {holdInvoice = true;}


if(holdInvoice == true)

{

//EpiDataView edvInvHed = ( (EpiDataView) (oTrans.EpiDataViews["APInvHed"]));

if((bool)edvInvHed.dataView[edvInvHed.Row]["Checkbox02"]) {

return; // it' s approved

}

else if((bool)edvInvHed.dataView[edvInvHed.Row]["DebitMemo"]) {

return; //Don't need to put a hold on for debit memo's

}


MessageBox.Show("Invoice will be put on hold, as it requires approval.");

edvInvHed.dataView[edvInvHed.Row]["InvoiceHeld"] = true;

}

}

else {return;}

}