예제 #1
0
        public async Task <ActionResult> UpdateViewQA(string search)
        {
            var nhnch     = new NHibernateNonCatalogStore();
            var employees = new NHibernateCompanyStore();
            var category  = new NHibernateCategoryStore();
            var supplier  = new NHibernateISupplierStore();
            IList <NonCatalogItemHeadModel> nonCatalogHeads = null;

            ViewData["Categories"] = await category.GeatAllCategoryAsync();

            ViewData["pageName"]  = "QuoteAnalysisUV";
            ViewData["employees"] = await employees.GetAllEmployeeAsync();

            ViewData["supplier"] = await supplier.GeatAllSupplierAsync();

            ViewData["brand"] = await supplier.GeatAllBrandAsync();

            long id;

            if (search == null)
            {
                nonCatalogHeads = await nhnch.FindLatestNonCatalogHeadAsync(10);
            }
            else if (long.TryParse(search, out id))
            {
                nonCatalogHeads = await nhnch.FindIdNonCatalogHeadListAsync(id);
            }
            else
            {
                nonCatalogHeads = await nhnch.SearchNonCatalogByNameAsync(search);
            }
            return(View(nonCatalogHeads));
        }
        // GET: ItemMaintenance
        public async Task <ActionResult> AddItems()
        {
            var branditems    = new NHibernateItemStore();
            var suppliernames = new NHibernateISupplierStore();

            ViewData["BrandItems"] = await branditems.GetAllBrandNameAsync();

            ViewData["SupplierNames"] = await suppliernames.GeatAllSupplierAsync();

            return(View());
        }
예제 #3
0
        public async Task <ActionResult> QuoteAnalysis()
        {
            var category  = new NHibernateCategoryStore();
            var supplier  = new NHibernateISupplierStore();
            var employees = new NHibernateCompanyStore();

            ViewData["pageName"]   = "QuoteAnalysis";
            ViewData["Categories"] = await category.GeatAllCategoryAsync();

            ViewData["supplier"] = await supplier.GeatAllSupplierAsync();

            ViewData["brand"] = await supplier.GeatAllBrandAsync();

            ViewData["employees"] = await employees.GetAllEmployeeAsync();

            return(View());
        }
        // POST api/<controller>
        public async Task <string> Post(POViewModel value)
        {
            const long PurchaserHead = 6;
            var        nhss          = new NHibernateISupplierStore();
            var        nhcs          = new NHibernateCompanyStore();
            var        nhpos         = new NHibernatePOStore();
            var        nhus          = new NHibernateUserStore();
            var        company       = new NHibernateCompanyStore();
            var        requierDate   = value.RequiredDate < DateTime.UtcNow ? DateTime.UtcNow.AddDays(6) : value.RequiredDate;
            var        user          = await nhus.FindByStampAsync(value.SecurityStamp);

            var requestor = await nhcs.GetEmployeeAsync(value.RequestorId);

            var po = await nhpos.FindPOAByIdAsync(value.Id);

            if (po == null)
            {
                po = new POHeaderModel()
                {
                    Supplier       = await nhss.FindSupplierByIdAsync(value.SupplierId),
                    PaymentTerm    = value.PaymentTerm,
                    Requestor      = requestor,
                    DeliveryAdress = value.DeliveryAdress,
                    Status         = value.Status,
                    RequiredDate   = requierDate,
                    NoteToBuyer    = value.NoteToBuyer,
                    CreatedBy      = user,
                    Amount         = value.Amount,
                    CRC            = requestor.Team.CRC,
                    Lines          = new List <POLinesModel>()
                };
                foreach (var line in value.Lines)
                {
                    var nhps   = new NHibernatePRStore();
                    var poLine = new POLinesModel()
                    {
                        Quantity    = line.Quantity,
                        UOM         = line.UOM,
                        Description = line.Description,
                        UnitPrice   = line.UnitPrice,
                        PRLine      = await nhps.GetPRLineAsync(line.PRLineId),
                        Name        = line.Name,
                        CreatedBy   = user
                    };
                    po.Lines.Add(poLine);
                }
            }
            else
            {
                po.Requestor = await nhcs.GetEmployeeAsync(value.RequestorId);

                po.DeliveryAdress = value.DeliveryAdress;
                po.Amount         = value.Amount;
                for (var i = 0; i < po.Lines.Count; i++)
                {
                    var found = false;
                    var id    = po.Lines.ElementAt(i).Id;
                    foreach (var line in value.Lines)
                    {
                        if (line.Id == id)
                        {
                            found = true;
                            po.Lines.ElementAt(i).Quantity    = line.Quantity;
                            po.Lines.ElementAt(i).UOM         = line.UOM;
                            po.Lines.ElementAt(i).Description = line.Description;
                            po.Lines.ElementAt(i).UnitPrice   = line.UnitPrice;
                            break;
                        }
                    }
                    if (found == false)
                    {
                        po.Lines.ElementAt(i).DeleteTime = DateTime.UtcNow;
                    }
                }
            }
            if (value.Status == StatusType.ForApproval)
            {
                var approver = new POAprovalModel()
                {
                    Approver = await company.GetPositionByIdAsync(PurchaserHead),
                    Status   = StatusType.ForApproval
                };
                po.Approvals = new List <POAprovalModel>();
                po.Approvals.Add(approver);
                var costApprover = company.FindCostApprover(po.Amount);
                if (costApprover.Result != null)
                {
                    var approver2 = new POAprovalModel()
                    {
                        Approver = costApprover.Result.Approver,
                        Status   = StatusType.ForApproval
                    };
                    po.Approvals.Add(approver2);
                }
            }

            try {
                await nhpos.SaveOrUpdatePOHeaderAsync(po);
            } catch (Exception e) {
            }
            return(po.RequisitionNo);
        }
        public async Task <long> Post(NonCatalogViewModel value)
        {
            const long PurchaserHead = 6;

            var nhnch            = new NHibernateNonCatalogStore();
            var user             = new NHibernateUserStore();
            var nnc              = new NHibernateNonCatalogStore();
            var supplierStore    = new NHibernateISupplierStore();
            var subcategoryStore = new NHibernateCategoryStore();
            var company          = new NHibernateCompanyStore();
            var createdby        = await user.FindByStampAsync(value.SecurityStamp);

            var nonCatalog = await nnc.GetNonCatalogAsync(value.Id);

            if (nonCatalog == null)
            {
                nonCatalog = new NonCatalogItemHeadModel();
            }
            nonCatalog.Name        = value.Name;
            nonCatalog.Analysis    = value.Analysis;
            nonCatalog.SubCategory = await subcategoryStore.FindSubCategoryByIdAsync(value.SubCategoryId);

            nonCatalog.Requestor = await company.GetEmployeeAsync(value.RequestorId);

            nonCatalog.CreatedBy = createdby;
            nonCatalog.Approver  = await company.GetPositionByIdAsync(PurchaserHead);

            for (var line = 0; line < nonCatalog.Lines.Count; line++)
            {
                if (!value.Lines.Any(x => x.Id == nonCatalog.Lines.ElementAt(line).Id))
                {
                    nonCatalog.Lines.ElementAt(line).DeleteTime = DateTime.UtcNow;
                }
            }
            foreach (var line in value.Lines)
            {
                if (nonCatalog.Lines.Any(x => x.Id == line.Id) && line.Id != 0)
                {
                    continue;
                }
                var supplier = await supplierStore.FindSupplierByIdAsync(line.SupplierId);

                string tempSupplier = null;
                if (supplier == null)
                {
                    tempSupplier = line.TempSupplier;
                }

                var nonCatalogLine = new NonCatalogItemLinesModel {
                    Selected     = line.Selected,
                    Supplier     = supplier,
                    Price        = line.Price,
                    Description  = line.Description,
                    Quantity     = line.Quantity,
                    UOM          = line.UOM,
                    Discount     = line.Discount,
                    TotalAnount  = line.TotalAnount,
                    Availability = line.Availability,
                    Terms        = line.Terms,
                    Brand        = await supplierStore.FindBrandByIdAsync(line.BrandId),
                    CreatedBy    = createdby,
                    TempSupplier = tempSupplier
                };
                nonCatalog.Lines.Add(nonCatalogLine);
            }
            if (value.Approved)
            {
                nonCatalog.ApprovedBy   = createdby;
                nonCatalog.DateApproved = DateTime.UtcNow;
            }
            return(await nnc.CreateNonCatalogHeadAsync(nonCatalog));
        }