Ejemplo n.º 1
0
        internal static string CreateInvoice(long userId, string status, string transid, string paymentmethod, ProductInfo productInfo, ProductPriceInfo ppi)
        {
            string companyName = string.Empty;
            string userPath = String.Empty;
            string password = HttpContext.Current.Session["access"] as string;
            UserInfo userInfo = null;
            ClientInfo clientInfo = null;
            using (Database db = new MySqlDatabase())
            {
                userPath = db.GetUserDocumentPath(userId, password);

                userPath = userPath.Replace("\\", "/");

                if (!Directory.Exists(userPath))
                    Directory.CreateDirectory(userPath);

                userInfo = db.GetUser(userId, password);
                clientInfo = db.GetClientInfo(userId);

                companyName = clientInfo.CompanyName;
            }
            // complete userPath with document name
            string filename = String.Format("INV{0}.pdf", transid);
            userPath = Path.Combine(userPath, filename);

            // Get the invoice template from the proper location
            string templatePath = Resource.InvoiceTemplate;
            string invoiceTemplate = HttpContext.Current.Server.MapPath(templatePath);
            try
            {
                InvoiceForm form = new InvoiceForm(invoiceTemplate);
                string culture = "nl-NL";
                if (HttpContext.Current.Session["culture"] != null)
                    culture = HttpContext.Current.Session["culture"] as string;
                CultureInfo cultureInfo = new CultureInfo(culture);

                List<string> fields = new List<string>();
                fields.Add(clientInfo.GetFullName());
                fields.Add(clientInfo.AddressLine1);
                if (!string.IsNullOrEmpty(clientInfo.AddressLine2))
                    fields.Add(clientInfo.AddressLine2);
                string tmpResidence = clientInfo.ZipCode + " " + clientInfo.City.ToUpper();
                if (!string.IsNullOrEmpty(tmpResidence))
                    fields.Add(tmpResidence);
                if (!string.IsNullOrEmpty(clientInfo.Country))
                    fields.Add(clientInfo.Country);
                while (fields.Count < 5)
                    fields.Add(" ");

                form.ClientAddress = fields.ToArray();
                form.InvoiceDate = DateTime.Now.ToString("d", cultureInfo);
                form.InvoiceNumber = transid;
                using (Database db = new MySqlDatabase())
                {
                    Transaction transaction = db.GetTransaction(Util.UserId, transid);
                    foreach (TransactionLine tl in transaction.TransactionLines)
                    {
                        form.InvoiceLines.Add(new PdfInvoiceLine()
                        {
                            Description = tl.Description,
                            Quantity = tl.Quantity,
                            UnitPrice = tl.Price,
                            VatRate = tl.VatPercentage
                        });
                    }
                }
                form.GenerateInvoice(userPath, companyName);
            }
            catch (Exception ex)
            {
                Logger.Instance.Write(LogLevel.Error, ex, "[CreateInvoice]");
            }

            SendInvoice(userId, userPath);

            return userPath;
        }
        private bool isProfileCompleted()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["userId"]))
            {
                Util.UserId = Convert.ToInt64(Request.QueryString["userId"]);
            }

            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);
                DataSet ds = db.GetRegister(Util.UserId);

                string userDocPath = db.GetUserDocumentPath(ui.UserId, Session["access"] as string);
                decimal percentComplete = DetermineCompletion(userDocPath, ui, ci);
                Session["percentComplete"] = percentComplete;

                Session["isActive"] = ui.IsActive;
                if (percentComplete < 100)
                    return false;
                else
                    return true;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Logger logger = Logger.Instance;

            IncludePage(BuyProductInc, Resources.Resource.incBuyProduct);
            IncludePage(RhosMovementInc, Resources.Resource.incRhosMovement2);

            string activeModule = string.Empty;

            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName);// ci.GetFullName());
                CreditsLiteral.Text = Util.GetUserCredits(Util.UserId).ToString();
                ProtectedLiteral.Text = protectedTracks.ToString();
                string userDocPath = db.GetUserDocumentPath(ui.UserId, Session["access"] as string);
                decimal percentComplete = DetermineCompletion(userDocPath, ui, ci);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            if (!IsPostBack)
            {
                long prodid = -1;
                long transid = -1;
                ParamsDictionary parms = new ParamsDictionary();
                string desc = "???";
                if (Request.Params["pid"] != null /* && Request.Params["tid"] == null */)
                {
                    prodid = Convert.ToInt64(Request.Params["pid"]);
                    if (prodid > -1)
                    {
                        using (Database db = new MySqlDatabase())
                        {
                            ProductInfo pi = db.GetProductById(prodid);
                            ProductPriceInfoList ppil = db.GetProductPrices(prodid);
                            decimal price = 0m;
                            foreach (ProductPriceInfo ppi in ppil)
                            {
                                if (ppi.IsoCurrency == "EUR")
                                {
                                    price = ppi.Price;
                                    break;
                                }
                            }

                            desc = pi.Name;
                            parms.Add("{%product%}", desc);
                            parms.Add("{%credits%}", pi.Credits.ToString());
                            parms.Add("{%price%}", string.Format("{0:C}", price));
                        }

                        string _priceInEuro = parms["{%price%}"];

                        if (_priceInEuro.Contains("$"))
                        {
                            parms.Remove("{%price%}");
                            _priceInEuro = _priceInEuro.Replace("$", "€").Replace(".", ",");
                            parms.Add("{%price%}", _priceInEuro);
                        }
                    }
                }

                if (Request.Params["tid"] != null /* && Request.Params["pid"] != null */)
                {
                    transid = Convert.ToInt64(Request.Params["tid"]);
                    if (transid > -1)
                    {
                        using (Database db = new MySqlDatabase())
                        {
                            Transaction transaction = db.GetQuotation(transid);
                            string statuscode = transaction.StatusCode;
                            string[] parts = statuscode.Split('(', ':', ')');
                            int credits = 0;
                            if (parts.Length >= 3)
                                credits = Convert.ToInt32(parts[2]);
                            desc = string.Format(Resources.Resource.BulkPurchase, credits, transaction.Amount);
                            parms.Add("{%product%}", desc);
                            parms.Add("{%credits%}", credits.ToString());
                        }
                    }
                }

                IncludePage(ProductInc, Resources.Resource.incBuyProductText, parms);

                //ProductLiteral.Text = string.Format(Resources.Resource.Purchase1, desc);
            }

            if (Convert.ToString(Session["culture"]).Contains("nl"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
            }
        }