public void TaxCorrectionOnReturnInvoice(Invoice invoice, object[] objPageDetails) { invoice.fltBalanceDue -= (invoice.fltGovernmentTaxAmount + invoice.fltProvincialTaxAmount); InvoiceManager IM = new InvoiceManager(); IM.CalculateNewInvoiceReturnTotalsToUpdate(invoice, objPageDetails); }
protected void GrdInvoicedItems_RowDeleting(object sender, GridViewDeleteEventArgs e) { //Collects current method for error tracking string method = "GrdInvoicedItems_RowDeleting"; object[] objPageDetails = { Session["currPage"].ToString(), method }; try { Invoice returnInvoice = IM.CallReturnCurrentInvoice(Convert.ToInt32(Request.QueryString["invoice"]), CU.location.intProvinceID, objPageDetails)[0]; lblInvalidQty.Visible = false; //Stores the info about the item in that index InvoiceItems selectedSku = IIM.CallReturnInvoiceItemForReturnProcess(Convert.ToInt32(((Label)GrdInvoicedItems.Rows[e.RowIndex].Cells[0].FindControl("lblInvoiceItemID")).Text), objPageDetails); //if (selectedSku.bitIsDiscountPercent) //{ // selectedSku.fltItemPrice -= ((selectedSku.fltItemDiscount / 100) * selectedSku.fltItemPrice); //} //else //{ // selectedSku.fltItemPrice -= selectedSku.fltItemDiscount; //} selectedSku.intInvoiceID = Convert.ToInt32(returnInvoice.intInvoiceID); if (!IIM.CallItemAlreadyInCart(selectedSku, objPageDetails)) { int currentQTY = selectedSku.intItemQuantity; string quantityForReturn = ((TextBox)GrdInvoicedItems.Rows[e.RowIndex].Cells[2].FindControl("quantityToReturn")).Text; int quantitySold = Convert.ToInt32(((Label)GrdInvoicedItems.Rows[e.RowIndex].Cells[2].FindControl("quantitySold")).Text); int returnQuantity = 1; if (quantityForReturn != "") { if (int.TryParse(quantityForReturn, out returnQuantity)) { returnQuantity = Convert.ToInt32(quantityForReturn); } } if (returnQuantity > quantitySold || returnQuantity < 1) { lblInvalidQty.Visible = true; } else { double returnDollars = 0; string returnAmount = ((TextBox)GrdInvoicedItems.Rows[e.RowIndex].Cells[7].FindControl("txtReturnAmount")).Text; if (returnAmount != "") { if (double.TryParse(returnAmount, out returnDollars)) { returnDollars = Convert.ToDouble(returnAmount); } } IIM.CallRemoveQTYFromInventoryWithSKU(selectedSku.intInventoryID, selectedSku.intItemTypeID, (currentQTY + returnQuantity), objPageDetails); selectedSku.intItemQuantity = returnQuantity; selectedSku.fltItemRefund = -1 * returnDollars; selectedSku.fltItemCost *= -1; IIM.CallInsertItemIntoSalesCart(selectedSku, returnInvoice.intTransactionTypeID, returnInvoice.dtmInvoiceDate, CU.location.intProvinceID, objPageDetails); //deselect the indexed item GrdInvoicedItems.EditIndex = -1; //store items available for return in session GrdInvoicedItems.DataSource = IIM.CallReturnInvoiceItemsFromProcessedSalesForReturn(returnInvoice.varInvoiceNumber.ToString(), returnInvoice.dtmInvoiceDate, CU.location.intProvinceID, objPageDetails); GrdInvoicedItems.DataBind(); IM.CalculateNewInvoiceReturnTotalsToUpdate(IM.CallReturnCurrentInvoice(returnInvoice.intInvoiceID, CU.location.intProvinceID, objPageDetails)[0], objPageDetails); returnInvoice = IM.CallReturnCurrentInvoice(returnInvoice.intInvoiceID, CU.location.intProvinceID, objPageDetails)[0]; GrdReturningItems.DataSource = returnInvoice.invoiceItems; GrdReturningItems.DataBind(); //recalculate the return total lblReturnSubtotalDisplay.Text = "$ " + returnInvoice.fltSubTotal.ToString("#0.00"); } } else { MessageBoxCustom.ShowMessage("Same item cannot be returned for a different amount. " + "Either cancel item to set both at new return amount or process a second return.", this); } } //Exception catch catch (ThreadAbortException tae) { } catch (Exception ex) { //Log all info into error table ER.CallLogError(ex, CU.employee.intEmployeeID, Convert.ToString(Session["currPage"]) + "-V3.2", method, this); //Display message box MessageBoxCustom.ShowMessage("An Error has occurred and been logged. " + "If you continue to receive this message please contact " + "your system administrator.", this); } }