Beispiel #1
0
        private void DisplayEditMode()
        {
            var invoice = Session["Invoice"] as Invoice;

            invoice.InvoiceSkus = ValidSkus(invoice.InvoiceSkus);
            InvoiceInfo1.BindData(invoice, Session["ActionMode"] as string);
            InvoiceInfo1.BindInvoiceSkuGrid(invoice.InvoiceSkus);
            InvoiceInfo1.SetRenderMode(Ordering.Controls.Invoices.InvoiceInfo.ControlState.Edit);
            //begin - shan - mar 06, 2012 - show cancel button always
            //pnlStep2.Visible = true;
            pnlStep2.Visible = btnSave.Visible = litSaveInstr.Visible = true;
            //end
            lblPanelIndex1.Visible = false;
            lnkStep1Edit.Visible   = false;
            pnlStep1.CssClass      = "step1-editing";

            var totalAmount = invoice.InvoiceSkus.Aggregate <InvoiceSKU, decimal>(0, (current, sku) => current + sku.TotalPrice);

            InvoiceTotal1.TaxPercentage  = invoice.TaxPercentage;
            InvoiceTotal1.TaxAmount      = invoice.TaxAmount;
            InvoiceTotal1.ShipAmount     = invoice.ShippingAmount;
            InvoiceTotal1.ShipPercentage = invoice.ShippingPercentage;
            InvoiceTotal1.TotalTaxAmount = invoice.TaxAmount;
            InvoiceTotal1.TotalDue       = totalAmount - invoice.CustomerDiscount + invoice.TaxAmount + invoice.ShippingAmount;

            //begin - shan - mar 06, 2012 - show cancel button always
            //pnlStep2.Visible = false;
            pnlStep2.Visible = btnSave.Visible = litSaveInstr.Visible = false;
            //end
            Session["ActionMode"] = null;
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Redirect("~/Ordering/Invoice");
            Response.End();

            if (!Page.IsPostBack)
            {
                var    member        = (MembershipUser <DistributorProfileModel>)Membership.GetUser();
                string distributorID = member.Value.Id;
                if (null != Session["ActionMode"] && Session["Invoice"] != null)
                {
                    DisplayEditMode();
                }
                else if (null != Session["InvoiceContactID"])
                {
                    var invoiceContactID = (int)Session["InvoiceContactID"];
                    var assignedIds      = new List <int>();
                    var contact          = ContactsDataProvider.GetContactDetail(invoiceContactID, out assignedIds);
                    if (null != contact)
                    {
                        var invoice = CreateInvoiceFromContact(contact);


                        lblPanelIndex1.Visible = true;
                        lnkStep1Edit.Visible   = false;
                        pnlStep1.CssClass      = "step1-editing";
                        InvoiceInfo1.BindData(invoice, string.Empty);
                        InvoiceInfo1.BindInvoiceSkuGrid();
                        InvoiceInfo1.SetInvoiceDistributorNumber(distributorID);
                        InvoiceInfo1.SetRenderMode(Ordering.Controls.Invoices.InvoiceInfo.ControlState.Edit);
                        pnlStep1.Visible = true;
                        //begin - shan - mar 06, 2012 - show cancel button always
                        //pnlStep2.Visible = false;
                        pnlStep2.Visible = btnSave.Visible = litSaveInstr.Visible = false;
                        //end
                        Session["InvoiceContactID"] = null;
                    }
                    else
                    {
                    }
                }
                //From Bizworks
                else if (Session["InvoiceStep2"] != null && Convert.ToBoolean(Session["InvoiceStep2"]) == true)
                {
                    var invoice = Session["Invoice"] as Invoice;
                    InvoiceInfo1.BindData(invoice, string.Empty);
                    InvoiceInfo1.BindInvoiceSkuGrid();
                    InvoiceInfo1.SetRenderMode(Ordering.Controls.Invoices.InvoiceInfo.ControlState.Read);
                    //begin - shan - mar 06, 2012 - show cancel button always
                    //pnlStep2.Visible = true;
                    pnlStep2.Visible = btnSave.Visible = litSaveInstr.Visible = true;
                    //end
                    lblPanelIndex1.Visible = false;
                    lnkStep1Edit.Visible   = true;
                    pnlStep1.CssClass      = "step1-readonly";
                    decimal totalAmount = 0;
                    if (null != invoice.InvoiceSkus)
                    {
                        foreach (var sku in invoice.InvoiceSkus)
                        {
                            totalAmount = totalAmount + sku.TotalPrice;
                        }

                        var taxAmount = 0M;

                        if (invoice.TaxAmount == 0)
                        {
                            taxAmount = OrderProvider.CalculateTaxForInvoice(invoice);
                        }
                        else
                        {
                            taxAmount = invoice.TaxAmount;
                        }

                        var taxRate = 0M;
                        if (taxAmount != 0)
                        {
                            taxRate = decimal.Divide(taxAmount, totalAmount);
                        }

                        var totalDue      = totalAmount - invoice.CustomerDiscount;
                        var taxPercentage = 0M;


                        taxPercentage = (taxRate > 0) ? taxRate * 100 : invoice.TaxPercentage;

                        InvoiceTotal1.RenderTaxErrorMessage(!(taxAmount > 0 || taxPercentage > 0));
                        InvoiceTotal1.TaxPercentage = taxPercentage;


                        InvoiceTotal1.TotalTaxAmount = (invoice.TaxAmount > 0) ? invoice.TaxAmount : Math.Round((totalDue * invoice.TaxPercentage / 100), 2);;

                        totalDue += invoice.TaxAmount > 0 ? invoice.TaxAmount : Math.Round((totalDue * invoice.TaxPercentage / 100), 2);

                        InvoiceTotal1.ShipAmount          = invoice.ShippingAmount;
                        InvoiceTotal1.ShipPercentage      = invoice.ShippingPercentage;
                        InvoiceTotal1.TotalShippingAmount = (invoice.ShippingAmount > 0) ? invoice.ShippingAmount : Math.Round((totalDue * invoice.ShippingPercentage / 100), 2);

                        totalDue += invoice.ShippingAmount > 0 ? invoice.ShippingAmount : Math.Round((totalDue * invoice.ShippingPercentage / 100), 2);

                        InvoiceTotal1.TotalDue = totalDue;
                        this.InvoiceTotal1.SetInvoiceStatus(invoice.Status);
                    }
                    Session["InvoiceStep2"] = null;
                }
                //Form DWS.
                else if (!string.IsNullOrEmpty(Request.QueryString["cid"]))
                {
                    var customerOrderID  = Request.QueryString["cid"];
                    var customerOrderV01 = CustomerOrderingProvider.GetCustomerOrderByOrderID(customerOrderID);
                    if (null != customerOrderV01)
                    {
                        var invoice = CreateInvoiceFromCustomerOrder(customerOrderV01);
                        lblPanelIndex1.Visible = true;
                        lnkStep1Edit.Visible   = false;
                        pnlStep1.CssClass      = "step1-editing";
                        InvoiceInfo1.BindData(invoice, string.Empty);
                        InvoiceInfo1.BindInvoiceSkuGrid();
                        InvoiceInfo1.SetInvoiceDistributorNumber(distributorID);
                        InvoiceInfo1.SetRenderMode(Ordering.Controls.Invoices.InvoiceInfo.ControlState.Edit);
                        pnlStep1.Visible = true;
                        //begin - shan - mar 06, 2012 - show cancel button always
                        //pnlStep2.Visible = false;
                        pnlStep2.Visible = btnSave.Visible = litSaveInstr.Visible = false;
                        //end
                    }
                }
                else if (!string.IsNullOrEmpty(Request.QueryString["c"]))
                {
                    var assignedIds = new List <int>();
                    var contactid   = Request.QueryString["c"];
                    var contact     = ContactsDataProvider.GetContactDetail(Convert.ToInt32(contactid), out assignedIds);
                    if (null != contact)
                    {
                        var invoice = CreateInvoiceFromContact(contact);
                        lblPanelIndex1.Visible = true;
                        lnkStep1Edit.Visible   = false;
                        pnlStep1.CssClass      = "step1-editing";
                        InvoiceInfo1.BindData(invoice, string.Empty);
                        InvoiceInfo1.BindInvoiceSkuGrid();
                        InvoiceInfo1.SetInvoiceDistributorNumber(distributorID);
                        InvoiceInfo1.SetRenderMode(Ordering.Controls.Invoices.InvoiceInfo.ControlState.Edit);
                        pnlStep1.Visible = true;
                        //begin - shan - mar 06, 2012 - show cancel button always
                        //pnlStep2.Visible = false;
                        pnlStep2.Visible = btnSave.Visible = litSaveInstr.Visible = false;
                        //end
                    }
                }
                else
                {
                    lblPanelIndex1.Visible = true;
                    lnkStep1Edit.Visible   = false;
                    pnlStep1.CssClass      = "step1-editing";
                    InvoiceInfo1.SetInvoiceDistributorNumber(distributorID);
                    InvoiceInfo1.SetRenderMode(Ordering.Controls.Invoices.InvoiceInfo.ControlState.Edit);
                    pnlStep1.Visible = true;
                    //begin - shan - mar 06, 2012 - show cancel button always
                    //pnlStep2.Visible = false;
                    pnlStep2.Visible = btnSave.Visible = litSaveInstr.Visible = false;
                    //end
                    //shan - mar 14, 2012 - format the sub total fields and set default values
                    //shan - mar 12, 2012 - set invoice date to current date when creating for first time
                    //this.InvoiceInfo1.InvoiceDatePicker.SelectedDate = DateTime.Today;
                    this.InvoiceInfo1.SetDefaultValues();
                    //coming to page for first time..clear invoice session, if exists..
                    this.Session["Invoice"] = null;
                }
            }

            (Master as OrderingMaster).gdoNavMidCSS("gdo-nav-mid col-sm-7 gdo-nav-mid-invoices");
        }