Exemple #1
0
        public IEnumerable <ProfitForProduct> ViewProfitForProductsBasedOnDuration(IEnumerable <Product> products, Expression <Func <Batch, bool> > predicate = null)
        {
            List <ProfitForProduct> ProfitForProductsList = new List <ProfitForProduct>();

            foreach (var item in products)
            {
                string[] ProfitForProducts = predicate == null?BatchRepo.GetAll(x => x.ProductId == item.Id).Select(x => x.ProfitMargin).ToArray() :
                                                 BatchRepo.GetAll(x => x.ProductId == item.Id).Where(predicate).Select(x => x.ProfitMargin).ToArray();

                double[] ExpectedProfit = new double[ProfitForProducts.Count()];
                double[] ActualProfit   = new double[ProfitForProducts.Count()];


                for (var i = 0; i < ProfitForProducts.Count(); ++i)
                {
                    ExpectedProfit[i] = GetProfitForProduct(ProfitForProducts[i])["Expected"];
                    ActualProfit[i]   = GetProfitForProduct(ProfitForProducts[i])["Actual"];
                }

                double AverageExpectedProfitMargin = ExpectedProfit.Average();
                double AverageActualProfitMargin   = ActualProfit.Average();

                ProfitForProductsList.Add(new ProfitForProduct
                {
                    ProductName    = item.Name,
                    ActualProfit   = AverageActualProfitMargin,
                    ExpectedProfit = AverageExpectedProfitMargin,
                });
            }
            return(ProfitForProductsList);
        }
        public TransactionsForProduct GetTransactionsForProduct(Guid productId, out Dictionary <int, Dictionary <Month, double> > TurnoverPerYear, Expression <Func <Transaction, bool> > TransactionPredicate = null)
        {
            Product Product = ProductRepo.Get(x => x.Id == productId);

            TransactionsForProduct TransactionsRecords = new TransactionsForProduct();

            Batch[] ProductInStoreRecords = BatchRepo.GetAll(x => x.ProductId == productId).ToArray();
            Guid[]  ProductInStoreIds     = ProductInStoreRecords.Select(x => x.Id).ToArray();

            Transaction[] TransactionsForProduct = TransactionPredicate == null?TransactionRepo.GetAll(x => x.Batch.ProductId == productId).OrderBy(x => x.DateOfTransaction).ToArray() : TransactionRepo.GetAll(x => x.Batch.ProductId == productId).Where(TransactionPredicate).OrderBy(x => x.DateOfTransaction).ToArray();

            Dictionary <int, Dictionary <Month, double> > TransactionsPerYear = new Dictionary <int, Dictionary <Month, double> >();

            TransactionsPerYear = GroupTransactionsPerYear(TransactionsForProduct, out TurnoverPerYear);

            if (TransactionsPerYear != null)
            {
                foreach (var item in TransactionsPerYear)
                {
                    int Year = item.Key;
                    Dictionary <Month, double> TransactionsPerMonth = item.Value;
                    TransactionsRecords.TransactionsForProductInYear.Add(new TransactionsForProductInYear()
                    {
                        Year = Year, TransactionsPerMonth = TransactionsPerMonth
                    });
                }
                TransactionsRecords.Product = Product;

                return(TransactionsRecords);
            }

            return(null);
        }
Exemple #3
0
 public FindPicture(MainWindow mainWindow)
 {
     this.mainWindow = mainWindow;
     InitializeComponent();
     batchRepo = mainWindow.controller.GetAllBatches();
     LoadBatch();
 }
Exemple #4
0
        public LossForProduct GetLossForProduct(Guid productId)
        {
            Product        Product     = ProductRepo.Get(x => x.Id == productId);
            LossForProduct LossRecords = new LossForProduct();


            Batch[] ProductInStoreRecords = BatchRepo.GetAll(x => x.ProductId == productId).ToArray();
            Guid[]  ProductInStoreIds     = ProductInStoreRecords.Select(x => x.Id).ToArray();
            Loss[]  LossesForProduct      = LossRepo.GetAll(x => x.Batch.ProductId == productId).OrderBy(x => x.DateOfLoss).ToArray();

            Dictionary <int, Dictionary <Month, double> > LossPerYear = new Dictionary <int, Dictionary <Month, double> >();

            LossPerYear = GroupLossPerYear(LossesForProduct);

            foreach (var item in LossPerYear)
            {
                int Year = item.Key;
                Dictionary <Month, double> LossPerMonth = item.Value;
                LossRecords.LossForProductInYear.Add(new LossForProductInYear()
                {
                    Year = Year, LossPerMonth = LossPerMonth,
                });
            }
            LossRecords.Product = Product;
            return(LossRecords);
        }
Exemple #5
0
        public IEnumerable <Batch> ProductsPast75PercentOfShelfLife()
        {
            List <Batch> ProductsInStoreList = new List <Batch>();

            ProductsInStoreList = BatchRepo.GetAll(x => (x.QuantitySold + x.QuantityAuctioned + x.QuantityDisposedOf) < x.QuantityPurchased).ToList();
            List <Batch> SoonToExpireProductsInList = new List <Batch>();

            foreach (var item in ProductsInStoreList)
            {
                DateTime ManufactureDate = item.ManufactureDate;
                DateTime ExpiryDate      = item.ExpiryDate;

                if (ExpiryDate > DateTime.Now)
                {
                    if (IsProductPast75PercentOfShelfLife(item))
                    {
                        if (ProductToBeAuctionedRepo.GetAll(x => x.BatchId == item.Id).FirstOrDefault() == null &&
                            AuctionRepo.GetAll(x => x.BatchId == item.Id).FirstOrDefault() == null)
                        {
                            ProductToBeAuctionedRepo.Add(new ProductToBeAuctioned()
                            {
                                AuctionPrice             = 0,
                                HasBeenReviewedByManager = false,
                                BatchId = item.Id,
                                //StoreId = new StoreManager().GetStoreId(),
                                DateOfAuction = ReturnAuctionDateUsingPercentageOfShelfLife(80, item),
                            });
                        }

                        SoonToExpireProductsInList.Add(item);
                    }
                }
            }
            return(SoonToExpireProductsInList);
        }
Exemple #6
0
        public ActionResult TransactionSuccessful(string trxref, string reference)
        {
            Transaction Transaction      = new Transaction();
            string      UserId           = LoggedInUser.Id.ToString();
            List <Cart> CartTransactions = CartRepo.GetAll(x => x.CustomerId == UserId).ToList();

            foreach (var item in CartTransactions)
            {
                TransactionRepo.Add(new Transaction()
                {
                    AuctioneeId       = UserId,
                    BatchId           = item.Auction.BatchId,
                    BulkPurchase      = false,
                    DateOfTransaction = DateTime.Now,
                    Quantity          = item.Quantity,
                    TransactionType   = TransactionType.Auction,
                    TotalCost         = item.Auction.AuctionPrice * item.Quantity,
                });

                Batch batch = BatchRepo.Get(x => x.Id == item.Auction.BatchId);
                batch.QuantityAuctioned += item.Quantity;
                BatchRepo.Update(batch);
            }

            Guid[] ids = CartTransactions.Select(x => x.Id).ToArray();

            foreach (var item in ids)
            {
                CartRepo.Delete(item);
            }



            return(View());
        }
Exemple #7
0
 public ActionResult Update(int id)
 {
     ViewBag.Technology   = new SelectList(TechnologyRepo.All(null), "id", "name");
     ViewBag.Trainer      = new SelectList(TrainerRepo.All(null), "id", "name");
     ViewBag.BootcampType = new SelectList(BootcampTypeRepo.All(), "id", "name");
     ViewBag.Room         = new SelectList(RoomRepo.All(), "id", "name");
     return(PartialView("_Update", BatchRepo.Get(id)));
 }
Exemple #8
0
        // Add Participant
        public ActionResult AddParticipant(long id)
        {
            ViewBag.BiodataList = new SelectList(BatchRepo.ListParticipant(), "id", "name");

            ViewBag.IdBatch = id; // mengirim batch id

            return(PartialView("_AddParticipant"));
        }
Exemple #9
0
        public double ProfitForBatch(Guid BatchId, Boolean IsDiscount)
        {
            Batch   Batch              = BatchRepo.Get(x => x.Id == BatchId);
            Product Product            = Batch.Product;
            double  DiscountPercentage = Product.BulkPurchaseDiscountPercent;
            double  ProfitForBatch     = Batch.SellingPrice - Batch.PurchasePrice;

            return(IsDiscount == false? ProfitForBatch : ProfitForBatch - (Batch.SellingPrice * (DiscountPercentage / 100)));
        }
 public NewPictures(Window previousWindow, BatchRepo chosenBatch, int batchNr, int dayNr)
 {
     this.previousWindow = previousWindow;
     this.chosenBatch    = chosenBatch;
     this.batchNr        = batchNr;
     this.dayNr          = dayNr;
     controller          = Controller.ControllerInstance;
     InitializeComponent();
     LoadDataFromFindPicture(chosenBatch);
 }
Exemple #11
0
        public ActionResult AddParticipant(ClazzViewModel model)
        {
            ResponseResult result = BatchRepo.Add(model);

            return(Json(new
            {
                success = result.Success,
                message = result.ErrorMessage,
                entity = result.Entity
            }, JsonRequestBehavior.AllowGet));
        }
Exemple #12
0
        public double ExpectedProfitForBatch(Guid batchId)
        {
            double ExpectedProfit = 0;
            Batch  Batch          = BatchRepo.Get(x => x.Id == batchId);

            if (Batch != null)
            {
                ExpectedProfit = Batch.SellingPrice * Batch.QuantityPurchased - Batch.PurchasePrice * Batch.QuantityPurchased;
            }
            return(ExpectedProfit);
        }
Exemple #13
0
        public ActionResult Edit(BatchViewModel model)
        {
            ResponseResult result = BatchRepo.Update(model);

            return(Json(new
            {
                success = result.Success,
                message = result.ErrorMessage,
                entity = result.Entity
            }, JsonRequestBehavior.AllowGet));
        }
Exemple #14
0
        public ActionResult DeleteParticipant(ClassViewModel model)
        {
            ResponResultViewModel result = BatchRepo.DeletePart(model.id);

            return(Json(new
            {
                success = result.Success,
                message = result.Message,
                entity = result.Entity
            }, JsonRequestBehavior.AllowGet));
        }
Exemple #15
0
        public double CalculateProfitLossForBatch(Guid batchId)
        {
            Batch  Batch         = BatchRepo.Get(x => x.Id == batchId);
            double PurchasePrice = Batch.PurchasePrice;
            double Value         = 0;

            Batch.Transactions.ToList().ForEach(m => {
                Value += ProfitForTransaction(m);
            });

            return(Value);
        }
Exemple #16
0
        private void ViewPictures_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Hidden;
            int       batchNr = int.Parse(cbb_BatchNumber.SelectedItem.ToString());
            int       dayNr   = int.Parse(cbb_DayNumber.SelectedItem.ToString());
            BatchRepo chosen  = GetChosenBatch(batchNr, dayNr);

            chosen.AddPictureDataFromDayId(batchNr, dayNr);
            NewPictures newPictures = new NewPictures(this, chosen, batchNr, dayNr);

            newPictures.Show();
        }
Exemple #17
0
        public ActionResult Update(BatchViewModel model)
        {
            //if (ModelState.IsValid)
            //{
            ResponResultViewModel result = BatchRepo.Update(model);

            return(Json(new
            {
                success = result.Success,
                message = result.Message,
                entity = result.Entity
            }, JsonRequestBehavior.AllowGet));
        }
Exemple #18
0
        private BatchRepo GetChosenBatch(int batchNr, int dayNr)
        {
            BatchRepo chosen = new BatchRepo();

            for (int i = 0; i < batchRepo.Count; i++)
            {
                if (batchRepo.GetBatchNrByIndex(i).Equals(batchNr))
                {
                    chosen.AddItem(batchRepo.GetItem(i));
                    chosen.DeleteAllDaysButChosen(batchNr, dayNr);
                }
            }
            return(chosen);
        }
Exemple #19
0
        // Validalsi Nama Batch Tidak Boleh Sama
        public ActionResult CheckName(string name = "")
        {
            BatchViewModel data   = BatchRepo.CheckName(name);
            ResponseResult result = new ResponseResult();

            if (data.name != null)
            {
                result.Success = false;
            }
            return(Json(new
            {
                success = result.Success
            }, JsonRequestBehavior.AllowGet));
        }
Exemple #20
0
        // Edit
        public ActionResult Edit(long id)
        {
            BatchViewModel model = new BatchViewModel();

            model = BatchRepo.ById(id);

            ViewBag.tanggalmulai   = model.periodFrom?.ToString("yyyy'-'MM'-'dd");
            ViewBag.tanggalselesai = model.periodTo?.ToString("yyyy'-'MM'-'dd");

            ViewBag.roomList         = new SelectList(RoomRepo.All(), "id", "name");
            ViewBag.BootcampTypeList = new SelectList(BootcampTypeRepo.All(), "id", "name");

            ViewBag.technologyList = new SelectList(TechnologyRepo.All(), "id", "name");
            ViewBag.TerainerList   = new SelectList(TrainerRepo.ByTechnology(model.technologyId), "id", "name"); // Mencari Berdasarkan Technologi

            return(PartialView("_Edit", model));
        }
 private void LoadDataFromFindPicture(BatchRepo chosen)
 {
     for (int i = 0; i < chosen.Count; i++)
     {
         RadioButton radioBtn = new RadioButton
         {
             Margin = new Thickness(2, 10, 2, 10),
             Height = 100,
             HorizontalAlignment = HorizontalAlignment.Center,
             VerticalAlignment   = VerticalAlignment.Top,
             Content             = new Image {
                 Source = new BitmapImage(new Uri(chosen.GetPictureLinkByIndex(batchNr, dayNr, i), UriKind.Relative))
             },
             Name = "_" + chosen.GetPictureIdByIndex(batchNr, dayNr, i)
         };
         radioBtn.Checked += this.Radio_CheckedFindPicture;
         WP_mainWrapPanel.Children.Add(radioBtn);
     }
 }
Exemple #22
0
        // Set Up Test List
        public ActionResult SetUpTest(long id)
        {
            ViewBag.IdBatch = id; // mengirim bath id

            List <TestViewModel> data = TestRepo.All("");

            foreach (var item in data)
            {
                BatchTestViewModel btmodel = BatchRepo.Check(id, item.id);
                if (btmodel.batch_id == 0)
                {
                    item.check = true;
                }
                else
                {
                    item.check = false;
                }
            }

            return(PartialView("_SetUpTest", data));
        }
        //MessedUp Code...Logic shouldnt have write actions to database
        public async Task <Transaction> AddSalesTransactionAsync(Transaction model, string agentId)
        {
            Transaction TransactionRecord = model;
            Batch       Batch             = BatchRepo.Get(c => c.Id == model.BatchId);
            Product     Product           = Batch.Product;

            if (TransactionRecord.BulkPurchase)
            {
                TransactionRecord.Quantity *= Product.QuantityPerCarton;
                TransactionRecord.TotalCost = TransactionRecord.Quantity * Batch.SellingPrice * ((100 - Product.BulkPurchaseDiscountPercent) / 100);
            }
            else
            {
                TransactionRecord.TotalCost = TransactionRecord.Quantity * Batch.SellingPrice;
            }
            TransactionRecord.AgentId         = agentId;
            TransactionRecord.TransactionType = TransactionType.Sale;
            Batch.QuantitySold += TransactionRecord.Quantity;

            await BatchRepo.UpdateAsync(Batch);

            return(await TransactionRepo.AddAsync(TransactionRecord));
        }
Exemple #24
0
 // List & Search
 public ActionResult List(string search = "")
 {
     return(PartialView("_List", BatchRepo.All(search)));
 }
Exemple #25
0
 public IEnumerable <Batch> RetrieveProductInStoreRecordsForProduct(Guid productId)
 {
     return(BatchRepo.GetAll(x => x.ProductId == productId));
 }
Exemple #26
0
 public ActionResult IndexClass()
 {
     return(View(BatchRepo.ListParticipant()));
 }
Exemple #27
0
 public ActionResult ListPart()
 {
     return(PartialView("_ListPart", BatchRepo.ListParticipant()));
 }
 public List <Batch> GetBatchesForAllProductsForStore(Guid storeId)
 {
     return(BatchRepo.GetAll(x => x.Product.StoreId == storeId).ToList());
 }
Exemple #29
0
        public ActionResult SearchClass(string code)
        {
            List <ClassViewModel> item = BatchRepo.ListParticipant(code);

            return(PartialView("_ListPart", item));
        }
Exemple #30
0
 public ActionResult List(string search = "")
 {
     ViewBag.BatchName = new SelectList(BatchRepo.All(search), "id", "name");
     return(PartialView("_List", ClazzRepo.BySearch(search)));
 }