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);
            }
        }
Exemplo n.º 2
0
        protected void GrdInventorySearched_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //Collects current method for error tracking
            string method = "GrdInventorySearched_RowCommand";

            object[] objPageDetails = { Session["currPage"].ToString(), method };
            try
            {
                Invoice invoice = IM.CallReturnCurrentInvoice(Convert.ToInt32(Request.QueryString["invoice"].ToString()), objPageDetails)[0];
                lblInvalidQty.Visible = false;
                int    index    = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                int    quantity = 1;
                string qty      = ((TextBox)GrdInventorySearched.Rows[index].Cells[2].FindControl("quantityToAdd")).Text;
                if (qty != "")
                {
                    if (int.TryParse(qty, out quantity))
                    {
                        quantity = Convert.ToInt32(qty);
                    }
                }
                int currentQty = Convert.ToInt32(((Label)GrdInventorySearched.Rows[index].Cells[2].FindControl("QuantityInOrder")).Text);
                if (quantity > currentQty || quantity < 1)
                {
                    lblInvalidQty.Visible = true;
                }
                else
                {
#pragma warning disable IDE0017 // Simplify object initialization
                    InvoiceItems selectedSku = new InvoiceItems();
#pragma warning restore IDE0017 // Simplify object initialization
                    selectedSku.intInventoryID = Convert.ToInt32(e.CommandArgument);
                    selectedSku.intInvoiceID   = invoice.intInvoiceID;
                    if (!IIM.CallItemAlreadyInCart(selectedSku, objPageDetails))
                    {
                        double discount       = 0;
                        string discountAmount = ((TextBox)GrdInventorySearched.Rows[index].Cells[5].FindControl("txtAmountDiscount")).Text;
                        if (discountAmount != "")
                        {
                            if (double.TryParse(discountAmount, out discount))
                            {
                                discount = Convert.ToDouble(discountAmount);
                            }
                        }
                        selectedSku.fltItemDiscount      = discount;
                        selectedSku.varItemDescription   = ((Label)GrdInventorySearched.Rows[index].Cells[3].FindControl("Description")).Text;
                        selectedSku.fltItemRefund        = 0;
                        selectedSku.fltItemPrice         = double.Parse(((Label)GrdInventorySearched.Rows[index].Cells[4].FindControl("rollPrice")).Text, NumberStyles.Currency);
                        selectedSku.fltItemCost          = double.Parse(((Label)GrdInventorySearched.Rows[index].Cells[4].FindControl("rollCost")).Text, NumberStyles.Currency);
                        selectedSku.bitIsDiscountPercent = ((CheckBox)GrdInventorySearched.Rows[index].Cells[5].FindControl("chkDiscountPercent")).Checked;
                        selectedSku.bitIsClubTradeIn     = ((CheckBox)GrdInventorySearched.Rows[index].Cells[6].FindControl("chkTradeInSearch")).Checked;
                        selectedSku.intItemTypeID        = Convert.ToInt32(((Label)GrdInventorySearched.Rows[index].Cells[7].FindControl("lblTypeIDSearch")).Text);
                        selectedSku.intItemQuantity      = quantity;

                        //add item to table and remove the added qty from current inventory
                        IIM.CallInsertItemIntoSalesCart(selectedSku, invoice.intTransactionTypeID, invoice.dtmInvoiceDate, Convert.ToInt32(DdlShippingProvince.SelectedValue), objPageDetails);
                        IIM.CallRemoveQTYFromInventoryWithSKU(selectedSku.intInventoryID, selectedSku.intItemTypeID, (currentQty - quantity), objPageDetails);

                        invoice = IM.CallReturnCurrentInvoice(invoice.intInvoiceID, objPageDetails)[0];
                        //Set an empty variable to bind to the searched items grid view so it is empty
                        GrdInventorySearched.DataSource = null;
                        GrdInventorySearched.DataBind();
                        Session["currentInvoice"] = invoice;
                        //Recalculate the new subtotal
                        UpdateInvoiceTotals();
                    }
                    else
                    {
                        MessageBoxCustom.ShowMessage("Item is already in the cart. Please update item in cart or process a second sale.", 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);
            }
        }