Example #1
0
        public ActionResult Edit(int id)
        {
            var discount = _fR.GetWhere <Discount>(s => s.Id == id)?.FirstOrDefault() ?? new Discount();

            if (discount.Id <= 0)
            {
                return(RedirectToAction("Index"));
            }

            return(View("Create", discount));
        }
Example #2
0
        public ActionResult GetVoucher(string date)
        {
            //
            //order date parse useable datetime format
            DateTime voucherDate;

            try
            {
                voucherDate = DateTime.ParseExact(date, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
            }
            catch
            {
                return(Json(new Response {
                    Status = false, Message = "Tarih formatı yanlış Lütfen sayfayı yenileyip tekrar deneyin"
                }, JsonRequestBehavior.AllowGet));
            }
            //
            var order = _fR.GetWhere <Order>(x => (x.VoucherDate - voucherDate.Date).TotalDays == 0 && x.Status && !x.IsDeleted);

            if (order.Count <= 0)
            {
                return(Json(new Response {
                    Status = false, Message = "Aradığnız tarih için belge bulunamadı."
                }, JsonRequestBehavior.AllowGet));
            }

            //
            string directory = Server.MapPath("~/_Voucher");

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            //
            //
            string filePath = Path.Combine(directory, $"{voucherDate:yyyy-MM-dd}.txt");

            //
            try
            {
                // Check if file already exists. If yes, delete it.
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }

                // Create a new file
                using (System.IO.StreamWriter sw = System.IO.File.CreateText(filePath))
                {
                    foreach (var item in order)
                    {
                        //This is example of one line will create in text file
                        //{Platform kodu = TR Farmina}; {satici kodu}; {satici adi}; {belge tarihi} ;Invoice;  {Belge No};{Musteri kodu}; {musteri adi};{vergi no};{ulke kodu}; {bolge}; {posta kodu}; {Sehir}; {adres}; {urun kodu}; {urun barkodu}; {urun ismi}; {adet}; {fiyat}; {indirimin adi};{indirim tutar};{toplam Kdvsiz }; {toplam kdv li};TL;

                        var voucherStartLine = $"{item.PlatformCode};{item.Supplier.Code};{item.Supplier.Name};{item.VoucherDate:yyyy-MM-dd};Invoice;{item.VoucherNumber};{item.Company.CustomerCode};{item.Company.Name};{item.Company.TaxNumber};{item.Company.CountryCode};{item.Company.Region};{item.Company.ZipCode};{item.Company.City};{item.Company.Address};";

                        foreach (var op in item.OrderProducts)
                        {
                            var total = op.Price * op.Quantity;
                            var totalDiscountPrice = 0M;
                            var discountRates      = op.Discount.Split('+').Where(x => int.Parse(x) > 0).Select(s => int.Parse(s));
                            if (discountRates.Count() > 0)
                            {
                                var discountPrice = 0M;
                                foreach (var discount in discountRates)
                                {
                                    discountPrice       = total * discount / 100;
                                    totalDiscountPrice += discountPrice;
                                    total = total - discountPrice;
                                }
                            }
                            //
                            var taxPrice     = total * item.Tax / 100;
                            var totalWithTax = total + taxPrice;
                            //
                            var productLine = $"{op.Product.Code};{op.Product.Barcode};{op.Product.Name};{op.Quantity};{op.Price:0.##};{op.DiscountName};{totalDiscountPrice:0.##};{total:0.##};{totalWithTax:0.##};TL;";
                            //
                            sw.WriteLine("{0}", voucherStartLine + productLine);
                        }
                    }
                }

                return(Json(new Response {
                    Status = true, Message = filePath
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception Ex)
            {
                return(Json(new Response {
                    Status = false, Message = "Tarih formatı yanlış Lütfen sayfayı yenileyip tekrar deneyin"
                }, JsonRequestBehavior.AllowGet));
            }
        }
Example #3
0
 // GET: Product
 public ActionResult Index()
 {
     return(View(_fR.GetWhere <Product>(s => s.Status && !s.IsDeleted).OrderByDescending(o => o.Id)));
 }