Пример #1
0
 public void Save(LogoOrganization logo)
 {
     _collection.Save(logo);
 }
Пример #2
0
        public InvoiceModule()
        {
            this.RequiresAuthentication();
            Post["/createinvoice"] = p =>
            {
                try
                {
                    Invoices result = this.InvoiceService().Create(this.Request.Form.invoice, this.CurrentAccount().OwnerId);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    return(Response.AsJson(new { error = true, message = ex.Message }));
                }
            };
            Get["/GetDataInvoice"] = p =>
            {
                int countInvoice = this.InvoicesQueryRepository().CountInvoice(this.CurrentAccount().OwnerId);
                return(Response.AsJson(countInvoice));
            };
            Get["/GetDataInvoiceToPaging/{start}/{limit}"] = p =>
            {
                int start = p.start;
                int limit = p.limit;
                IEnumerable <Invoices> invoices = this.InvoicesQueryRepository().GetDataInvoiceToPaging(this.CurrentAccount().OwnerId, start, limit);
                return(Response.AsJson(invoices));
            };
            Get["/GetDataInvoiceToPDF/{id}"] = p =>
            {
                Guid          invoiceId     = p.id;
                Invoices      invoice       = this.InvoicesQueryRepository().FindById(invoiceId, this.CurrentAccount().OwnerId);
                InvoiceReport invoiceReport = new InvoiceReport(invoice);
                Customer      customer      = this.CustomerReportRepository().GetCustomerById(Guid.Parse(invoice.CustomerId));
                Organization  organization  = this.OrganizationReportRepository().FindByOwnerId(this.CurrentAccount().OwnerId);

                LogoOrganization logo     = this.LogoOrganizationQuery().GetLogo(this.CurrentAccount().OwnerId);
                DefaultTemplate  template = new DefaultTemplate();

                string html = template.GetInvoiceDefaultTemplate(invoiceReport, customer, organization, logo);
                EO.Pdf.Runtime.AddLicense("aP0BELxbvNO/++OfmaQHEPGs4PP/6KFspbSzy653hI6xy59Zs7PyF+uo7sKe" +
                                          "tZ9Zl6TNGvGd3PbaGeWol+jyH+R2mbbA3a5rp7XDzZ+v3PYEFO6ntKbEzZ9o" +
                                          "tZGby59Zl8AEFOan2PgGHeR3q9bF266OzffU8MOSwdXjFvlww7vSIrx2s7ME" +
                                          "FOan2PgGHeR3hI7N2uui2un/HuR3hI514+30EO2s3MKetZ9Zl6TNF+ic3PIE" +
                                          "EMidtbjC4K9qq73K47J1pvD6DuSn6unaD71GgaSxy5914+30EO2s3OnP566l" +
                                          "4Of2GfKe3MKetZ9Zl6TNDOul5vvPuIlZl6Sxy59Zl8DyD+NZ6w==");
                EO.Pdf.HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0.5f, 0.3f, 7.5f, 10f);
                MemoryStream memStream = new MemoryStream();
                HtmlToPdf.ConvertHtml(html, memStream);
                MemoryStream resultStream = new MemoryStream(memStream.GetBuffer());
                return(Response.FromStream(resultStream, "application/pdf"));
            };
            Delete["/deleteInvoice/{invoiceId}"] = p =>
            {
                try
                {
                    Guid _id = Guid.Parse(p.invoiceId);
                    this.InvoiceService().Delete(_id, this.CurrentAccount().OwnerId);
                }
                catch (Exception ex)
                {
                    return(Response.AsJson(new { error = true, message = ex.Message }));
                }
                return(Response.AsJson("OK"));
            };
            Get["/SearchInvoice/{key}"] = p =>
            {
                string                       key           = p.key;
                IList <Invoices>             invoices      = new List <Invoices>();
                IEnumerable <InvoiceReports> invoiceReport = this.InvoicesQueryRepository().Search(this.CurrentAccount().OwnerId, new string[] { key });
                foreach (InvoiceReports invoice in invoiceReport)
                {
                    invoices.Add(this.InvoicesRepository().Get(invoice._id, invoice.OwnerId));
                }
                return(Response.AsJson(invoices));
            };
            Post["/UpdateInvoice"] = p =>
            {
                try
                {
                    this.InvoiceService().Update(this.Request.Form.invoice, this.CurrentAccount().OwnerId);
                    return(Response.AsJson(new { error = false }));
                }
                catch (Exception ex)
                {
                    return(Response.AsJson(new { error = true, message = ex.Message }));
                }
            };
            Get["/invoice/{id}"] = p =>
            {
                Guid     invoiceId = p.id;
                Invoices invoice   = this.InvoicesQueryRepository().FindById(invoiceId, this.CurrentAccount().OwnerId);
                return(Response.AsJson(invoice));
            };
            Post["/approveinvoice/{id}"] = p =>
            {
                try
                {
                    Guid invoiceId = p.id;
                    this.InvoiceService().ApproveInvoice(p.id, this.CurrentAccount().OwnerId);
                    return(Response.AsJson(new { error = false }));
                }
                catch (Exception e)
                {
                    return(Response.AsJson(new { error = true, message = e.Message }));
                }
            };

            Get["/InvoiceAutoNumber"] = p =>
            {
                var autoNumber = this.InvoiceAutoNumberGenerator().GetInvoiceAutoNumberConfig(this.CurrentAccount().OwnerId);
                return(Response.AsJson(new { prefix = autoNumber.Prefix, mode = autoNumber.Mode }));
            };
            Post["/SetupInvoiceAutoNumber"] = p =>
            {
                try
                {
                    string Data = this.Request.Form.data;
                    InvoiceAutoNumberConfig config = Newtonsoft.Json.JsonConvert.DeserializeObject <InvoiceAutoNumberConfig>(Data);
                    this.InvoiceAutoNumberGenerator().SetupInvoiceAutoMumber(config.Mode, config.Prefix, this.CurrentAccount().OwnerId);
                    return(Response.AsJson(new { error = false }));
                }
                catch (Exception ex)
                {
                    return(Response.AsJson(new { error = true, message = ex.Message }));
                }
            };

            Post["/cancelinvoice/{id}"] = p =>
            {
                try
                {
                    this.InvoiceService().Cancel(p.id, this.Request.Form.Note, this.CurrentAccount().OwnerId);
                    return(Response.AsJson(new { error = false }));
                }
                catch (Exception e)
                {
                    return(Response.AsJson(new { error = true, message = e.Message }));
                }
            };

            Post["/forcecancelinvoice/{id}"] = p =>
            {
                try
                {
                    this.InvoiceService().ForceCancel(p.id, this.Request.Form.Note, this.CurrentAccount().OwnerId);
                    return(Response.AsJson(new { error = false }));
                }
                catch (Exception e)
                {
                    return(Response.AsJson(new { error = true, message = e.Message }));
                }
            };
        }
Пример #3
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"));
            };
        }
Пример #4
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);
        }