Пример #1
0
        public static int Inventory_Movement(Entity.Inventory.Inventory inventory)
        {
            int rowsAffacted = 0;

            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandText = "usp_Inventory_Movement";
                    cmd.CommandType = CommandType.StoredProcedure;
                    foreach (DataRow dr in inventory.InventoryDetails.Rows)
                    {
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@AssetId", dr["AssetId"].ToString());
                        cmd.Parameters.AddWithValue("@AssetLocationId", dr["AssetLocationId"].ToString());
                        cmd.Parameters.AddWithValue("@CustomerId", dr["CustomerId"].ToString());
                        cmd.Parameters.AddWithValue("@SaleChallanId", dr["SaleChallanId"].ToString());
                        cmd.Parameters.AddWithValue("@EmployeeId", dr["EmployeeId"].ToString());

                        if (con.State == ConnectionState.Closed)
                        {
                            con.Open();
                        }
                        rowsAffacted += cmd.ExecuteNonQuery();
                    }
                    con.Close();
                }
            }

            return(rowsAffacted);
        }
Пример #2
0
        public static int Inventory_Save(Entity.Inventory.Inventory inventory)
        {
            int rowsAffacted = 0;

            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandText = "usp_Inventory_Save";
                    cmd.CommandType = CommandType.StoredProcedure;
                    using (DataSet dsInventory = new DataSet())
                    {
                        dsInventory.Tables.Add(inventory.InventoryDetails);
                        cmd.Parameters.AddWithValue("@InventoryDetails", dsInventory.GetXml());
                    }
                    cmd.Parameters.AddWithValue("@Error", string.Empty).Direction = ParameterDirection.InputOutput;

                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    rowsAffacted += cmd.ExecuteNonQuery();
                    con.Close();
                }
            }

            return(rowsAffacted);
        }
Пример #3
0
 private void StockLocation_Delete(Entity.Inventory.Inventory inventory)
 {
     Business.Inventory.StockLocation objStockLocation = new Business.Inventory.StockLocation();
     foreach (DataRow dr in inventory.InventoryDetails.Rows)
     {
         objStockLocation.Delete(Convert.ToInt64(dr["StockLocationId"].ToString()));
     }
 }
Пример #4
0
 private void StockLocationTransaction_Save(Entity.Inventory.Inventory inventory)
 {
     Business.Inventory.StockLocationTransaction objStockLocationTransaction = new Business.Inventory.StockLocationTransaction();
     foreach (DataRow dr in inventory.InventoryDetails.Rows)
     {
         objStockLocationTransaction.Save(new StockLocationTransaction()
         {
             StockLocationId = Convert.ToInt64(dr["StockLocationId"].ToString()),
             EmployeeId      = Convert.ToInt32(HttpContext.Current.User.Identity.Name)
         });
     }
 }
Пример #5
0
 private void StockLocation_Save(Entity.Inventory.Inventory inventory)
 {
     Business.Inventory.StockLocation objStockLocation = new Business.Inventory.StockLocation();
     foreach (DataRow dr in inventory.InventoryDetails.Rows)
     {
         objStockLocation.Save(new StockLocation()
         {
             StockLocationId = Convert.ToInt64(dr["StockLocationId"].ToString()),
             StoreId         = Convert.ToInt32(ddlToStore.SelectedValue)
         });
     }
 }
Пример #6
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (Validation())
                {
                    Entity.Purchase.Purchase        purchase        = new Entity.Purchase.Purchase();
                    Business.Purchase.Purchase      objPurchase     = new Business.Purchase.Purchase();
                    Entity.Purchase.PurchaseDetails purchaseDetails = new Entity.Purchase.PurchaseDetails();
                    Entity.Inventory.Inventory      inventory       = new Entity.Inventory.Inventory();
                    Business.Inventory.Inventory    objInventory    = new Business.Inventory.Inventory();

                    purchase.PurchaseOrderNo = (!string.IsNullOrEmpty(txtPurchaseOrderNo.Text.Trim())) ? txtPurchaseOrderNo.Text.Trim() : string.Empty;
                    purchase.PurchaseDate    = Convert.ToDateTime(txtPurchaseDate.Text.Trim());
                    purchase.VendorId        = Convert.ToInt32(ddlVendor.SelectedValue);
                    purchase.InvoiceNo       = (!string.IsNullOrEmpty(txtInvoiceNo.Text.Trim())) ? txtInvoiceNo.Text.Trim() : string.Empty;
                    purchase.InvoiceDate     = (!string.IsNullOrEmpty(txtInvoiceDate.Text.Trim())) ? Convert.ToDateTime(txtInvoiceDate.Text.Trim()) : DateTime.MinValue;
                    purchase.BillAmount      = (!string.IsNullOrEmpty(txtBillAmount.Text.Trim())) ? Convert.ToDecimal(txtBillAmount.Text.Trim()) : 0;
                    purchase.PaymentAmount   = (!string.IsNullOrEmpty(txtPaymentAmount.Text.Trim())) ? Convert.ToDecimal(txtPaymentAmount.Text.Trim()) : 0;
                    int purchaseId = objPurchase.Purchase_Save(purchase);

                    foreach (DataRow drItem in _ItemsList.Rows)
                    {
                        purchase.PurchaseDetailsCollection.Add(
                            new Entity.Purchase.PurchaseDetails()
                        {
                            PurchaseId = purchaseId,
                            ItemId     = Convert.ToInt32(drItem["ItemIdType"].ToString().Split('|')[0]),
                            ItemType   = Convert.ToInt32(drItem["ItemIdType"].ToString().Split('|')[1]),
                            ItemQty    = (!string.IsNullOrEmpty(drItem["Quantity"].ToString())) ? Convert.ToDecimal(drItem["Quantity"].ToString()) : 0,
                            ItemRate   = (!string.IsNullOrEmpty(drItem["Rate"].ToString())) ? Convert.ToDecimal(drItem["Rate"].ToString()) : 0,
                            Discount   = (!string.IsNullOrEmpty(drItem["Discount"].ToString())) ? Convert.ToDecimal(drItem["Discount"].ToString()) : 0,
                            GST        = (!string.IsNullOrEmpty(drItem["GST"].ToString())) ? Convert.ToDecimal(drItem["GST"].ToString()) : 0,
                            HsnCode    = drItem["HsnCode"].ToString()
                        });
                    }
                    int purchaseDetailsResponse = objPurchase.PurchaseDetails_Save(purchase);

                    if (purchaseDetailsResponse > 0)
                    {
                        using (DataTable dtInventory = new DataTable())
                        {
                            dtInventory.Columns.Add("AssetId");
                            dtInventory.Columns.Add("ItemId");
                            dtInventory.Columns.Add("ItemType");
                            dtInventory.Columns.Add("AssetLocationId");
                            dtInventory.Columns.Add("CustomerId");
                            dtInventory.Columns.Add("SaleChallanId");
                            dtInventory.Columns.Add("EmployeeId");
                            dtInventory.Columns.Add("StoreId");

                            foreach (DataRow drItem in _ItemsList.Rows)
                            {
                                for (int qty = 1; qty <= Convert.ToInt32(drItem["Quantity"]); qty++)
                                {
                                    DataRow drInventoryItem = dtInventory.NewRow();
                                    drInventoryItem["AssetId"]         = Guid.NewGuid().ToString().ToUpper();
                                    drInventoryItem["ItemId"]          = drItem["ItemIdType"].ToString().Split('|')[0];
                                    drInventoryItem["ItemType"]        = drItem["ItemIdType"].ToString().Split('|')[1];
                                    drInventoryItem["AssetLocationId"] = (int)AssetLocation.Store; //Stock In
                                    drInventoryItem["CustomerId"]      = "";
                                    drInventoryItem["SaleChallanId"]   = "";
                                    drInventoryItem["EmployeeId"]      = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                                    drInventoryItem["StoreId"]         = Convert.ToInt32(ddlStore.SelectedValue);
                                    dtInventory.Rows.Add(drInventoryItem);
                                    dtInventory.AcceptChanges();
                                }
                            }

                            inventory.InventoryDetails = dtInventory;
                            int inventoryResponse = objInventory.Inventory_Save(inventory);

                            if (inventoryResponse > 0)
                            {
                                GlobalCache.RemoveAll();
                                ClearMasterControls();
                                ClearItemControls();
                                LoadItemList();
                                Message.IsSuccess = true;
                                Message.Text      = "Purchase Order saved";
                            }
                            else
                            {
                                Message.IsSuccess = false;
                                Message.Text      = "Inventory not saved";
                            }
                        }
                    }
                    else
                    {
                        Message.IsSuccess = false;
                        Message.Text      = "Purchase Order not saved";
                    }
                    Message.Show = true;
                }
            }
            catch (Exception ex)
            {
                ex.WriteException();

                Message.IsSuccess = false;
                Message.Text      = ex.Message;
                Message.Show      = true;
            }
        }
Пример #7
0
 public int Inventory_Movement(Entity.Inventory.Inventory inventory)
 {
     return(DataAccess.Inventory.Inventory.Inventory_Movement(inventory));
 }
Пример #8
0
 public int Inventory_Save(Entity.Inventory.Inventory inventory)
 {
     return(DataAccess.Inventory.Inventory.Inventory_Save(inventory));
 }
Пример #9
0
        private int SaveInventoryDetails(Entity.Inventory.Inventory inventory, Business.Inventory.Inventory objInventory)
        {
            int inventoryResponse = objInventory.Inventory_Movement(inventory);

            return(inventoryResponse);
        }
Пример #10
0
        private Entity.Inventory.Inventory PrepareInventoryDetails(int saleChallanId, Entity.Inventory.Inventory inventory, DataTable dtInventory)
        {
            dtInventory.Columns.Add("AssetId");
            dtInventory.Columns.Add("ItemId");
            dtInventory.Columns.Add("ItemType");
            dtInventory.Columns.Add("AssetLocationId");
            dtInventory.Columns.Add("CustomerId");
            dtInventory.Columns.Add("SaleChallanId");
            dtInventory.Columns.Add("EmployeeId");
            dtInventory.Columns.Add("StockLocationId");

            foreach (DataRow drItem in Business.Common.Context.SelectedSaleAssets.Rows)
            {
                DataRow drInventoryItem = dtInventory.NewRow();
                drInventoryItem["AssetId"]  = drItem["AssetId"].ToString().ToUpper();
                drInventoryItem["ItemId"]   = drItem["ItemId"].ToString();
                drInventoryItem["ItemType"] = drItem["ItemType"].ToString();
                if (ddlChallanType.SelectedValue == "1")
                {
                    drInventoryItem["AssetLocationId"] = (int)AssetLocation.Sale;
                }
                else if (ddlChallanType.SelectedValue == "2")
                {
                    drInventoryItem["AssetLocationId"] = (int)AssetLocation.FOC;
                }
                else if (ddlChallanType.SelectedValue == "3")
                {
                    drInventoryItem["AssetLocationId"] = (int)AssetLocation.Store;
                }
                drInventoryItem["CustomerId"]      = "";
                drInventoryItem["SaleChallanId"]   = saleChallanId;
                drInventoryItem["EmployeeId"]      = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                drInventoryItem["StockLocationId"] = Convert.ToInt64(drItem["StockLocationId"].ToString());
                dtInventory.Rows.Add(drInventoryItem);
                dtInventory.AcceptChanges();
            }

            inventory.InventoryDetails = dtInventory;
            return(inventory);
        }
Пример #11
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (Validation())
                {
                    Entity.Sale.SaleChallan        saleChallan        = new Entity.Sale.SaleChallan();
                    Business.Sale.SaleChallan      objSaleChallan     = new Business.Sale.SaleChallan();
                    Entity.Sale.SaleChallanDetails saleChallanDetails = new Entity.Sale.SaleChallanDetails();
                    Entity.Inventory.Inventory     inventory          = new Entity.Inventory.Inventory();
                    Business.Inventory.Inventory   objInventory       = new Business.Inventory.Inventory();

                    saleChallan.CustomerMasterId = GetCustomerIdByName(txtCustomerName.Text.Trim());
                    saleChallan.Note             = txtNote.Text.Trim();
                    saleChallan.ChallanNo        = (!string.IsNullOrEmpty(txtChallanNo.Text.Trim())) ? txtChallanNo.Text.Trim() : string.Empty;
                    saleChallan.OrderNo          = (!string.IsNullOrEmpty(txtOrderNo.Text.Trim())) ? txtOrderNo.Text.Trim() : string.Empty;
                    saleChallan.OrderDate        = (!string.IsNullOrEmpty(txtOrderDate.Text.Trim())) ? Convert.ToDateTime(txtOrderDate.Text.Trim()) : DateTime.MinValue;
                    saleChallan.ChallanTypeId    = Convert.ToInt32(ddlChallanType.SelectedValue);
                    saleChallan.CreatedBy        = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                    int saleChallanId = objSaleChallan.SaleChallan_Save(saleChallan);

                    int purchaseDetailsResponse = 0;
                    if (saleChallanId > 0)
                    {
                        purchaseDetailsResponse = SaveSaleChallanDetails(saleChallan, objSaleChallan, saleChallanId);
                    }
                    else
                    {
                        throw new Exception("Something went wrong! Sale challan master value not inserted.");
                    }

                    if (purchaseDetailsResponse > 0)
                    {
                        using (DataTable dtInventory = new DataTable())
                        {
                            inventory = PrepareInventoryDetails(saleChallanId, inventory, dtInventory);
                            if (ddlChallanType.SelectedValue == "3")//Stock Transfer
                            {
                                StockLocation_Save(inventory);
                                StockLocationTransaction_Save(inventory);
                                Message.IsSuccess = true;
                                Message.Text      = "Stock transfer successful.";
                            }
                            else
                            {
                                int inventoryResponse = SaveInventoryDetails(inventory, objInventory);
                                StockLocation_Delete(inventory);
                                if (inventoryResponse > 0)
                                {
                                    LoadItemList();
                                    Message.IsSuccess = true;
                                    Message.Text      = "Sale Order saved";
                                }
                                else
                                {
                                    Message.IsSuccess = false;
                                    Message.Text      = "Inventory not saved";
                                }
                            }
                            ClearAllControls();
                        }
                    }
                    else
                    {
                        Message.IsSuccess = false;
                        Message.Text      = "Sale Order not saved";
                    }
                    Message.Show = true;
                }
            }
            catch (Exception ex)
            {
                ex.WriteException();

                Message.IsSuccess = false;
                Message.Text      = ex.Message;
                Message.Show      = true;
            }
        }