コード例 #1
0
        public async Task <ActionResult> Create()
        {
            // var id = SignInManager.UserManager.Users.FirstOrDefault().Id;
            ApplicationUser  loadedUserDetails = (await _userManager.FindByNameAsync(User.Identity.Name.ToString()));
            CreateTaxInvoice cti = new CreateTaxInvoice();

            cti.GSTIDSeller  = loadedUserDetails.GstId;
            cti.NameoFSeller = loadedUserDetails.EntityName;
            cti.DateIssue    = DateTime.Now.ToShortDateString();
            cti.SerialNumber = Guid.NewGuid().ToString();

            return(View(cti));
        }
コード例 #2
0
        public async Task <ActionResult> Create(string itemarray, string NameBuyer, string GSTIDBuyer, string RegisteredMobileNoBuyer, string TotalAmountHidden, string GSTAmountHidden, string DateIssue, string SerialNumber, string NameOfSeller, string GSTIdSeller, string PONO, string emailBuyer)
        {
            int count = 0;

            try
            {
                List <InvoiceItemDetail> itemList = new List <InvoiceItemDetail>();
                JavaScriptSerializer     js       = new JavaScriptSerializer();
                string[] itemsarray         = js.Deserialize <string[]>(js.Deserialize <string>(JsonConvert.SerializeObject(itemarray)));
                int      totalpurchaseItems = itemsarray.Length;
                count++;
                if (itemarray != null)
                {
                    for (int i = 0; i < totalpurchaseItems / 5; i++)
                    {
                        InvoiceItemDetail item = new InvoiceItemDetail();
                        item.Product  = itemsarray[(i * 5) + 0];
                        item.GST      = Convert.ToDouble(itemsarray[(i * 5) + 1]);
                        item.Quantity = Convert.ToDouble(itemsarray[(i * 5) + 2]);
                        item.Rate     = Convert.ToDouble(itemsarray[(i * 5) + 3]);
                        item.Amount   = Convert.ToDouble(itemsarray[(i * 5) + 4]);
                        itemList.Add(item);
                        //item.Amount = Convert.ToInt32(itemsarray[(i * 7) + 5]);
                    }
                }
                count++;
                CreateTaxInvoice taxInvoice = new CreateTaxInvoice();
                taxInvoice.DateIssue      = DateIssue;
                taxInvoice.SerialNumber   = SerialNumber;
                taxInvoice.NameoFSeller   = NameOfSeller;//,string GSTIdSeller
                taxInvoice.GSTIDSeller    = GSTIdSeller;
                taxInvoice.NameBuyer      = NameBuyer;
                taxInvoice.EmailBuyer     = emailBuyer;
                taxInvoice.GSTIdBuyer     = GSTIDBuyer;
                taxInvoice.RegisteNoBuyer = RegisteredMobileNoBuyer;
                taxInvoice.itemDetails    = itemList;
                taxInvoice.MerchantId     = (await _userManager.FindByNameAsync(User.Identity.Name.ToString())).Id;
                taxInvoice.TotalAmount    = Convert.ToDouble(TotalAmountHidden);
                taxInvoice.GSTAmount      = Convert.ToDouble(GSTAmountHidden);
                taxInvoice.TaxStatus      = (int)TaxInvoiceStatus.Created;
                taxInvoice.CreatedOn      = DateTime.Now;
                taxInvoice.PONO           = PONO;
                MongoDbRepository <CreateTaxInvoice> mdr = new MongoDbRepository <CreateTaxInvoice>();
                mdr.Insert(taxInvoice);
                var             path = HttpContext.Request.Host.Value;
                ApplicationUser loadedUserDetails = (await _userManager.FindByNameAsync(User.Identity.Name.ToString()));

                await CreateInvoice.CreateInvoiceWithMailSending(taxInvoice, User.Identity.Name.ToString(), path, loadedUserDetails);

                count++;
            }

            //CreateTaxInvoice cti = new CreateTaxInvoice();
            catch (Exception e)
            {
                var smtp = new SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential("*****@*****.**", "pachikkara")
                };

                using (var message = new MailMessage("*****@*****.**", "*****@*****.**")
                {
                    Subject = "main Loop",
                    Body = count.ToString()
                })
                {
                    smtp.Send(message);
                }
            }
            return(RedirectToAction("Create"));
        }
コード例 #3
0
        public static async Task  CreateInvoiceWithMailSending(CreateTaxInvoice invoice, string fromEmail, string path, ApplicationUser au)
        {
            int counter = 0;

            try
            {
                //var collectionmr = db.GetCollection<MerchantRegistration>("MerchantRegistration");
                // var mr = collectionmr.FindAll().ToList<MerchantRegistration>().FirstOrDefault();
                InvoiceJSON invoicejson = new InvoiceJSON();
                invoicejson.version = "1.0.1118";
                billLists[] billListarray = new billLists[1];
                billLists   billlist      = new billLists();
                billlist.userGstin     = au.GstId;
                billlist.supplyType    = "O";
                billlist.subSupplyType = 1;
                billlist.docType       = "INV";
                billlist.docNo         = "20";
                //Test
                billlist.docDate     = invoice.DateIssue;
                billlist.transType   = 1;
                billlist.fromGstin   = invoice.GSTIDSeller;
                billlist.fromTrdName = invoice.NameoFSeller;
                //T2
                // billlist.fromAddr1 = mr.Address1;
                // billlist.fromAddr2 = mr.Address2;
                // billlist.fromPlace = mr.City;
                billlist.fromStateCode       = 27;
                billlist.actualFromStateCode = 27;
                //T2
                billlist.toGstin           = invoice.GSTIdBuyer;
                billlist.toTrdName         = invoice.NameBuyer;
                billlist.toAddr1           = "1st floor, Jain Complex, opp.Bhoot Nath Mandir, Indra Nagar";
                billlist.toAddr2           = "";
                billlist.toPlace           = "Pune";
                billlist.toStateCode       = 27;
                billlist.actualToStateCode = 27;
                //Test
                billlist.totalValue     = invoice.TotalAmount;// 121.00;
                billlist.cgstValue      = invoice.GSTAmount / 2;
                billlist.sgstValue      = invoice.GSTAmount / 2;
                billlist.igstValue      = 0.00;
                billlist.cessValue      = 0.00;
                billlist.TotNonAdvolVal = 0.00;
                billlist.OthValue       = 0.0000;
                billlist.totInvValue    = invoice.TotalAmount;
                billlist.transMode      = 1;
                billlist.transDistance  = 60;
                counter++;
                billlist.transporterName = "";
                billlist.transporterId   = "";
                billlist.transDocNo      = "";
                billlist.transDocDate    = invoice.DateIssue;
                billlist.vehicleNo       = "";
                billlist.vehicleType     = "R";
                counter++;
                ItemLists[] itemlistarray = new ItemLists[invoice.itemDetails.Count];
                for (int count = 0; count < invoice.itemDetails.Count; count++)
                {
                    ItemLists itemlist = new ItemLists();
                    itemlist.itemNo      = count + 1;
                    itemlist.productName = invoice.itemDetails[count].Product;
                    itemlist.productDesc = invoice.itemDetails[count].Product;
                    itemlist.quantity    = invoice.itemDetails[count].Quantity;
                    //il.qtyUnit = invoice.itemDetails[count].Q;
                    itemlist.qtyUnit       = "Qty";
                    itemlist.taxableAmount = invoice.itemDetails[count].Amount;// (invoice.itemDetails[count].GST / 100) * invoice.itemDetails[count].Amount;
                    itemlist.sgstRate      = Convert.ToInt32(itemlist.taxableAmount / 2);
                    itemlist.cgstRate      = Convert.ToInt32(itemlist.taxableAmount / 2);
                    itemlist.igstRate      = 0;
                    itemlist.cessRate      = 0;
                    itemlist.cessNonAdvol  = 0;
                    itemlistarray[count]   = itemlist;
                }

                billlist.itemList     = itemlistarray;
                billListarray[0]      = billlist;
                invoicejson.billLists = billListarray;
                string json      = JsonConvert.SerializeObject(invoicejson, Formatting.Indented);
                var    menstream = new MemoryStream(Encoding.Default.GetBytes(json));
                // var filePath = Path.GetTempFileName();
                //File.WriteAllBytes(filePath, menstream.ToArray());
                var       stream = new MemoryStream(Encoding.Default.GetBytes(json));
                IFormFile file   = new FormFile(stream, 0, (Encoding.Default.GetBytes(json)).Length, "name", "Invoice.json");

                // var filePath = Path.GetTempFileName();
                var filePath = Path.GetTempFileName();

                using (var streamfile = System.IO.File.Create(filePath))
                {
                    await file.CopyToAsync(streamfile);
                }
                //File.WriteAllBytes(filePath, attachment.Content);

                //using (var streamcreate = System.IO.File.Create(filePath))
                //{

                //}

                //StreamReader streamReader = new StreamReader(new MemoryStream
                //  using (var stream = System.IO.File.Create(filePath))
                {
                    //File.WriteAllBytes(filePath, menstream.ToArray());

                    //await filePath.CopyToAsync(menstream);
                }
                StreamReader streamReader = new StreamReader(filePath);// Server.MapPath("~/FileUpload/" + Path.GetFileName(file.FileName)));
                string       data         = streamReader.ReadToEnd();

                //InvoiceJSON invoiceJSON = JsonConvert.DeserializeObject<InvoiceJSON>(data);
                IpfsClient ipfs   = new IpfsClient("https://ipfs.infura.io:5001");
                var        result = ipfs.FileSystem.AddFileAsync(filePath).Result;
                var        url    = "https://ipfs.io/ipfs/" + result.Id.Hash.ToString() + "?filename=" + "Invoice.json";

                MongoDbRepository <MailInvoice> mdr = new MongoDbRepository <MailInvoice>();

                MailInvoice mi = new MailInvoice();
                mi.invoiceJSON             = invoicejson;
                mi.FromEmail               = fromEmail;
                mi.ToEmail                 = invoice.EmailBuyer;
                mi.InvoiceStatus           = MailInvoiceStatus.Created;
                mi.mailInvoiceCreationType = MailInvoiceCreationType.Created;
                mi.HashUrl                 = url;
                // mi.Hash = Hash;
                mdr.Insert(mi);
                var id = mi.Id.ToString();

                var fromAddress = new MailAddress("*****@*****.**", "From Name");
                var toAddress   = new MailAddress(invoice.EmailBuyer, "To Name");
                counter++;
                const string fromPassword = "******";
                const string subject      = "Invoice";
                ///const string body = "Body";
                Attachment attachment = new Attachment(menstream, new ContentType("application/json"));


                attachment.ContentDisposition.FileName = "Invoice.json";

                // attachment.ContentType= "application/json";

                //mailMessage.Attachments.Add(attachment);
                string authorityAccept = "http://" + path + "/TaxInvoice/Accept?id=" + id;
                string authorityReject = "http://" + path + "/TaxInvoice/Reject?id=" + id;
                //string a1= "<html>You have received an Invoice. Please do check the invoice and conform <a href=\'";


                var html = "<html> You have received an Invoice. Please do check the invoice and conform<br /><a href='" + authorityAccept + "' style= \"background-color: #90EE90\" > Accept </a>&nbsp &nbsp<a href='" + authorityReject + "' style= \"background-color: #FFFF00\" > Reject </a></ html >";


                var smtp = new SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                };
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = html,
                    IsBodyHtml = true
                })

                {
                    message.Attachments.Add(attachment);
                    smtp.Send(message);
                }
                // return invoicejson;
            }
            catch (Exception e)
            {
                // return invoicejson;
            }
        }