예제 #1
0
        public void CreateRefund(RefundRequired request)
        {
            using (var context = new eRaceContext())
            {
                foreach (var item in request.RequiredInvoice)
                {
                    var newinvoice = new Invoice
                    {
                        EmployeeID  = item.EmployeeID,
                        InvoiceDate = item.InvoiceDate,
                        SubTotal    = item.SubTotal,
                        GST         = item.GST,
                        Total       = item.Total
                    };
                    context.Invoices.Add(newinvoice);
                }

                foreach (var item in request.ReuquiredDetail)
                {
                    var newdetail = new InvoiceDetail
                    {
                        ProductID = item.ProductID,
                        Quantity  = item.Quantity
                    };

                    var product = (from x in context.Products
                                   where x.ProductID == item.ProductID
                                   select x).FirstOrDefault();
                    product.QuantityOnHand += newdetail.Quantity;
                    context.Entry(product).Property(y => y.QuantityOnHand).IsModified = true;
                }


                foreach (var item in request.RequiredStore)
                {
                    var newstore = new StoreRefund
                    {
                        OriginalInvoiceID = item.OriginalInvoiceID,
                        ProductID         = item.ProductID,
                        Reason            = item.Reason,
                    };
                    context.StoreRefunds.Add(newstore);
                }
                context.SaveChanges();
            }
        }
예제 #2
0
        protected void Refund_Click(object sender, EventArgs e)
        {
            string  userName = User.Identity.Name;
            decimal subtotal = 0;
            decimal tax      = 0;
            decimal total    = 0;


            List <RefundDetail> newDetail = new List <RefundDetail>();
            RefundDetail        newRow    = null;
            CheckBox            selection = null;
            int error = 0;

            for (int rowIndex = 0; rowIndex < RefundInvoiceGridView.Rows.Count; rowIndex++)
            {
                selection = RefundInvoiceGridView.Rows[rowIndex].FindControl("RefundCheckBox") as CheckBox;
                if (!selection.Checked)
                {
                    MessageUserControl.ShowInfo("please select refund product and enter a refund reason");
                }
                else
                {
                    if (string.IsNullOrEmpty((RefundInvoiceGridView.Rows[rowIndex].FindControl("ReasonTextBox") as TextBox).Text))
                    {
                        MessageUserControl.ShowInfo("Please  enter a refund reason.");
                        error = 1;
                    }
                    else
                    {
                        newRow               = new RefundDetail();
                        newRow.Product       = (RefundInvoiceGridView.Rows[rowIndex].FindControl("ProductLabel") as Label).Text;
                        newRow.Qty           = int.Parse((RefundInvoiceGridView.Rows[rowIndex].FindControl("QtyLabel") as Label).Text);
                        newRow.Price         = decimal.Parse((RefundInvoiceGridView.Rows[rowIndex].FindControl("PriceLabel") as Label).Text);
                        newRow.Amount        = decimal.Parse((RefundInvoiceGridView.Rows[rowIndex].FindControl("AmountLabel") as Label).Text);
                        newRow.RestockCharge = decimal.Parse((RefundInvoiceGridView.Rows[rowIndex].FindControl("RestockChargeLabel") as Label).Text);
                        newRow.Reason        = (RefundInvoiceGridView.Rows[rowIndex].FindControl("ReasonTextBox") as TextBox).Text;
                        newDetail.Add(newRow);

                        subtotal = subtotal + newRow.Amount - newRow.RestockCharge;
                        tax      = subtotal * (decimal)0.05;
                        total    = subtotal + tax;
                    }
                }
            }


            int refunded = 0;

            if (error == 0)
            {
                foreach (var exists in newDetail)
                {
                    int prodID        = Get_ProductID(exists.Product);
                    int originvoiceID = int.Parse(InvocieNumber.Text);
                    refunded = CheckForRefunded(originvoiceID, prodID);
                    if (refunded == 1)
                    {
                    }
                    else
                    {
                        MessageUserControl.TryRun(() =>
                        {
                            SubtotalTextBox.Text = string.Format("${0:#,#.00}", subtotal.ToString());
                            GSTTextBox.Text      = string.Format("${0:#,#.00}", tax.ToString());
                            TotalTextBox.Text    = string.Format("${0:C}", total.ToString());


                            List <InvoiceDetailInfo> alldetaill = new List <InvoiceDetailInfo>();
                            List <StoreRefundInfo> refundlist   = new List <StoreRefundInfo>();

                            foreach (var item in newDetail)
                            {
                                alldetaill.Add(new InvoiceDetailInfo
                                {
                                    ProductID = Get_ProductID(item.Product),
                                    Quantity  = item.Qty,
                                });
                            }

                            foreach (var items in newDetail)
                            {
                                refundlist.Add(new StoreRefundInfo
                                {
                                    OriginalInvoiceID = int.Parse(InvocieNumber.Text),
                                    ProductID         = Get_ProductID(items.Product),
                                    Reason            = items.Reason,
                                }
                                               );
                            }

                            List <InvoiceInfo> NewInvoice = new List <InvoiceInfo>();

                            NewInvoice.Add(new InvoiceInfo
                            {
                                EmployeeID  = Get_EmpID(userName),
                                InvoiceDate = DateTime.Now,
                                SubTotal    = (subtotal * -1),
                                GST         = (tax * -1),
                                Total       = (total * -1),
                            });


                            RefundRequired request = new RefundRequired
                            {
                                RequiredInvoice = NewInvoice,
                                ReuquiredDetail = alldetaill,
                                RequiredStore   = refundlist
                            };

                            var controller = new StoreRefundController();
                            controller.CreateRefund(request);



                            foreach (GridViewRow row in RefundInvoiceGridView.Rows)
                            {
                                var checkbox  = row.FindControl("RefundCheckBox") as CheckBox;
                                var reasonbox = row.FindControl("ReasonTextBox") as TextBox;

                                checkbox.Enabled  = false;
                                reasonbox.Enabled = false;
                            }
                        }, "Refund successful", "Selected products have been refunded.");

                        RefundOrder.Enabled       = false;
                        RefundInvoiceTextBox.Text = getinvocieid().ToString();
                    }
                }
            }
            else
            {
                MessageUserControl.ShowInfo("one of the product is not enter a reason ");
            }
        }