示例#1
0
        private double CalculateItemAmount(bool purchase)
        {
            double amt = 0;

            if (!string.IsNullOrEmpty(txtQuantity.Text) && !string.IsNullOrWhiteSpace(txtQuantity.Text) && !string.IsNullOrEmpty(txtRate.Text))
            {
                double rate     = Convert.ToDouble(txtRate.Text);
                int    quantity = Convert.ToInt32(txtQuantity.Text);
                if (!purchase)
                {
                    amt = (CalculationHelper.AmountRemovingGST(rate)) * quantity;
                }
                else
                {
                    amt = rate * quantity;
                }
            }
            return(amt);
        }
示例#2
0
        private void AddItem()
        {
            try
            {
                Logger.Info("Add item start.");
                var  selectedItem = cmbAddItem.SelectedItem as DropDown;
                bool addNew       = true;
                if (ovlItems.GetItemCount() > 0)
                {
                    var items = ovlItems.Objects.Cast <BillingItemModel>().ToList();
                    var rate  = toggleBilling.Checked ? Convert.ToDouble(txtRate.Text) : CalculationHelper.AmountRemovingGST(Convert.ToDouble(txtRate.Text));

                    items = items.Where(x => x.ProductValue == selectedItem.Value && x.Rate == rate).ToList();
                    if (items.Any())
                    {
                        var existingItem = items.First();
                        existingItem.Quantity += Convert.ToInt32(txtQuantity.Text);
                        existingItem.Total    += CalculationHelper.RoundAmount(CalculateItemAmount(toggleBilling.Checked));
                        addNew = false;
                        ovlItems.UpdateObject(existingItem);
                        Logger.Info(string.Format("Added item {0} in existing entry.", existingItem.ProductName));
                    }
                }

                if (addNew)
                {
                    BillingItemModel salesItem = new BillingItemModel();
                    salesItem.SrNo         = ovlItems.Items.Count + 1;
                    salesItem.ProductName  = selectedItem.Name.ToString();
                    salesItem.Quantity     = Convert.ToInt32(txtQuantity.Text);
                    salesItem.Rate         = toggleBilling.Checked ? Convert.ToDouble(txtRate.Text) : CalculationHelper.AmountRemovingGST(Convert.ToDouble(txtRate.Text));
                    salesItem.Total        = CalculationHelper.RoundAmount(CalculateItemAmount(toggleBilling.Checked));
                    salesItem.ProductValue = selectedItem.Value.ToString();
                    // Add in items list.
                    ovlItems.AddObject(salesItem);
                    Logger.Info(string.Format("Added item {0} in items list.", salesItem.ProductName));
                }
                txtRound.Text = string.Empty;
                Logger.Info("Add item success.");
            }
            catch (Exception ex)
            {
                Logger.Error("Error in add item.");
                throw ex;
            }
        }