Пример #1
0
        public ActionResult PositionsEdit(long?id)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                List <SelectListItem> CountryOfOrigin = new List <SelectListItem>()
                {
                    new SelectListItem {
                        Value = "PL", Text = "Polska"
                    },
                    new SelectListItem {
                        Value = "DE", Text = "Niemcy"
                    },
                    new SelectListItem {
                        Value = "US", Text = "USA"
                    },
                };

                ViewBag.COODDL = new SelectList(CountryOfOrigin, "Value", "Text");

                List <SelectListItem> HSCode = new List <SelectListItem>()
                {
                    new SelectListItem {
                        Value = "123", Text = "Śrubka"
                    },
                    new SelectListItem {
                        Value = "343", Text = "Układ Scalony"
                    },
                    new SelectListItem {
                        Value = "536", Text = "Drut"
                    },
                };

                ViewBag.HSDDL = new SelectList(HSCode, "Value", "Text");


                SadPositions position = db.SadPositions.Find(id);
                if (position == null)
                {
                    return(HttpNotFound());
                }
                return(View(position));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Пример #2
0
        public ActionResult PositionsEdit(SadPositions position)
        {
            if (ModelState.IsValid)
            {
                position.Rate           /= 100;
                db.Entry(position).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Positionslist", new { id = position.IdSad, idpos = position.Id }));
            }
            List <SelectListItem> CountryOfOrigin = new List <SelectListItem>()
            {
                new SelectListItem {
                    Value = "PL", Text = "Polska"
                },
                new SelectListItem {
                    Value = "DE", Text = "Niemcy"
                },
                new SelectListItem {
                    Value = "US", Text = "USA"
                },
            };

            ViewBag.COODDL = new SelectList(CountryOfOrigin, "Value", "Text");

            List <SelectListItem> HSCode = new List <SelectListItem>()
            {
                new SelectListItem {
                    Value = "123", Text = "Śrubka"
                },
                new SelectListItem {
                    Value = "343", Text = "Układ Scalony"
                },
                new SelectListItem {
                    Value = "536", Text = "Drut"
                },
            };

            ViewBag.HSDDL = new SelectList(HSCode, "Value", "Text");
            return(View(position));
        }
Пример #3
0
        public ActionResult AddInvoice(long[] ids)
        {
            using (var office = new OfficeModel())
            {
                using (DbContextTransaction transaction = office.Database.BeginTransaction())
                {
                    long          sadID = Convert.ToInt32(Session["SelectedIdIS"]);
                    var           sad   = office.SAD.FirstOrDefault(x => x.Id == sadID);
                    StringBuilder sb    = new StringBuilder();
                    if (ids.Any())
                    {
                        foreach (var id in ids)
                        {
                            var positionlist = office.InvoicePosition.Where(x => x.InvoiceId == id);
                            if (positionlist.Any())
                            {
                                foreach (var position in positionlist)
                                {
                                    if (String.IsNullOrEmpty(position.HSCode))
                                    {
                                        transaction.Rollback();
                                        TempData["msg"] = "<script>alert('HS Code jest pusty');</script>";
                                        return(RedirectToAction("SADInvoice", new { id = sadID }));
                                    }
                                    else
                                    {
                                        if (office.SadPositions.Any(x => x.IdSad == sadID))                                                                                                                       //jezeli sad ma jakies pozycje to:
                                        {
                                            List <SadPositions> pos = office.SadPositions.Where(x => x.IdSad == sad.Id && x.HSCode == position.HSCode && x.CountryOfOrigin == position.CountryOfOrigin).ToList(); // sprobuj znaleźć podobne pozycje po kodzie hs i kodzie pochodzenia dla sadu

                                            if (pos.Any())
                                            {
                                                var SADposition = pos.First();
                                                position.TransportsCost   = position.TransportsCost.HasValue ? position.TransportsCost.Value : 0;
                                                SADposition.PositionValue = SADposition.PositionValue + ((position.Price * position.Quantity * sad.ExchangeRate) + position.TransportsCost);
                                                SADposition.DutyValue     = SADposition.DutyValue.HasValue ? SADposition.DutyValue.Value : 0;
                                                if (SADposition.Rate == 0)                                                 // jezeli stawka jest rozna od zera
                                                {
                                                    SADposition.DutyValue = 0;
                                                }
                                                else
                                                {
                                                    SADposition.DutyValue = Math.Round(SADposition.PositionValue.Value * SADposition.Rate);                                                    //to oblicz wart celna na dstwaie stawki i wyliczonej wartosci pozycji
                                                }
                                                if (!office.SAD_Invoice.Any(x => x.ID_SAD == sad.Id && x.ID_SAD_POS == SADposition.Id && x.ID_INV == position.InvoiceId && x.ID_INV_POS == position.Id))
                                                {
                                                    SAD_Invoice pol = new SAD_Invoice();
                                                    pol.ID_SAD     = sad.Id;
                                                    pol.ID_SAD_POS = SADposition.Id;
                                                    pol.ID_INV     = position.InvoiceId;
                                                    pol.ID_INV_POS = position.Id;
                                                    office.SAD_Invoice.Add(pol);
                                                    office.SaveChanges();
                                                }
                                            }
                                            else                                            //dodaj nowa pozycje jeesli nie znaleziono
                                            {
                                                var addPosition = new SadPositions();
                                                addPosition.IdSad           = sad.Id;
                                                addPosition.HSCode          = position.HSCode;
                                                addPosition.CountryOfOrigin = position.CountryOfOrigin;
                                                addPosition.Rate            = 0;

                                                position.TransportsCost   = position.TransportsCost.HasValue ? position.TransportsCost.Value : 0;
                                                addPosition.PositionValue = (position.Price * position.Quantity * sad.ExchangeRate) + position.TransportsCost;
                                                if (addPosition.Rate == 0)                                                 // jezeli stawka jest rozna od zera
                                                {
                                                    addPosition.DutyValue = 0;
                                                }
                                                else
                                                {
                                                    addPosition.DutyValue = Math.Round(addPosition.PositionValue.Value * addPosition.Rate);                                                    //to oblicz wart celna na dstwaie stawki i wyliczonej wartosci pozycji
                                                }
                                                office.SadPositions.Add(addPosition);

                                                office.SaveChanges();



                                                if (!office.SAD_Invoice.Any(x => x.ID_SAD == sad.Id && x.ID_SAD_POS == addPosition.Id && x.ID_INV == position.InvoiceId && x.ID_INV_POS == position.Id))
                                                {
                                                    SAD_Invoice pol = new SAD_Invoice();
                                                    pol.ID_SAD     = sad.Id;
                                                    pol.ID_SAD_POS = addPosition.Id;
                                                    pol.ID_INV     = position.InvoiceId;
                                                    pol.ID_INV_POS = position.Id;
                                                    office.SAD_Invoice.Add(pol);
                                                    office.SaveChanges();
                                                }
                                            }
                                        }
                                        else                                         //jezeli nie ma pozycji to dodaj nowa
                                        {
                                            var addPosition = new SadPositions();
                                            addPosition.IdSad           = sad.Id;
                                            addPosition.HSCode          = position.HSCode;
                                            addPosition.CountryOfOrigin = position.CountryOfOrigin;
                                            addPosition.Rate            = 0;

                                            position.TransportsCost   = position.TransportsCost.HasValue ? position.TransportsCost.Value : 0;
                                            addPosition.PositionValue = (position.Price * position.Quantity * sad.ExchangeRate) + position.TransportsCost;
                                            if (addPosition.Rate == 0)                                             // jezeli stawka jest rozna od zera
                                            {
                                                addPosition.DutyValue = 0;
                                            }
                                            else
                                            {
                                                addPosition.DutyValue = Math.Round(addPosition.PositionValue.Value * addPosition.Rate);                                                //to oblicz wart celna na dstwaie stawki i wyliczonej wartosci pozycji
                                            }
                                            office.SadPositions.Add(addPosition);

                                            office.SaveChanges();



                                            if (!office.SAD_Invoice.Any(x => x.ID_SAD == sad.Id && x.ID_SAD_POS == addPosition.Id && x.ID_INV == position.InvoiceId && x.ID_INV_POS == position.Id))
                                            {
                                                SAD_Invoice pol = new SAD_Invoice();
                                                pol.ID_SAD     = sad.Id;
                                                pol.ID_SAD_POS = addPosition.Id;
                                                pol.ID_INV     = position.InvoiceId;
                                                pol.ID_INV_POS = position.Id;
                                                office.SAD_Invoice.Add(pol);
                                                office.SaveChanges();
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                sb.AppendLine("Faktura o id:" + id + " nie posiada żadnych pozycji - pominięto fakture");
                            }
                        }
                        if (!String.IsNullOrEmpty(sb.ToString()))
                        {
                            TempData["msg"] = "<script>alert('  Dodanie Faktur zakończone sukcesem ! Ostrzeżenia:" + sb.ToString() + "');</script>";
                        }
                        else
                        {
                            TempData["msg"] = "<script>alert('  Dodanie Faktur zakończone sukcesem !');</script>";
                        }

                        office.SaveChanges();
                        transaction.Commit();

                        return(RedirectToAction("SADInvoice"));
                    }
                    else
                    {
                        TempData["msg"] = "<script>alert('Wybierz fakturę do dodania  ');</script>";
                        return(RedirectToAction("SADInvoice"));
                    }
                }
            }
        }