예제 #1
0
        private void SaveDataTemp()
        {
            _guid           = Guid.NewGuid().ToString();
            _timer          = new System.Timers.Timer();
            _timer.Interval = 60000;
            _timer.Start();
            _timer.Elapsed += (s, e) =>
            {
                Monitor.Enter(rootLock);
                {
                    log.DebugFormat("Entering timer loop :{0}", _guid);
                    if (_salesDetailsList.Count() < 0 || SelectedCustomer == null)
                    {
                        Monitor.Exit(rootLock);
                        return;
                    }
                    //Save to temp table
                    //IsDirty = true;
                    //var deletedItems =RMSEntitiesHelper.Instance.RMSEntities.SaleTemps.Where(i => _salesDetailsList.Contains(j => j.ProductId != i.ProductId) == true);
                    var saleTempItems = RMSEntitiesHelper.Instance.RMSEntities.SaleTemps.Where(g => g.Guid == _guid);

                    foreach (var delItem in saleTempItems.ToList())
                    {
                        if (!_salesDetailsList.Any(p => p.ProductId == delItem.ProductId && delItem.Guid == _guid))
                        {
                            RMSEntitiesHelper.Instance.RMSEntities.SaleTemps.Remove(delItem);
                        }
                    }

                    foreach (var item in _salesDetailsList.ToList())
                    {
                        var tempItem = RMSEntitiesHelper.Instance.RMSEntities.SaleTemps.FirstOrDefault(st => st.ProductId == item.ProductId && st.Guid == _guid);
                        if (tempItem != null)
                        {
                            tempItem.SaleDate           = _transcationDate;
                            tempItem.CustomerId         = _selectedCustomer == null ? -1 : _selectedCustomer.Id;
                            tempItem.PaymentMode        = SelectedPaymentId.ToString();
                            tempItem.OrderNo            = OrderNo;
                            tempItem.ProductId          = item.ProductId;
                            tempItem.Quantity           = item.Qty.HasValue == false? 0 : item.Qty;
                            tempItem.SellingPrice       = item.SellingPrice;
                            tempItem.DiscountPercentage = item.DiscountPercentage;
                            tempItem.DiscountAmount     = item.DiscountAmount;
                            tempItem.Amount             = item.Amount;
                            tempItem.PriceId            = item.PriceId;
                            continue;
                        }

                        var newSaletemp =
                            new SaleTemp()
                        {
                            Guid               = _guid,
                            SaleDate           = _transcationDate,
                            CustomerId         = _selectedCustomer == null ? -1 : _selectedCustomer.Id,
                            PaymentMode        = SelectedPaymentId.ToString(),
                            OrderNo            = OrderNo,
                            ProductId          = item.ProductId,
                            Quantity           = item.Qty,
                            SellingPrice       = item.SellingPrice,
                            DiscountPercentage = item.DiscountPercentage,
                            DiscountAmount     = item.DiscountAmount,
                            Amount             = item.Amount,
                            PriceId            = item.PriceId
                        };

                        //    RMSEntitiesHelper.Instance.RMSEntities.Entry(newSaletemp).State = System.Data.EntityState.Added;
                        RMSEntitiesHelper.Instance.RMSEntities.SaleTemps.Add(newSaletemp);
                    }

                    RMSEntitiesHelper.Instance.RMSEntities.SaveChanges();
                }
                Monitor.Exit(rootLock);
                log.DebugFormat("Exit timer loop :{0}", _guid);
            };
        }
예제 #2
0
        //private bool IsValid(DependencyObject obj)
        //{
        //    The dependency object is valid if it has no errors and all
        //    of its children (that are dependency objects) are error-free.
        //    return !Validation.QuantityValidationRule.GetHasError(obj) &&
        //    LogicalTreeHelper.GetChildren(obj)
        //    .OfType<DependencyObject>()
        //    .All(IsValid);
        //}

        private void OnSave(object parameter)
        {
            //var result1 = Utility.IsValid(parameter as DependencyObject);

            PanelLoading = true;
            var purchaseSaveTask = System.Threading.Tasks.Task.Run(() =>
            {
                //Monitor.Enter(rootLock);
                //if(_salesDetailsList.Any(s=> s.Qty > s.AvailableStock || ))
                //{
                //    Utility.ShowErrorBox("Quantity can't be more than the available stock");
                //    return;
                //}

                //check if complete amount is paid, else mark it in PaymentDetails table against the customer
                var outstandingBalance = _totalAmount.Value - AmountPaid;
                if (outstandingBalance > 0)
                {
                    //var msg = "Outstanding balance Rs " + outstandingBalance.ToString("N2") + ". Do you want to keep as pending balance amount?";
                    //var result = Utility.ShowMessageBoxWithOptions(msg);

                    //if (result == System.Windows.MessageBoxResult.Cancel) return;

                    //if (result == System.Windows.MessageBoxResult.Yes)
                    //{
                    RMSEntitiesHelper.Instance.RMSEntities.PaymentDetails.Add
                    (
                        new PaymentDetail
                    {
                        BillId     = _billSales.BillId,
                        AmountPaid = AmountPaid,
                        CustomerId = _selectedCustomer.Id
                    }
                    );
                    //}
                    var customer        = RMSEntitiesHelper.Instance.RMSEntities.Customers.FirstOrDefault(c => c.Id == _selectedCustomer.Id);
                    customer.BalanceDue = customer.BalanceDue.HasValue ? customer.BalanceDue.Value + outstandingBalance : outstandingBalance;
                }


                log.DebugFormat("Enter save :{0}", _guid);
                _billSales.CustomerId      = _selectedCustomer.Id;
                _billSales.CustomerOrderNo = OrderNo;
                _billSales.RunningBillNo   = _runningBillNo;
                _billSales.PaymentMode     = SelectedPaymentId.ToString();

                if (_isEditMode)
                {
                    SaveOnEdit();
                    return;
                }

                foreach (var saleDetailItem in _salesDetailsList)
                {
                    if (saleDetailItem.ProductId == 0)
                    {
                        continue;
                    }
                    if (saleDetailItem.Qty == null || saleDetailItem.Qty > saleDetailItem.AvailableStock || saleDetailItem.AvailableStock == 0)
                    {
                        Utility.ShowErrorBox("Selling quantity can't be more than available quantity");
                        return;
                    }
                    var saleDetail          = RMSEntitiesHelper.Instance.RMSEntities.SaleDetails.Create();
                    saleDetail.Discount     = saleDetailItem.Discount;
                    saleDetail.PriceId      = saleDetailItem.PriceId;
                    saleDetail.ProductId    = saleDetailItem.ProductId;
                    saleDetail.Qty          = saleDetailItem.Qty;
                    saleDetail.SellingPrice = saleDetailItem.SellingPrice;
                    saleDetail.BillId       = _billSales.BillId;
                    _billSales.SaleDetails.Add(saleDetail);

                    var stockToReduceColln = RMSEntitiesHelper.Instance.RMSEntities.Stocks.Where(s => s.ProductId == saleDetailItem.ProductId && s.PriceId == saleDetailItem.PriceId);
                    var stock = stockToReduceColln.FirstOrDefault();

                    if (stock != null)
                    {
                        stock.Quantity -= saleDetailItem.Qty.Value;
                    }
                }

                //_totalAmount = _extensions.Calculate(_totalAmount.Value);

                _billSales.TotalAmount = _totalAmount;
                _billSales.Discount    = GetDiscountValue();
                decimal?oldValue;
                _billSales.TransportCharges = _extensions.GetPropertyValue("TransportCharges", out oldValue);


                RMSEntitiesHelper.Instance.RMSEntities.Sales.Add(_billSales);


                RemoveTempSalesItemForGUID(_guid);
                //this is done to get the latest bill no
                RMSEntitiesHelper.Instance.SelectRunningBillNo(_categoryId);
                _billSales.RunningBillNo = _runningBillNo;

                var _category       = RMSEntitiesHelper.Instance.RMSEntities.Categories.FirstOrDefault(c => c.Id == _categoryId);
                _category.RollingNo = _runningBillNo;

                RMSEntitiesHelper.Instance.RMSEntities.SaveChanges();
                //Monitor.Exit(rootLock);
                log.DebugFormat("Exit save :{0}", _guid);

                if (parameter == null)
                {
                    _salesBillPrint.Print(_billSales.Customer.Name, _salesDetailsList.ToList(), _billSales, AmountPaid, BalanceAmount, _showRestrictedCustomer);
                }

                if (_salesParams.GetTemproaryData)
                {
                    _closeCommand.Execute(null);
                }
                Clear();
            }).ContinueWith(
                (t) =>
            {
                PanelLoading = false;
            });
        }
예제 #3
0
        private void SaveInterim()
        {
            if (SelectedCustomer == null)
            {
                Utility.ShowErrorBox("Select a customer to save the items else items will not be saved");
                return;
            }

            var itemsToSave = _salesDetailsList.Take(3).ToList();

            if (itemsToSave.Count() < 3)
            {
                _autoResetEvent.Set();
                return;
            }

            Monitor.Enter(rootLock);
            log.Debug("Enter save :SaveInterim");

            var totalAmount = 0M;

            foreach (var saleDetailItem in itemsToSave)
            {
                if (saleDetailItem.ProductId == 0 || saleDetailItem.Qty == null)
                {
                    continue;
                }
                var saleDetail = new SaleDetail();
                saleDetail.Discount     = saleDetailItem.Discount;
                saleDetail.PriceId      = saleDetailItem.PriceId;
                saleDetail.ProductId    = saleDetailItem.ProductId;
                saleDetail.Qty          = saleDetailItem.Qty;
                saleDetail.SellingPrice = saleDetailItem.SellingPrice;
                saleDetail.BillId       = _billSales.BillId;
                _billSales.SaleDetails.Add(saleDetail);

                var stockToReduceColln = RMSEntitiesHelper.Instance.RMSEntities.Stocks.Where(s => s.ProductId == saleDetailItem.ProductId &&
                                                                                             s.PriceId == saleDetailItem.PriceId);
                var stock = stockToReduceColln.FirstOrDefault();
                if (stock != null)
                {
                    stock.Quantity -= saleDetailItem.Qty.Value;
                }
                totalAmount += saleDetail.Qty.Value * saleDetail.SellingPrice.Value;
            }

            //_totalAmount = _extensions.Calculate(_totalAmount.Value);

            _billSales.TotalAmount = _billSales.TotalAmount == null ? totalAmount : _billSales.TotalAmount + totalAmount;
            //_billSales.TransportCharges = _extensions.GetPropertyValue("TransportCharges");

            if (_billSales.BillId == 0)
            {
                _billSales.CustomerId      = _selectedCustomer.Id;
                _billSales.CustomerOrderNo = OrderNo;
                _billSales.RunningBillNo   = _runningBillNo;
                _billSales.PaymentMode     = SelectedPaymentId.ToString();

                RMSEntitiesHelper.Instance.RMSEntities.Sales.Add(_billSales);
                var _category = RMSEntitiesHelper.Instance.RMSEntities.Categories.FirstOrDefault(c => c.Id == _categoryId);
                _category.RollingNo = _runningBillNo;
                RMSEntitiesHelper.Instance.SelectRunningBillNo(_categoryId);
                _billSales.RunningBillNo = _runningBillNo;
            }

            RMSEntitiesHelper.Instance.RMSEntities.SaveChanges();

            itemsToSave.ForEach
            (
                (s) =>
            {
                App.Current.Dispatcher.Invoke(delegate
                {
                    //var stateBefore = RMSEntitiesHelper.Instance.RMSEntities.Entry<SaleDetail>(s.).State;
                    _salesDetailsList.Remove(s);
                    //var stateAfter = RMSEntitiesHelper.Instance.RMSEntities.Entry<SaleDetail>(s).State;
                });
            }
            );

            if (_salesDetailsList.Count() == 0)
            {
                App.Current.Dispatcher.Invoke(delegate
                {
                    _salesDetailsList.Add(new SaleDetailExtn());
                });
            }

            Monitor.Exit(rootLock);
            log.Debug("Exit SaveIternim");
            _autoResetEvent.Set();
        }
예제 #4
0
        private void OnSave(object parameter)
        {
            if (_isEditMode)
            {
                SaveOnEdit(parameter);
                return;
            }

            PanelLoading = true;
            var purchaseSaveTask = System.Threading.Tasks.Task.Run(() =>
            {
                //Add free items to free items table
                //Sum up the free item to main stock
                var purchase = new Purchase()
                {
                    RunningBillNo      = RunningBillNo,
                    CompanyId          = SelectedCompany.Id,
                    Discount           = GetDiscountValue(),
                    SpecialDiscount    = SpecialDiscountAmount,
                    InvoiceNo          = InvoiceNo,
                    TotalBillAmount    = TotalAmount,
                    TransportCharges   = TransportCharges,
                    CoolieCharges      = CoolieCharges,
                    KCoolieCharges     = KCoolieCharges,
                    LocalCoolieCharges = LocalCoolieCharges,
                    Tax         = TotalTax,
                    PaymentMode = SelectedPaymentId.ToString()
                };

                foreach (var item in _purchaseDetailsList)
                {
                    if (item.Qty == null || item.Qty <= 0)
                    {
                        Utility.ShowErrorBox("Purchase quantity can't be empty or zero");
                        return;

                        //App.Current.Dispatcher.BeginInvoke(
                        //    (Action)(() =>
                        //    {
                        //        Utility.ShowErrorBox("Purchase quantity can't be empty or zero");
                        //    }
                        //    ));
                    }
                    var purchaseDetail         = new PurchaseDetail();
                    purchaseDetail.ProductId   = item.ProductId;
                    purchaseDetail.Discount    = item.Discount;
                    purchaseDetail.ActualPrice = item.PurchasePrice.Value;
                    purchaseDetail.Tax         = item.Tax;

                    var priceDetails = _rmsEntities.PriceDetails.Where(pr => pr.ProductId == item.ProductId &&
                                                                       pr.Price == item.CostPrice &&
                                                                       pr.SellingPrice == item.SellingPrice);
                    var priceId = 0;
                    PriceDetail priceDetailItem = null;
                    if (priceDetails.Any())
                    {
                        //Same item exists. Just update the with new billId
                        priceDetailItem        = priceDetails.FirstOrDefault();
                        priceDetailItem.BillId = item.BillId;
                        priceId = priceDetailItem.PriceId;
                        priceDetailItem.SellingPrice = item.SellingPrice.Value;
                    }
                    else
                    {
                        //New Price, add it to price details list
                        priceDetailItem = new PriceDetail()
                        {
                            BillId       = RunningBillNo,
                            ProductId    = item.ProductId,
                            Price        = item.CostPrice,
                            SellingPrice = item.SellingPrice.Value
                        };
                        _rmsEntities.PriceDetails.Add(priceDetailItem);
                    }

                    var stock = _rmsEntities.Stocks.Where(s => s.ProductId == item.ProductId &&
                                                          s.PriceId == priceId &&
                                                          s.ExpiryDate.CompareTo(item.ExpiryDate.Value) == 0);
                    var qty = item.Qty;
                    if (item.FreeIssue.HasValue)
                    {
                        qty = item.FreeIssue.Value + item.Qty.Value;
                        _rmsEntities.PurchaseFreeDetails.Add(
                            new PurchaseFreeDetail()
                        {
                            ProductId  = item.ProductId,
                            FreeQty    = item.FreeIssue.Value,
                            FreeAmount = item.PurchasePrice * item.FreeIssue.Value
                                         //BillId = RunningBillNo
                        });
                    }
                    if (stock.Any())
                    {
                        stock.FirstOrDefault().Quantity += qty.Value;
                    }
                    else
                    {
                        //Add stock for new price
                        var newStock = new Stock()
                        {
                            //PriceId = priceDetailItem.PriceId,
                            ExpiryDate = item.ExpiryDate.Value,
                            Quantity   = qty.Value,
                            ProductId  = item.ProductId
                        };

                        _rmsEntities.Stocks.Add(newStock);

                        newStock.PriceDetail = priceDetailItem;
                    }

                    purchaseDetail.PurchasedQty = qty;
                    purchaseDetail.PriceId      = priceDetailItem.PriceId;
                    purchaseDetail.PriceDetail  = priceDetailItem;
                    purchase.PurchaseDetails.Add(purchaseDetail);
                }

                //check if complete amount is paid, else mark it in PaymentDetails table against the customer
                var outstandingBalance = _totalAmount.Value - AmountPaid;
                if (outstandingBalance > 0)
                {
                    //var msg = "Outstanding balance Rs " + outstandingBalance + ". Do you want to keep as pending balance amount?";
                    //var result = Utility.ShowMessageBoxWithOptions(msg);
                    //if (result == System.Windows.MessageBoxResult.Yes)
                    //{
                    _rmsEntities.PurchasePaymentDetails.Add
                    (
                        new PurchasePaymentDetail
                    {
                        PurchaseBillId = purchase.BillId,
                        AmountPaid     = AmountPaid,
                        CompanyId      = _selectedCompany.Id
                    }
                    );
                    //}
                    var company       = _rmsEntities.Companies.FirstOrDefault(c => c.Id == SelectedCompany.Id);
                    company.DueAmount = company.DueAmount.HasValue ? company.DueAmount.Value + outstandingBalance : outstandingBalance;
                }

                var _category       = _rmsEntities.Categories.FirstOrDefault(c => c.Id == _categoryId);
                _category.RollingNo = _runningBillNo;

                _rmsEntities.Purchases.Add(purchase);
                _rmsEntities.SaveChanges();

                var currentRunningBillNo = _runningBillNo;

                if (parameter.ToString() == "PrintSave")
                {
                    App.Current.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        //Call the print on print & save
                        PurchaseSummaryViewModel psummVM = new PurchaseSummaryViewModel(_showRestrictedCompanies);
                        psummVM.RunningBillNo = currentRunningBillNo;
                        psummVM.PrintCommand.Execute(null);
                    }));
                }

                RMSEntitiesHelper.Instance.SelectRunningBillNo(_categoryId);
                RunningBillNo = _runningBillNo;

                Clear();
            }).ContinueWith(
                (t) =>
            {
                PanelLoading = false;
            });
        }