public async Task <IActionResult> OnGet(string reqNo)
        {
            Suppliers = _context.Suppliers.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.Name
            }).ToList();
            WarehouseStock = _context.WarehouseStock.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.StockName
            }).ToList();
            AllSuppliers      = _context.Suppliers.AsNoTracking().ToList();
            AllWarehouseStock = _context.WarehouseStock.AsNoTracking().ToList();
            ApplicationUser   = await _userManager.GetUserAsync(User);

            Requisitions     = _context.Requisitions.AsNoTracking().Where(r => r.ReqNo == reqNo).ToList();
            Supplier         = AllSuppliers.FirstOrDefault(s => s.Id == Requisitions.FirstOrDefault().SupplierId);
            SelectedSupplier = Supplier.Name;
            List <Warehouse> wStock = new List <Warehouse>();

            foreach (var req in Requisitions)
            {
                wStock.Add(AllWarehouseStock.FirstOrDefault(w => w.Id == req.StockId));
            }
            WStock = wStock;
            ReqNo  = reqNo;
            return(Page());
        }
        public async Task <IActionResult> OnPostEditReq()
        {
            Suppliers = _context.Suppliers.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.Name
            }).ToList();
            WarehouseStock = _context.WarehouseStock.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.StockName
            }).ToList();
            AllSuppliers      = _context.Suppliers.AsNoTracking().ToList();
            AllWarehouseStock = _context.WarehouseStock.AsNoTracking().ToList();
            ApplicationUser   = await _userManager.GetUserAsync(User);

            Supplier         = AllSuppliers.FirstOrDefault(s => s.Id == Requisitions.FirstOrDefault().SupplierId);
            SelectedSupplier = Supplier.Name;
            List <Warehouse> wStock = new List <Warehouse>();

            foreach (var req in Requisitions)
            {
                wStock.Add(AllWarehouseStock.FirstOrDefault(w => w.Id == req.StockId));
            }
            WStock = wStock;
            if (await _userManager.IsInRoleAsync(ApplicationUser, "Admin"))
            {
                try
                {
                    CreatePDF(AllSuppliers.FirstOrDefault(s => s.Id == Convert.ToInt32(SelectedSupplier)).Email, ReqNo);
                }
                catch (Exception)
                {
                    _logger.LogError("Error in creating PDF");
                }
                Requisitions = _context.Requisitions.AsNoTracking().Where(r => r.ReqNo == ReqNo).ToList();
                foreach (var req in Requisitions)
                {
                    req.Approved     = "Approved";
                    req.ApprovedDate = DateTime.Now;
                    req.Approver     = ApplicationUser.UserName;

                    _context.Requisitions.Update(req);
                }
                _context.SaveChanges();
                TempData["StatusMessage"] = "Requisition created, approved and sent to supplier.";
            }
            else
            {
                TempData["StatusMessage"] = "Requisition created and waiting approval.";
            }
            return(Redirect("~/WarehousePages/RequisitionIndex"));
        }
        public void CreatePDF(string supplierEmail, string reqNo)
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Landscape,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                Out = Path.Combine(_hostingEnvironment.WebRootPath, reqNo + ".pdf")
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = GetHTMLString(supplierEmail),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(_hostingEnvironment.WebRootPath, "/libs/bootstrap/css", "bootstrap.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            _converter.Convert(pdf);

            // Sending Mail
            List <InternetAddress> toEmailAddresses   = new List <InternetAddress>();
            List <InternetAddress> fromEmailAddresses = new List <InternetAddress>();
            MailboxAddress         toAddress          = new MailboxAddress(supplierEmail);

            toEmailAddresses.Add(toAddress);
            MailboxAddress fromAddress = new MailboxAddress("*****@*****.**");

            fromEmailAddresses.Add(fromAddress);
            EmailMessage emailMessage = new EmailMessage()
            {
                ToAddresses   = toEmailAddresses,
                FromAddresses = fromEmailAddresses,
                Subject       = "New Requisition",
                Content       = string.Format(@"Good Day {0}.{1}Please find attached new Requisition.{2}{3}Best Regards,",
                                              AllSuppliers.FirstOrDefault(s => s.Email == supplierEmail).Name,
                                              Environment.NewLine, Environment.NewLine, Environment.NewLine),
                Attachments = Path.Combine(_hostingEnvironment.WebRootPath, reqNo + ".pdf")
            };

            _emailSender.SendMail(emailMessage);
        }
Example #4
0
        public IActionResult Create(AllSuppliers model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            this.suppliers
            .Add(model.Name,
                 model.IsImporter);
            this.AddLogg(nameof(Create));

            return(this.RedirectToAction(nameof(All)));
        }
        public async Task <IActionResult> OnPostAddItems()
        {
            Suppliers = _context.Suppliers.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.Name
            }).ToList();
            WarehouseStock = _context.WarehouseStock.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.StockName
            }).ToList();
            AllSuppliers      = _context.Suppliers.AsNoTracking().ToList();
            AllWarehouseStock = _context.WarehouseStock.AsNoTracking().ToList();
            Supplier          = AllSuppliers.FirstOrDefault(s => s.Id == Requisitions.FirstOrDefault().SupplierId);
            SelectedSupplier  = Supplier.Name;
            List <Warehouse> wStock = new List <Warehouse>();

            foreach (var req in Requisitions)
            {
                wStock.Add(AllWarehouseStock.FirstOrDefault(w => w.Id == req.StockId));
            }
            WStock = wStock;
            Warehouse warehouseStock = new Warehouse();

            warehouseStock = _context.WarehouseStock.AsNoTracking().AsNoTracking().FirstOrDefault(s => s.Id == Convert.ToInt32(SelectedStock));

            ApplicationUser = await _userManager.GetUserAsync(User);

            Requisition requisition = new Requisition
            {
                StockId      = warehouseStock.Id,
                Quantity     = Quantity,
                Price        = warehouseStock.Price,
                Total        = warehouseStock.Price * Quantity,
                Requester    = ApplicationUser.UserName,
                ReqDate      = DateTime.Now,
                SupplierId   = Convert.ToInt32(SelectedSupplier),
                ReqNo        = ReqNo,
                Approved     = "Waiting Approval",
                ApprovedDate = DateTime.Now
            };
            await _context.Requisitions.AddAsync(requisition);

            await _context.SaveChangesAsync();

            Requisitions = _context.Requisitions.AsNoTracking().Where(r => r.ReqNo == ReqNo).ToList();
            return(Page());
        }
Example #6
0
        public IActionResult Edit(int id, AllSuppliers model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            this.suppliers
            .Edit(id,
                  model.Name,
                  model.IsImporter);
            this.AddLogg(nameof(Edit));


            return(this.RedirectToAction(nameof(All)));
        }
Example #7
0
        private void deleteInvoice_E(object obj)
        {
            if (MessageBox.Show("Are you sure you want to delete the selected Invoice", "Confirm delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                try
                {
                    if (selectedInvoiceId == null || selectedInvoiceId < 0)
                    {
                        return;
                    }
                    if (invoiceFor == "Clients")
                    {
                        ClientInvoice iv = db.ClientInvoices.Find(selectedInvoiceId);

                        db.Clients.Find(CurrentSelectedId).Invoices.Remove(iv);
                        db.ClientInvoices.Remove(iv);

                        AllClients.Where(i => i.ClientId == CurrentSelectedId).First().Invoices.Remove(iv);
                    }

                    else if (invoiceFor == "Suppliers")
                    {
                        SupplierInvoice iv = db.SupplierInvoices.Find(selectedInvoiceId);

                        db.Suppliers.Find(CurrentSelectedId).Invoices.Remove(iv);
                        db.SupplierInvoices.Remove(iv);

                        AllSuppliers.Where(i => i.SupplierId == CurrentSelectedId).First().Invoices.Remove(iv);
                    }


                    db.SaveChanges();
                    refreshCs_E(null);
                    selectedInvoiceId = -1;
                }
                catch
                {
                    MessageBox.Show("Unable to Delete Invoice", "Deletion Failed", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
Example #8
0
        private async void delete_E(object obj)
        {
            try
            {
                if (allSuppliersSelectedId == null || allSuppliersSelectedId < 0)
                {
                    MessageBox.Show("Please select a supplier to delete");
                    return;
                }

                if (MessageBox.Show("Are you sure you want to delete the selected Supplier", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    db.Suppliers.Remove(db.Suppliers.Find(allSuppliersSelectedId));
                    await db.SaveChangesAsync();

                    AllSuppliers.Remove(db.Suppliers.Find(allSuppliersSelectedId));
                    refreshCs_E(null);
                }
            }
            catch
            {
            }
        }
Example #9
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Warehouse = await _context.WarehouseStock.FirstOrDefaultAsync(m => m.Id == id);

            AllSuppliers = _context.Suppliers.ToList();
            Suppliers    = _context.Suppliers.Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.Name
            }).ToList();

            SelectedTag = AllSuppliers.FirstOrDefault(s => s.Id == Warehouse.SupplierId).Id.ToString();

            if (Warehouse == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public string GetHTMLString(string supplierEmail)
        {
            Requisitions = _context.Requisitions.AsNoTracking().ToList();
            var sb = new StringBuilder();

            sb.AppendFormat(@"
                        <html>
                            <head>
                            </head>
                            <body>
                                <div class='header'><h1>Requisition</h1></div>
                                <table class='table'>
                                    <tr>
                                        <td colspan='2' align='right'>{0}</td>
                                    </tr>            
                                    <tr>            
                                        <td>            
                                            <table class='table'>
                                                <tr>
                                                    <th>Requisitioner Info</th>
                                                </tr>
                                                <tr>
                                                    <th>Name</th>
                                                    <td>{1} {2}</td>
                                                </tr>
                                                <tr>
                                                    <th>Phone</th>
                                                    <td>{3}</td>
                                                </tr>
                                                <tr>
                                                    <th>Email</th>
                                                    <td>{4}</td>
                                                </tr>
                                            </table>
                                        </td>
                                        <td>
                                            <table class='table'>
                                                <tr>
                                                    <th>Supplier Info</th>
                                                </tr>
                                                <tr>
                                                    <th>Name</th>
                                                    <td>{5}</td>
                                                </tr>
                                                <tr>
                                                    <th>Phone</th>
                                                    <td>{6}</td>
                                                </tr>
                                                <tr>
                                                    <th>Address</th>
                                                    <td>{7}</td>
                                                </tr>
                                                <tr>
                                                    <th>Email</th>
                                                    <td>{8}</td>
                                                </tr>
                                                <tr>
                                                    <th>Attention</th>
                                                    <td>{9}</td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>                                    
                                    <tr>
                                        <td colspan='2'>
                                            <table class='table'>
                                                <thead>
                                                    <tr>
                                                        <th>Stock Item</th>
                                                        <th>Quantity</th>
                                                        <th>Unit Price</th>
                                                        <th>Total</th>
                                                    </tr>
                                                </thead>
                                                <tbody>", ReqNo, ApplicationUser.FirstName, ApplicationUser.LastName, ApplicationUser.PhoneNumber, ApplicationUser.Email,
                            AllSuppliers.FirstOrDefault(s => s.Email == supplierEmail).Name, AllSuppliers.FirstOrDefault(s => s.Email == supplierEmail).Phone,
                            AllSuppliers.FirstOrDefault(s => s.Email == supplierEmail).Address, AllSuppliers.FirstOrDefault(s => s.Email == supplierEmail).Email, AllSuppliers.FirstOrDefault(s => s.Email == supplierEmail).Contact);

            foreach (var item in Requisitions)
            {
                sb.AppendFormat(@"
                    <tr>
                        <td>{0}</td>
                        <td>{1}</td>
                        <td>{2}</td>
                        <td>{3}</td>
                    </tr>", AllWarehouseStock.FirstOrDefault(w => w.Id == item.StockId).StockName, item.Quantity, item.Price, item.Total);
            }
            sb.Append(@"
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </body>
                        </html>");

            return(sb.ToString());
        }