Ejemplo n.º 1
0
        private void OnUpdatePurchaseDetails(M.PurchaseOrderDetail detail)
        {
            var detilsInDb = _purchaseOrderDetailRepository.Get(detail.Id);

            var qty = detail.Quantity - detilsInDb.Quantity;


            detilsInDb.Quantity      = detail.Quantity;
            detilsInDb.PurchasePrice = detail.PurchasePrice;
            detilsInDb.SalePrice     = detail.SalePrice;

            _purchaseOrderDetailRepository.Save();

            var productInDb = _productRepository.Get(detail.ProductId);

            productInDb.Quantity     += qty;
            productInDb.SalePrice     = detail.SalePrice > productInDb.SalePrice ? detail.SalePrice : productInDb.SalePrice;
            productInDb.PurchasePrice = detail.PurchasePrice > productInDb.PurchasePrice ? detail.PurchasePrice : productInDb.PurchasePrice;

            _productRepository.Save();


            ///this event is enough to call. Because it will will update the information where it is subscribed
            EA.GetEvent <SubmittedEvent>().Publish();
            EA.GetEvent <Messanger>().Publish("Inventory is being updated");
            //await Dialoger.ShowMessageAsync(this, "Inventory", "Inventory is being updated.", MessageDialogStyle.Affirmative, OkCancelMessageSettings);
        }
Ejemplo n.º 2
0
        private async void Submit()
        {
            var progress = await Dialoger.ShowProgressAsync(this, "Purchase Order", "Please wait. Order is in progress", settings : OkCancelMessageSettings);

            var maxValue = PurchaseOrderListViewModel.Items.Count;

            progress.Minimum = 0;
            progress.Maximum = maxValue;

            var progressValue = 0;
            await Task.Delay(100);

            var purchaseOrder = new M.PurchaseOrder
            {
                SupplierId = SupplierSelectionViewModel.SelectedItem.Id,
                OrderDate  = SupplierSelectionViewModel.OrderDate
            };

            foreach (var item in PurchaseOrderListViewModel.Items)
            {
                var purchasedetail = new M.PurchaseOrderDetail()
                {
                    ProductId     = item.ProductId,
                    PurchasePrice = item.PurchasePrice,
                    SalePrice     = item.SalePrice,
                    Quantity      = item.Quantity,
                };
                purchaseOrder.OrderDetails.Add(purchasedetail);

                var product = _productRepository.Get(purchasedetail.ProductId);

                product.Quantity += purchasedetail.Quantity;

                if (purchasedetail.PurchasePrice > product.PurchasePrice)
                {
                    product.PurchasePrice = purchasedetail.PurchasePrice;
                }

                if (purchasedetail.SalePrice > product.SalePrice)
                {
                    product.SalePrice = purchasedetail.SalePrice;
                }

                _productRepository.Save();

                progressValue++;

                progress.SetProgress(progressValue);
                await Task.Delay(100);
            }

            var supplier = _supplierRepository.Get(purchaseOrder.SupplierId);

            supplier.PurchaseOrders.Add(purchaseOrder);
            _supplierRepository.Save();

            await Task.Delay(100);

            PurchaseOrderListViewModel.Items.Clear();
            PurchaseOrderListViewModel.CalculateTotal();

            EA.GetEvent <SubmittedEvent>().Publish();

            await progress.CloseAsync();

            await Dialoger.ShowMessageAsync(this, "Purchase Order", "Purchase order completed.\nInventory is being updated.", MessageDialogStyle.Affirmative, OkCancelMessageSettings);
        }