Esempio n. 1
0
        public ActionResult RemoveSuppliersMultiple(Array lineitemids, Array supplierids, int rfqId)
        {
            foreach (var lineitemid in lineitemids)
            {
                foreach (var supplierid in supplierids)
                {
                    var id = lineitemid;

                    var supplier = _context.Suppliers.FirstOrDefault(x => x.Id == supplierid.ToString());
                    if (supplier != null)
                    {
                        var lineitemsupplier = new LineItemSupplier
                        {
                            LineItemId   = Convert.ToInt32(id),
                            SupplierId   = supplier.Id,
                            SupplierName = supplier.SupplierName
                        };

                        var lineitemsuppliers = _context.LineItemSuppliers
                                                .Where(x => x.LineItemId == lineitemsupplier.LineItemId)
                                                .FirstOrDefault(x => x.SupplierId == lineitemsupplier.SupplierId);


                        if (lineitemsuppliers != null)
                        {
                            _context.LineItemSuppliers.Remove(lineitemsuppliers);
                            _context.SaveChanges();
                        }
                    }
                }
            }

            return(Json(Url.Action("Index", "TechnicalLineItem", new { id = rfqId })));
        }
Esempio n. 2
0
        public ActionResult Suppliers(LineItemSupplier supplier)
        {
            if (ModelState.IsValid && supplier.SupplierId != null)
            {
                var lineitemsuppliers = _context.LineItemSuppliers.Where(x => x.LineItemId == supplier.LineItemId)
                                        .Where(x => x.SupplierId == supplier.SupplierId).ToList();
                if (lineitemsuppliers.Count == 0)
                {
                    _context.LineItemSuppliers.Add(supplier);
                    _context.SaveChanges();
                }

                return(RedirectToAction("Suppliers", new { id = supplier.LineItemId }));
            }

            var lineitem = _context.LineItems.FirstOrDefault(x => x.Id == supplier.LineItemId);

            return(View(lineitem));
        }
Esempio n. 3
0
        private async Task Createsupplierlineitems(LineItemSupplier lineItemSupplier, int masterid)
        {
            var suplineitem = await
                              _context.SupplierPriceLineItems.Include("OfferMaster").Include("LineItem").FirstOrDefaultAsync(x =>
                                                                                                                             x.LineItemId == lineItemSupplier.LineItemId && x.OfferMasterId == masterid).ConfigureAwait(true);

            if (suplineitem == null)
            {
                //will be added if supplier has price

                var lastpricelist = await _context.SupplierPriceLineItems.Include("OfferMaster").Include("LineItem").Where(l =>
                                                                                                                           l.OfferMaster.SupplierId == lineItemSupplier.SupplierId &&
                                                                                                                           l.LineItem.Impa == lineItemSupplier.LineItem.Impa && l.SupplierPrice != 0).OrderBy(l => l.CreatedDate).Distinct().ToListAsync().ConfigureAwait(true);


                var supplierLineItem = new SupplierPriceLineItem
                {
                    OfferMasterId = masterid,
                    LineItemId    = lineItemSupplier.LineItemId,
                    CreatedDate   = DateTime.Now.Date
                };

                if (lastpricelist.Count > 0)
                {
                    var lastoffer = lastpricelist[0];
                    supplierLineItem.Currency           = lastoffer.Currency;
                    supplierLineItem.Vat                = lastoffer.Vat;
                    supplierLineItem.Comment            = lastoffer.Comment;
                    supplierLineItem.SupplierPrice      = lastoffer.SupplierPrice;
                    supplierLineItem.OldPriceDate       = lastoffer.CreatedDate;
                    supplierLineItem.IsOldPrice         = true;
                    supplierLineItem.TurkishDescription = lastoffer.TurkishDescription;
                }

                _context.SupplierPriceLineItems.Add(supplierLineItem);
                await _context.SaveChangesAsync();
            }
        }
Esempio n. 4
0
        public async Task AddDefinedSuppliers(string impa, int itemid)
        {
            var supkayitlilar = await _context.LineItemSuppliers.Where(x => x.LineItemId == itemid).ToListAsync();

            var supeskiler = await _context.LineItemSuppliers.Where(x => x.LineItem.Impa == impa).GroupBy(x => x.SupplierId)
                             .Select(g => new
            {
                g.FirstOrDefault().SupplierId,
                g.FirstOrDefault().SupplierName
            })
                             .ToListAsync();

            foreach (var item in supeskiler.ToList())
            {
                foreach (var kayitli in supkayitlilar)
                {
                    if (kayitli.SupplierId == item.SupplierId)
                    {
                        supeskiler.Remove(item);
                    }
                }
            }


            foreach (var sup in supeskiler)
            {
                var supplier = new LineItemSupplier
                {
                    LineItemId   = itemid,
                    SupplierId   = sup.SupplierId,
                    SupplierName = sup.SupplierName
                };

                _context.LineItemSuppliers.Add(supplier);
                _context.SaveChanges();
            }
        }
Esempio n. 5
0
        public ActionResult AddNewSupplier(int fileid, int lineitemid, string lineitemimpa, string supplierid, string price, int vat, string currency, string remark)
        {
            try
            {
                var lineitem    = _context.LineItems.FirstOrDefault(l => l.Id == lineitemid);
                int referanceno = lineitem.ReferanceNumberId;

                var sup = _context.Suppliers.FirstOrDefault(s => s.Id == supplierid);


                //check master and add supplier

                var supplier = new LineItemSupplier
                {
                    LineItemId   = lineitemid,
                    SupplierId   = sup.Id,
                    SupplierName = sup.SupplierName
                };

                _context.LineItemSuppliers.Add(supplier);
                _context.SaveChanges();



                int masterid = 0;
                var offerid  = GetStringSha256Hash(fileid + "/-/" + sup.Id);
                var offer    = _context.OfferMasters.FirstOrDefault(x => x.OfferId == offerid);


                //offer master save
                if (offer == null)
                {
                    var offermaster = new OfferMaster
                    {
                        OfferId    = offerid,
                        FileId     = fileid,
                        SupplierId = sup.Id
                    };

                    _context.OfferMasters.Add(offermaster);
                    _context.SaveChanges();

                    masterid = offermaster.Id;
                }
                else
                {
                    masterid = offer.Id;
                }


                // suplineitem
                var supplierLineItem = new SupplierPriceLineItem
                {
                    OfferMasterId = masterid,
                    LineItemId    = supplier.LineItemId,
                    CreatedDate   = DateTime.Now.Date,
                    Vat           = vat,
                    Comment       = remark,
                    SupplierPrice = Convert.ToDecimal(price),
                    Currency      = currency
                };

                _context.SupplierPriceLineItems.Add(supplierLineItem);
                _context.SaveChanges();


                // supplier select
                var lineitemsupplier = _context.ViewSupplierPriceLineItems.Include("OfferMaster").FirstOrDefault(s => s.Id == supplierLineItem.Id);

                if (lineitemsupplier != null)
                {
                    lineitem.SelectedSupplierName            = lineitemsupplier.SupplierName;
                    lineitem.SelectedSupplierCurrency        = lineitemsupplier.Currency;
                    lineitem.SelectedSupplierId              = lineitemsupplier.OfferMaster.SupplierId;
                    lineitem.SelectedSupplierPrice           = lineitemsupplier.SupplierPrice;
                    lineitem.SelectedSupplierRemark          = lineitemsupplier.Comment;
                    lineitem.SelectedSupplierCalculatedPrice = lineitemsupplier.RealPrice;
                    lineitem.IsWareHouseSelected             = false;

                    _context.SaveChanges();
                }


                return(Json(true));
            }
            catch (Exception e)
            {
                return(Json(false));
            }
        }
Esempio n. 6
0
        public async Task AddDefinedSuppliers(string impa, int itemid, int fileid)
        {
            try
            {
                var suppliers = _context.LineItemSuppliers.Where(x => x.LineItem.Impa == impa).GroupBy(x => x.SupplierId)
                                .Select(g => new
                {
                    g.FirstOrDefault().SupplierId,
                    g.FirstOrDefault().SupplierName
                })
                                .ToListAsync();


                foreach (var sup in await suppliers)
                {
                    var supplier = new LineItemSupplier
                    {
                        LineItemId   = itemid,
                        SupplierId   = sup.SupplierId,
                        SupplierName = sup.SupplierName
                    };

                    _context.LineItemSuppliers.Add(supplier);
                    _context.SaveChanges();



                    int masterid = 0;
                    var offerid  = GetStringSha256Hash(fileid + "/-/" + sup.SupplierId);
                    var offer    = _context.OfferMasters.FirstOrDefault(x => x.OfferId == offerid);


                    //offer master save
                    if (offer == null)
                    {
                        var offermaster = new OfferMaster
                        {
                            OfferId    = offerid,
                            FileId     = fileid,
                            SupplierId = sup.SupplierId
                        };

                        masterid = offermaster.Id;
                        _context.OfferMasters.Add(offermaster);
                        _context.SaveChanges();
                    }
                    else
                    {
                        masterid = offer.Id;
                    }


                    // suplineitem


                    var lastpricelist = await _context.SupplierPriceLineItems.Include("OfferMaster").Include("LineItem").Where(l =>
                                                                                                                               l.OfferMaster.SupplierId == supplier.SupplierId &&
                                                                                                                               l.LineItem.Impa == supplier.LineItem.Impa && l.SupplierPrice != 0).OrderBy(l => l.CreatedDate).Distinct().ToListAsync().ConfigureAwait(true);


                    var supplierLineItem = new SupplierPriceLineItem
                    {
                        OfferMasterId = masterid,
                        LineItemId    = supplier.LineItemId,
                        CreatedDate   = DateTime.Now.Date
                    };

                    if (lastpricelist.Count > 0)
                    {
                        var lastoffer = lastpricelist[0];
                        supplierLineItem.Currency      = lastoffer.Currency;
                        supplierLineItem.Vat           = lastoffer.Vat;
                        supplierLineItem.Comment       = lastoffer.Comment;
                        supplierLineItem.SupplierPrice = lastoffer.SupplierPrice;
                        supplierLineItem.OldPriceDate  = lastoffer.CreatedDate;
                        supplierLineItem.IsOldPrice    = true;
                    }

                    _context.SupplierPriceLineItems.Add(supplierLineItem);
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }