예제 #1
0
        public OrganizationModule()
        {
            this.RequiresClaims(new string[1] { Account.OWNER });

            Post["/setuporganization"] = p =>
            {
                try
                {
                    string name = (string)this.Request.Form.name;
                    string timezone = (string)this.Request.Form.timezone;
                    string curr = (string)this.Request.Form.curr;
                    int starts = (int)this.Request.Form.starts;
                    Account acc = this.CurrentAccount();
                    this.OrganizationRepository().Save(new Organization()
                    {
                        _id = acc.OwnerId,
                        OwnerId = acc.OwnerId,
                        Name = name,
                        Currency = curr,
                        FiscalYearPeriod = starts
                    });
                    Image img = Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Content\images\default-logo-organization.png"));
                    MemoryStream imgStream = new MemoryStream();
                    img.Save(imgStream, ImageFormat.Png);
                    byte[] logoData = readImageAndCompress(imgStream);

                    LogoOrganization logoOrganization = new LogoOrganization { _id = this.CurrentAccount().OwnerId, ImageData = logoData, OwnerId = this.CurrentAccount().OwnerId };
                    this.LogoOrganizationCommand().Save(logoOrganization);
                }
                catch (Exception ex)
                {
                    return Response.AsRedirect("/?error=true&message=" + ex.Message);
                }
                return Response.AsRedirect("/");
            };

            Post["/settingorganization"] = p =>
                {
                    try
                    {
                        var test = this.Request.Form.Organization;
                        Organization org = JsonConvert.DeserializeObject<Organization>(this.Request.Form.Organization);
                        org._id = this.CurrentAccount().OwnerId;
                        this.OrganizationRepository().Save(org);
                    }
                    catch (Exception ex)
                    {
                        return Response.AsJson(new { error = false, message = ex.Message });
                    }
                    return Response.AsJson("success");
                };

            Post["/uploadlogoorg"] = p =>
            {
                Stream stream = this.Request.Files.FirstOrDefault().Value;
                byte[] logoData = readImageAndCompress(stream);

                LogoOrganization logoOrganization = new LogoOrganization { _id = this.CurrentAccount().OwnerId, ImageData = logoData, OwnerId = this.CurrentAccount().OwnerId };
                this.LogoOrganizationCommand().Save(logoOrganization);
                return Response.AsRedirect("/uploadlogo");
            };

            Get["/logoOrganization"] = p =>
            {
                LogoOrganization logo = this.LogoOrganizationQuery().GetLogo(this.CurrentAccount().OwnerId);
                if (logo == null)
                    return null;
                MemoryStream stream = new MemoryStream(Zip7.Decompress(logo.ImageData));
                return Response.FromStream(stream, "image/png");
            };
        }
예제 #2
0
 public string GetInvoiceDefaultTemplate(InvoiceReport invoice, Customer customer, Organization organization, LogoOrganization logo)
 {
     int sayTotal = Convert.ToInt32(GetTotal(invoice.SubTotal, GetTotalDiscount(invoice.Items), GetTotalTax()));
     StringTemplate template = new StringTemplate(TEMPLATE);
     template.SetAttribute("invoices", invoice);
     template.SetAttribute("customer", customer);
     template.SetAttribute("organization", organization);
     template.SetAttribute("totaldiscount", GetTotalDiscount(invoice.Items).ToString("###,###,###,##0"));
     template.SetAttribute("totaltax", GetTotalTax().ToString("###,###,###,##0"));
     template.SetAttribute("total", GetTotal(invoice.SubTotal, GetTotalDiscount(invoice.Items), GetTotalTax()).ToString("###,###,###,##0"));
     template.SetAttribute("InvoiceDate",invoice.InvoiceDate.ToString("dd-MMM-yyyy"));
     template.SetAttribute("DueDate", invoice.DueDate.ToString("dd-MMM-yyyy"));
     template.SetAttribute("SubTotal", invoice.SubTotal.ToString("###,###,###,##0"));
     template.SetAttribute("terbilang", SayNumber.Terbilang(sayTotal));
     template.SetAttribute("Note", invoice.Note);
     if (logo != null)
     {
         template.SetAttribute("logodata", Convert.ToBase64String(logo.ImageData));
     }
     string InvoiceReport = template.ToString();
     return InvoiceReport;
 }
예제 #3
0
 public void Save(LogoOrganization logo)
 {
     _collection.Save(logo);
 }