Esempio n. 1
0
        public ActionResult Edit(Transaction Transaction)
        //[Bind(Include = "TransactionID,CompanyId,TransactionType,TransactionDate,In,Out,ResponsiblePerson,Comment,Active")]
        {
            if (ModelState.IsValid)
            {
                if (Transaction == null | Session["UserID"] == null)
                {
                    return(RedirectToAction("Login", "Login"));
                }
                else
                {
                    if (Transaction.ResponsiblePerson == Prenosna.DajJuzerAjDi(Session["UserID"]))
                    {
                        bool Udri = true;
                        if (Transaction.TransactionType == PrevodSrb.Produkcija)
                        {
                            if (Transaction.Amount > 0)
                            {
                            }
                            else
                            {
                                TempData["msg"] = "Ako upisujete transakciju produkcija, mora da se unese iznos koji je veći od nule";
                                return(RedirectToAction("Index"));
                            }
                        }

                        Transaction.TransactionDate = Prenosna.StariDatum;
                        if (Udri)
                        {
                            db.Entry(Transaction).State = EntityState.Modified;
                        }
                        else
                        {
                            db.Transactions.Add(Transaction);
                        }
                        //   db.Entry(Transaction).State = EntityState.Modified;
                        Prenosna.SnimiDb(db);

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["msg"] = Prenosna.Poruka(PrevodSrb.Ne_mogu_se_menjati_unosi_drugog_korisnika_);
                    }
                }
            }
            ViewBag.ListaSelekta = ListaSelekta;

            //ViewBag.ResponsiblePerson = new SelectList(db.SystemUsers, "UserId", "Nick", Transaction.ResponsiblePerson);

            return(View(Transaction));
        }
Esempio n. 2
0
        public ActionResult Create(Transaction transaction, string selektovanaFirma = "")
        //[Bind(Include = "TransactionID,CompanyId,TransactionType,TransactionDate,In,Out,ResponsiblePerson,Comment,Active")]
        {
            if (ModelState.IsValid)
            {
                try
                {
                    transaction.Active = true;
                    var firstOrDefault = this.db.Companies
                                         .FirstOrDefault(x => x.Active && x.CompanyDescription == selektovanaFirma);
                    if (firstOrDefault
                        != null)
                    {
                        transaction.CompanyId = firstOrDefault.CompanyId;
                    }
                    if (transaction.TransactionType == PrevodSrb.Produkcija)
                    {
                        if (transaction.Amount > 0)
                        {
                            firstOrDefault.UpdatedOn = DateTime.Now;
                        }
                        else
                        {
                            TempData["msg"] = "Ako upisujete transakciju produkcija, mora da se unese iznos koji je veći od nule";
                            return(RedirectToAction("Index"));
                        }
                    }
                    ;

                    transaction.ResponsiblePerson = Prenosna.DajJuzerAjDi(Session["UserID"]);
                    transaction.TransactionDate   = DateTime.Now;

                    db.Transactions.Add(transaction);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    TempData["msg"] = Prenosna.Poruka(PrevodSrb.Niste_ulogovani);
                    return(RedirectToAction("Login", "Login"));
                }
            }

            //ViewBag.ResponsiblePerson = new SelectList(db.Users, "UserId", "Nick", Transaction.ResponsiblePerson);
            return(View(transaction));
        }
Esempio n. 3
0
 public ActionResult DeleteConfirmed(int id)
 {
     if (Session["UserID"] == null)
     {
         TempData["msg"] = Prenosna.Poruka(PrevodSrb.Niste_ulogovani);
         return(RedirectToAction("Index"));
     }
     else
     {
         Transaction Transaction = db.Transactions.Find(id);
         if (Transaction != null && Transaction.ResponsiblePerson == Prenosna.DajJuzerAjDi(Session["UserID"]))
         {
             db.Transactions.Remove(Transaction);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             TempData["msg"] = Prenosna.Poruka(PrevodSrb.Ne_može_se_brisati_unos_drugog_korisnika);
             return(RedirectToAction("Index"));
         }
     }
 }
Esempio n. 4
0
        // GET: PrikazNaplate
        public ActionResult Index(string sortOrder, string selektovanaFirma, string saldo = null, DateTime?saldoDatum = null)
        {
            try
            {
                bool Poz = false;
                if (saldo == ">0")
                {
                    Poz = true;
                }
                else
                {
                    Poz = false;
                }

                var kompanije = this.db.Companies.Include(x => x.Transactions).Where(x => x.Active == true && x.Transactions.Any(y => y.TransactionType == PrevodSrb.Produkcija && y.Amount != 0));
                var firme     = kompanije.AsEnumerable().Where(x => (x.CompanyDescription == selektovanaFirma || selektovanaFirma == "" || selektovanaFirma == null)).OrderByDescending(x => x.UpdatedOn).AsEnumerable();
                if (saldo != null && saldo != "")
                {
                    firme = firme.Where(x => (Poz == true ? Prenosna.RacunajSaldo(x).Value >= 0 : Prenosna.RacunajSaldo(x).Value < 0));
                }
                if (saldoDatum != null)
                {
                    firme = firme.Where(x => Prenosna.RacunajSaldo(x).Key == (DateTime)saldoDatum);
                }
                //if (Rata!= null) { firme = firme.Where(x => x.MonthlyFee = Rata;)}
                ViewBag.Opisi = kompanije.AsEnumerable().Select(x => x.CompanyDescription).Distinct();
                List <string> a = new List <string>();
                a.Add(">0");
                a.Add("<0");
                ViewBag.Saldo = a;
                var b = kompanije.AsEnumerable().Select(x => Prenosna.RacunajSaldo(x).Key).Distinct();
                ViewBag.SaldoDatum        = b;
                ViewBag.SortingSaldo      = String.IsNullOrEmpty(sortOrder) ? "Saldo" : "";
                ViewBag.SortingName       = sortOrder == "Name" ? "Name_Desc" : "Name";
                ViewBag.SortingRata       = sortOrder == "Rata" ? "Rata_Desc" : "Rata";
                ViewBag.SortingSaldoDatum = sortOrder == "SaldoDatum" ? "SaldoDatum_Desc" : "SaldoDatum";
                switch (sortOrder)
                {
                case "Name":
                    firme = firme.OrderBy(stu => stu.CompanyDescription);
                    break;

                case "Name_Desc":
                    firme = firme.OrderByDescending(stu => stu.CompanyDescription);
                    break;

                case "Rata":
                    firme = firme.OrderBy(stu => stu.CompanyDescription);
                    break;

                case "Rata_Desc":
                    firme = firme.OrderByDescending(stu => stu.CompanyDescription);
                    break;

                case "SaldoDatum":
                    firme = firme.OrderBy(stu => Prenosna.RacunajSaldo(stu).Key);
                    break;

                case "SaldoDatum_Desc":
                    firme = firme.OrderByDescending(stu => Prenosna.RacunajSaldo(stu).Key);
                    break;

                case "Saldo":
                    firme = firme.OrderBy(stu => Prenosna.RacunajSaldo(stu).Value);
                    break;

                default:
                    firme = firme.OrderByDescending(stu => Prenosna.RacunajSaldo(stu).Value);
                    break;
                }
                List <Models.PrikazNaplate> Izlaz = new List <Models.PrikazNaplate>();
                foreach (Models.Company x in firme)
                {
                    var z   = Prenosna.RacunajSaldo(x);
                    var rat = Prenosna.RacunajRatu(x);
                    Izlaz.Add(new Models.PrikazNaplate()
                    {
                        Opis = x.CompanyDescription, Rata = rat, FirmaId = x.CompanyId, Saldo = z.Value, SaldoDatum = z.Key, Selected = z.Value < 0 ? true : false, Kolor = z.Value < 0 ? System.Drawing.Color.Red : z.Value == 0? System.Drawing.Color.Black : System.Drawing.Color.Green
                    });
                }
                Izlaz = Izlaz.OrderByDescending(x => x.Saldo).ToList();
                return(View(Izlaz));
            }
            catch { return(null); }
        }
Esempio n. 5
0
        // GET: Transactions/Index
        public ViewResult Index(string sortOrder, string selektovanaFirma = "", string selektovanTip = "", bool aktivni = true, DateTime?datum1 = null, DateTime?datum2 = null, bool In = true, bool Out = true, string iili = "")
        {/**/
            var klijenti = db.Transactions.Include(c => c.SystemUser).Include(c => c.Company).AsEnumerable()
                           .Where(x => x.Active == aktivni).ToList();
            DateTime d1 = DateTime.MinValue;
            DateTime d2 = DateTime.MaxValue;

            if (datum1 == null)
            {
                datum1 = d1;
            }
            if (datum2 == null)
            {
                datum2 = d2;
            }

            var Transactions = klijenti.Where(x => (x.Company.CompanyDescription == selektovanaFirma || selektovanaFirma == "" || selektovanaFirma == null) &&
                                              (x.TransactionType == selektovanTip || selektovanTip == "" ||
                                               selektovanTip == null) &&
                                              x.TransactionDate >= datum1 && x.TransactionDate <= datum2).AsQueryable();

            if (iili != "")
            {
                Transactions = iili == "i" ? Transactions.Where(x => x.Out == Out & x.In == In).AsQueryable() : Transactions.Where(x => x.Out == Out | x.In == In).AsQueryable();
            }
            List <string> listica = new List <string>();

            listica.Add("ili");
            listica.Add("i");
            ViewBag.IIli         = listica.AsEnumerable();
            ViewBag.Opisi        = klijenti.Select(x => x.Company.CompanyDescription).Distinct();
            ViewBag.Tipovi       = Transactions.Select(x => x.TransactionType).Distinct();
            ViewBag.Odgovorni    = Transactions.Select(x => x.ResponsiblePerson).Distinct();
            ViewBag.Datumi       = Transactions.OrderBy(x => x.TransactionDate).Select(x => x.TransactionDate).Distinct();
            ViewBag.Datumi2      = Transactions.OrderBy(x => x.TransactionDate).Select(x => x.TransactionDate).Distinct();
            ViewBag.Inovi        = Prenosna.PretvoriListuBoolUDaNeSelektAjtem(Transactions.Select(x => x.In).Distinct());
            ViewBag.Outovi       = Prenosna.PretvoriListuBoolUDaNeSelektAjtem(Transactions.Select(x => x.Out).Distinct());
            ViewBag.Aktivni      = Prenosna.PretvoriListuBoolUDaNeSelektAjtem(db.Transactions.AsEnumerable().Select(x => x.Active).Distinct());
            ViewBag.ListaSelekta = ListaSelekta;

            ViewBag.SortingDate = String.IsNullOrEmpty(sortOrder) ? "Date" : "";
            //ViewBag.SortingDate = sortOrder == "Date" ? "Date_Desc" : "Date";
            ViewBag.SortingName    = sortOrder == "Name" ? "Name_Desc" : "Name";
            ViewBag.SortingAmount  = sortOrder == "Amount" ? "Amount_Desc" : "Amount";
            ViewBag.SortingContact = sortOrder == "Contact" ? "Contact_Desc" : "Contact";
            ViewBag.SortingType    = sortOrder == "Type" ? "Type_Desc" : "Type";
            ViewBag.SortingTypeDoc = sortOrder == "TypeDoc" ? "TypeDoc_Desc" : "TypeDoc";

            ViewBag.SortingIn  = sortOrder == "In" ? "In_Desc" : "In";
            ViewBag.SortingOut = sortOrder == "Out" ? "Out_Desc" : "Out";

            ViewBag.SortingComment = sortOrder == "Comment" ? "Comment_Desc" : "Comment";
            ViewBag.SortingActive  = sortOrder == "Active" ? "Active_Desc" : "Active";

            ViewBag.SortingNick = sortOrder == "Nick" ? "Nick_Desc" : "Nick";
            switch (sortOrder)
            {
            case "Name_Desc":
                Transactions = Transactions.OrderByDescending(stu => stu.Company.CompanyDescription);
                break;

            case "Name":
                Transactions = Transactions.OrderBy(stu => stu.Company.CompanyDescription);
                break;

            case "Contact_Desc":
                Transactions = Transactions.OrderByDescending(stu => stu.Contact);
                break;

            case "Contact":
                Transactions = Transactions.OrderBy(stu => stu.Contact);
                break;

            case "Amount_Desc":
                Transactions = Transactions.OrderByDescending(stu => stu.Amount);
                break;

            case "Amount":
                Transactions = Transactions.OrderBy(stu => stu.Amount);
                break;

            case "Date":
                Transactions = Transactions.OrderBy(stu => stu.TransactionDate);
                break;

            //case "Date_Desc":
            //    Transactions = Transactions.OrderByDescending(stu => stu.TransactionDate);
            //    break;
            case "Type":
                Transactions = Transactions.OrderBy(stu => stu.TransactionType);
                break;

            case "Type_Desc":
                Transactions = Transactions.OrderByDescending(stu => stu.TransactionType);
                break;

            //case "TypeDoc":
            //    Transactions = Transactions.OrderBy(stu => stu.NumberOfDocTypes);
            //    break;
            //case "TypeDoc_Desc":
            //    Transactions = Transactions.OrderByDescending(stu => stu.NumberOfDocTypes);
            //    break;
            case "Out":
                Transactions = Transactions.OrderBy(stu => stu.Out);
                break;

            case "Out_Desc":
                Transactions = Transactions.OrderByDescending(stu => stu.Out);
                break;

            case "In":
                Transactions = Transactions.OrderBy(stu => stu.In);
                break;

            case "In_Desc":
                Transactions = Transactions.OrderByDescending(stu => stu.In);
                break;

            case "Comment":
                Transactions = Transactions.OrderBy(stu => stu.Comment);
                break;

            case "Comment_Desc":
                Transactions = Transactions.OrderByDescending(stu => stu.Comment);
                break;

            case "Active":
                Transactions = Transactions.OrderBy(stu => stu.Active);
                break;

            case "Active_Desc":
                Transactions = Transactions.OrderByDescending(stu => stu.Active);
                break;

            case "Nick":
                Transactions = Transactions.OrderBy(stu => stu.SystemUser.Nick);
                break;

            case "Nick_Desc":
                Transactions = Transactions.OrderByDescending(stu => stu.SystemUser.Nick);
                break;

            default:
                Transactions = Transactions.OrderByDescending(stu => stu.TransactionDate);
                break;
            }
            return(View(Transactions.ToList()));
        }