Beispiel #1
0
 private async void Nextage_Tapped(object sender, EventArgs e)
 {
     if (PurchaseProducts.Count() == 0)
     {
         await DisplayAlert(AppResources.Alert, AppResources.SelectProduct, AppResources.Ok);
     }
     else
     {
         await Navigation.PushAsync(new PurchaseCheckout(PurchaseProducts, totallbl.Text));
     }
 }
Beispiel #2
0
 private void delete_Clicked(object sender, EventArgs e)
 {
     if (((sender as Button).BindingContext is Product _selectedro))
     {
         _selectedro.total_price = _selectedro.purchase_price * _selectedro.quantity;
         cartnolbl.Text          = (int.Parse(cartnolbl.Text) - _selectedro.quantity).ToString();
         _selectedro.quantity    = 0;
         totallbl.Text           = (double.Parse(totallbl.Text) - _selectedro.total_price).ToString("0.00");
         PurchaseProducts.Remove(_selectedro);
         purchasero.Remove(_selectedro);
         purchasero            = new ObservableCollection <Product>(PurchaseProducts);
         SalesList.ItemsSource = purchasero;
     }
 }
 public void PurchaseProduct(PurchaseProducts product)
 {
     using (var context = new CBContext())
     {
         //if (context.PurchaseProducts.Any(x => x.ProductId == product.ProductId))
         //{
         //    var purchaseRecord= context.PurchaseProducts.Where(x => x.ProductId == product.ProductId).FirstOrDefault();
         //    purchaseRecord.Qty = purchaseRecord.Qty+product.Qty;
         //    context.PurchaseProducts.Attach(purchaseRecord);
         //    context.Entry(purchaseRecord).Property(x => x.Qty).IsModified = true;
         //    context.SaveChanges();
         //}
         context.PurchaseProducts.Add(product);
         context.SaveChanges();
     }
 }
        public PurchaseProducts PostProductItems(PurchaseProducts objPurchaseOrderData)
        {
            PurchaseProducts ObjPurchaseOrder = new PurchaseProducts();

            // int intId = ObjPurchaseOrder.PurchaseProductId;
            try
            {
                //if (intId == 0)
                //{
                ObjPurchaseOrder = objPurchaseProductsBL.PostProductItems(objPurchaseOrderData);
                //}

                return(ObjPurchaseOrder);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #5
0
        public ActionResult SavePurchase(string purchaseItems)
        {
            var result             = JsonConvert.DeserializeObject <List <PurchaseViewModel> >(purchaseItems);
            PurchaseProducts temp  = new PurchaseProducts();
            StockInventry    stock = new StockInventry();
            int transactionId      = PurchaseService.Instance.PurchaseProductMasterMaxID() + 1;

            int totolAmount = 0;

            foreach (var pItems in result)
            {
                //Adding Product data in Purchase with DateWise


                Product p = ProductsService.Instance.GetProductInfo(pItems.ProductID);
                temp.ProductId     = p.Id;
                temp.Qty           = pItems.Quantity;
                temp.Date          = DateTime.Now;
                temp.TotalAmount   = pItems.TotalAmount;
                temp.TransactionId = transactionId;
                temp.BatchNo       = pItems.BatchNo;
                ProductsService.Instance.PurchaseProduct(temp);
                totolAmount = totolAmount + pItems.TotalAmount;
                //Adding Products data in stock
                stock.ProductId   = pItems.ProductID;
                stock.Price       = ProductsService.Instance.ProductPrice(pItems.ProductID);
                stock.Received    = stock.Received + pItems.Quantity;
                stock.Stock       = pItems.Quantity;
                stock.BatchNo     = pItems.BatchNo;
                stock.TotalAmount = stock.TotalAmount + pItems.TotalAmount;

                StockService.Instance.AddStock(stock);
            }
            PurchaseProductsMaster ob = new PurchaseProductsMaster();

            ob.Date          = DateTime.Now;
            ob.CreatedBy     = "Admin";
            ob.TotalAmount   = totolAmount;
            ob.TransactionId = transactionId;
            PurchaseService.Instance.AddTransaction(ob);
            return(Json("Success"));
        }
Beispiel #6
0
        private void ProductsList_FlowItemTapped(object sender, ItemTappedEventArgs e)
        {
            var saleproduct = ProductsList.FlowLastTappedItem as Product;

            saleproduct.total_price = saleproduct.purchase_price * saleproduct.quantity;
            totallbl.Text           = (double.Parse(totallbl.Text) -
                                       double.Parse(saleproduct.total_price.ToString())).ToString("0.00");
            saleproduct.quantity++;
            saleproduct.total_price = saleproduct.purchase_price * saleproduct.quantity;
            if (purchaseproducts.Count() == 0)
            {
                purchaseproducts.Add(saleproduct);

                cartnolbl.Text = (int.Parse(cartnolbl.Text) + 1).ToString();
                totallbl.Text  = (double.Parse(totallbl.Text) +
                                  double.Parse(saleproduct.total_price.ToString())).ToString("0.00");
            }
            else
            {
                var obj = PurchaseProducts.Find(x => x.id == saleproduct.id);
                if (obj != null)
                {
                    cartnolbl.Text = (int.Parse(cartnolbl.Text) + 1).ToString();
                    totallbl.Text  = (double.Parse(totallbl.Text) +
                                      double.Parse(saleproduct.total_price.ToString())).ToString("0.00");
                }
                else
                {
                    cartnolbl.Text = (int.Parse(cartnolbl.Text) + 1).ToString();
                    totallbl.Text  = (double.Parse(totallbl.Text) +
                                      double.Parse(saleproduct.total_price.ToString())).ToString("0.00");
                    PurchaseProducts.Add(saleproduct);
                }
            }
            purchasero            = new ObservableCollection <Product>(PurchaseProducts);
            SalesList.ItemsSource = purchasero;
        }
        public ActionResult <Purchase> PostPurchase(List <PurchaseDTO> purchaseDetail)
        {
            if (!ModelState.IsValid && purchaseDetail != null && purchaseDetail.Count > 0)
            {
                return(BadRequest(new { Message = "Required data missing" }));
            }

            //Check available quantity
            foreach (var item in purchaseDetail)
            {
                //Valid
                if (item.ProductQuantity <= 0)
                {
                    return(BadRequest(new
                    {
                        Message = string.Concat("ProductId <", item.ProductId, "> quantity must be greater  than 0")
                    }));
                }

                if (!_productRepository.CheckQuantityAvailable(item.ProductId, item.ProductQuantity))
                {
                    return(BadRequest(new {
                        Message = string.Concat("ProductId <", item.ProductId, "> unavailable or insufficient  stock")
                    }));
                }
            }
            var userId   = int.Parse(User.Identity.Name);
            var clientId = purchaseDetail.First().ClientId ?? userId;

            var newPurchase = new Purchase();

            newPurchase.ClientId         = clientId;
            newPurchase.NumberOfProducts = purchaseDetail.Count();
            newPurchase.Total            = 0; //Zero by default
            newPurchase.CreatedAt        = DateTime.Now;
            newPurchase.CreatedBy        = userId;

            _purchaseRepository.Create(newPurchase);


            foreach (var item in purchaseDetail)
            {
                var product = _productRepository.GetById(item.ProductId);

                //Create purchase detail
                var newPurchaseProduct = new PurchaseProducts();
                newPurchaseProduct.PurchaseId      = newPurchase.Id;
                newPurchaseProduct.ProductId       = product.Id;
                newPurchaseProduct.ProductQuantity = item.ProductQuantity;
                newPurchaseProduct.Price           = (decimal)product.Price;
                newPurchaseProduct.SubTotal        = decimal.Round((newPurchaseProduct.ProductQuantity * newPurchaseProduct.Price), 2);
                newPurchaseProduct.CreatedBy       = userId;
                newPurchaseProduct.CreatedAt       = DateTime.Now;

                _purchaseProductRepository.Create(newPurchaseProduct);

                //Update total purchase
                newPurchase.Total += newPurchaseProduct.SubTotal;

                //Decrement product stock
                product.Stock    -= newPurchaseProduct.ProductQuantity;
                product.UpdatedAt = DateTime.Now;
                product.UpdatedBy = userId;

                _productRepository.Update(product);
            }
            //Update total purchase
            newPurchase.UpdatedAt = DateTime.Now;
            newPurchase.UpdatedBy = userId;
            _purchaseRepository.Update(newPurchase);

            return(CreatedAtAction("GetPurchase", new { id = newPurchase.Id }, newPurchase));
        }