コード例 #1
0
ファイル: CInventory.cs プロジェクト: centhacker/RetailSystem
        public int Update(Models.MInventory model)
        {
            Common.Logger l         = new Common.Logger();
            string        ClassName = "CInventory";

            try
            {
                var query = from o in obj.Inventories where Convert.ToString(o.id) == Convert.ToString(model.id) select o;

                foreach (var item in query)
                {
                    item.ProductId    = int.Parse(model.ProductId);
                    item.WareHouseId  = int.Parse(model.WareHouseld);
                    item.Cost         = model.Cost;
                    item.Quantity     = model.Quantity;
                    item.FiscalYearId = int.Parse(model.FiscalYearld);
                }
                l.Print(ClassName, Common.LogPointer.Info.ToString(), "Model Values id[" + model.id + "] ProductId[" + model.ProductId + "] WareHouseId[" + model.WareHouseld + "] Cost[" + model.Cost + "] Quantity[ " + model.Cost + "] FiscalYearId[ " + model.FiscalYearld + " ] ");
                obj.SubmitChanges();
                l.Print(ClassName, Common.LogPointer.Info.ToString(), "Record Updated Successfully");
                return(1);
            }
            catch (Exception ex)
            {
                l.Print(ClassName, Common.LogPointer.Error.ToString(), ex.ToString());
                return(-1);
            }
        }
コード例 #2
0
ファイル: CInventory.cs プロジェクト: centhacker/RetailSystem
        public List <Models.MInventory> GetInventoryData()
        {
            List <Models.MInventory> Data = new List <Models.MInventory>();
            var query = from o in obj.Inventories orderby o.WareHouseId ascending select o;

            if (query != null)
            {
                foreach (var item in query)
                {
                    Models.MInventory  mi            = new Models.MInventory();
                    string             Get           = string.Empty;
                    string             WareHouseName = string.Empty;
                    Classes.CProducts  cp            = new CProducts();
                    Classes.CWareHouse cw            = new CWareHouse();
                    Get           = cp.GetProductNameWithTagsById(Convert.ToInt32(item.ProductId));
                    WareHouseName = cw.GetWareHouseNameById(Convert.ToInt32(item.WareHouseId));
                    string[] ProductDetails = Get.Split('-');
                    mi.ProductCode   = ProductDetails[0];
                    mi.ProductName   = ProductDetails[1];
                    mi.ProducyTag1   = ProductDetails[2];
                    mi.ProductTag2   = ProductDetails[3];
                    mi.ProductId     = item.ProductId.ToString();
                    mi.WareHouseld   = item.WareHouseId.ToString();
                    mi.WareHouseName = WareHouseName;
                    mi.Cost          = item.Cost;
                    mi.Quantity      = item.Quantity;
                    mi.TotalCost     = Convert.ToSingle(Convert.ToSingle(item.Cost) * Convert.ToSingle(item.Quantity));
                    Data.Add(mi);
                }
            }


            return(Data);
        }
コード例 #3
0
ファイル: CInventory.cs プロジェクト: centhacker/RetailSystem
        public List <Models.MInventory> GetAllbyid(int id)
        {
            List <Models.MInventory> model = new List <Models.MInventory>();
            var query = from o in obj.Inventories where Convert.ToString(o.id) == Convert.ToString(id) select o;

            foreach (var item in query)
            {
                Models.MInventory m = new Models.MInventory();
                m.id           = Convert.ToString(item.id);
                m.ProductId    = Convert.ToString(item.ProductId);
                m.WareHouseld  = Convert.ToString(item.WareHouseId);
                m.Cost         = item.Cost;
                m.Quantity     = item.Quantity;
                m.FiscalYearld = Convert.ToString(item.FiscalYearId);
                model.Add(m);
            }

            return(model);
        }
コード例 #4
0
        private void ParseAndBindList(string ProductsId, string WareHouseid)
        {
            List <Models.MInventory> DataToBind = new List <Models.MInventory>();

            InventoryData = (List <Models.MInventory>)HttpContext.Current.Cache["InventoryData"];
            var query = from o in InventoryData select o;

            if (InventoryData.Count > 0)
            {
                if (ProductsId != "-1")
                {
                    InventoryData = (from o in InventoryData
                                     where o.ProductId == ProductsId
                                     select o).ToList();
                }
                if (WareHouseid != "-1")
                {
                    InventoryData = (from o in InventoryData
                                     where o.WareHouseld == WareHouseid
                                     select o).ToList();
                }

                foreach (var item in InventoryData)
                {
                    Models.MInventory mi = new Models.MInventory();
                    mi.ProductId     = item.ProductId;
                    mi.WareHouseName = item.WareHouseName;
                    mi.ProductCode   = item.ProductCode;
                    mi.ProductName   = item.ProductName;
                    mi.Quantity      = item.Quantity;
                    mi.Cost          = item.Cost;
                    mi.TotalCost     = item.TotalCost;
                    DataToBind.Add(mi);
                }

                repInventory.DataSource = DataToBind;
                repInventory.DataBind();
            }
        }
コード例 #5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //Saving Journal
            try
            {
                #region Objects
                Classes.CBankOfAccount      cab  = new Classes.CBankOfAccount();
                Classes.CAccountTransaction cat  = new Classes.CAccountTransaction();
                Classes.CSaleTransations    ct   = new Classes.CSaleTransations();
                Classes.CDefaultAccount     df   = new Classes.CDefaultAccount();
                Classes.CInventory          ci   = new Classes.CInventory();
                Classes.CPayment            cpay = new Classes.CPayment();
                Classes.CPaymentLine        cpl  = new Classes.CPaymentLine();
                Classes.CPaymentContainer   cpc  = new Classes.CPaymentContainer();
                Models.MInventory           mi   = new Models.MInventory();
                Models.MAccountTransaction  mat  = new Models.MAccountTransaction();
                Models.MSaleTransactions    ms   = new Models.MSaleTransactions();
                Models.MPayments            mpay = new Models.MPayments();
                Models.PaymentContainer     mpc  = new Models.PaymentContainer();
                Models.PaymentLine          mpl  = new Models.PaymentLine();
                #endregion


                string WareHouseId = ddlWareHouse.SelectedValue;
                string ClientId    = ddlClient.SelectedValue;
                float  Discount    = Convert.ToSingle(txtDiscount.Text);
                Discount = Discount / grdSales.Rows.Count;
                bool[] Result = new bool[grdSales.Rows.Count];
                if (Convert.ToInt32(WareHouseId) > 0)
                {
                    if (Convert.ToInt32(ClientId) > 0)
                    {
                        #region Start Saving


                        for (int i = 0; i < grdSales.Rows.Count; i++)
                        {
                            DropDownList ddlProduct = (DropDownList)grdSales.Rows[i].FindControl("ddlProducts");
                            Label        txtCp      = (Label)grdSales.Rows[i].FindControl("txtCp");
                            TextBox      txtSp      = (TextBox)grdSales.Rows[i].FindControl("txtSp");
                            TextBox      txtUnits   = (TextBox)grdSales.Rows[i].FindControl("txtUnits");
                            TextBox      txtTotal   = (TextBox)grdSales.Rows[i].FindControl("txtTotal");
                            string       ProductId  = ddlProduct.SelectedValue;
                            string       CostPrice  = txtCp.Text;
                            string       SalePrice  = txtSp.Text;
                            string       TotalUnits = txtUnits.Text;
                            string       totalCost  = (Convert.ToInt32(TotalUnits) * Convert.ToInt32(SalePrice)).ToString();
                            totalCost    = Convert.ToSingle(Convert.ToSingle(totalCost) - Discount).ToString();
                            ms.ProductID = ProductId;

                            ms.CostPrice       = CostPrice;
                            ms.SalePrice       = SalePrice.ToString();
                            ms.units           = TotalUnits;
                            ms.clientID        = ClientId;
                            ms.VendorID        = "-1";
                            ms.date            = Convert.ToDateTime(txtDate.Text);
                            ms.transactionType = Common.Constants.SaleTransactions.Deduction.ToString();
                            ms.date            = Convert.ToDateTime(txtDate.Text);
                            ms.OrderId         = "-1";
                            ms.WareHouseId     = WareHouseId;
                            ms.Discount        = Discount.ToString();
                            //sale transaction
                            if (ct.Save(ms) > 0)
                            {
                                mi.WareHouseld  = WareHouseId;
                                mi.Cost         = CostPrice;
                                mi.Quantity     = TotalUnits;
                                mi.ProductId    = ProductId;
                                mi.FiscalYearld = Session["FiscalYear"].ToString();;
                                mi.Date         = Convert.ToDateTime(txtDate.Text);

                                //inventory
                                int retVal = ci.Save(mi, Common.Constants.SaleTransactions.Deduction);
                                if (retVal > 0)
                                {
                                    #region Accounts Transactions
                                    //Payments

                                    int TransactionId = 0;
                                    TransactionId = ct.GetLastTransactionId();
                                    if (TransactionId != 0)
                                    {
                                        string AccountId = string.Empty;
                                        AccountId       = df.ReturnSaleDefaultAccount(Convert.ToInt32(Session["WareHouse"])).ToString();
                                        mat.AccountId   = AccountId;
                                        mat.Debit       = "0";
                                        mat.Credit      = totalCost;
                                        mat.Description = "Purchased Product[" + ddlProduct.SelectedItem.Text + "] Units ["
                                                          + TotalUnits + " At Cost/Unit[" + CostPrice + "]] ";
                                        float AccountTotal = cab.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                                        AccountTotal           = AccountTotal + Convert.ToSingle(totalCost);
                                        mat.Total              = AccountTotal.ToString();
                                        mat.CurrentTransaction = TransactionId.ToString();
                                        mat.Transactiontype    = "Credit";
                                        mat.FiscalYearId       = Session["FiscalYear"].ToString();
                                        mat.eDate              = Convert.ToDateTime(txtDate.Text);
                                        //Account Transation
                                        if (cat.Save(mat) > 0)
                                        {
                                            //Updating Account total
                                            if (cab.SetNewAccountTotal(Convert.ToInt32(AccountId), AccountTotal) > 0)
                                            {
                                                //Updating Payments
                                                mpay.ClientId      = Convert.ToInt32(ClientId);
                                                mpay.VendorId      = 0;
                                                mpay.OrderId       = 0;
                                                mpay.TransactionId = TransactionId;
                                                mpay.Paid          = totalCost;
                                                mpay.TotalCost     = totalCost;
                                                mpay.PaymentType   = Common.Constants.PaymentTypes.Full.ToString();
                                                mpay.Paymentstate  = Common.Constants.PaymentState.Paid.ToString();
                                                if (cpay.Save(mpay) > 0)
                                                {
                                                    int PaymentId = cpay.ReturnLastPaymentId();
                                                    mpc.BankId         = Convert.ToInt32(AccountId);
                                                    mpc.PaymentId      = PaymentId;
                                                    mpc.AmountRemaning = "0";
                                                    if (cpc.Save(mpc) > 0)
                                                    {
                                                        mpl.PaymentId        = PaymentId;
                                                        mpl.PaidAmount       = totalCost;
                                                        mpl.RemainingAmount  = "0";
                                                        mpl.Date             = txtDate.Text;
                                                        mpl.BankId           = Convert.ToInt32(AccountId);
                                                        mpl.CumulativeAmount = totalCost;
                                                        if (cpl.Save(mpl) > 0)
                                                        {
                                                            ShowErrorModal("Successfully Saved Journal");
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                }
                                else if (retVal == 0)
                                {
                                    ShowErrorModal("Not enough units in Warehouse:" + ddlWareHouse.SelectedItem.Text
                                                   + "Of Product: " + ddlProduct.SelectedItem.Text);
                                    break;
                                }
                                else
                                {
                                    ShowErrorModal("There was Error Saving the Journal");
                                    break;
                                }
                            }
                            else
                            {
                                ShowErrorModal("There was Error Saving the Journal");
                                break;
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        ShowErrorModal("Please select a Client");
                    }
                }
                else
                {
                    ShowErrorModal("Please select WareHouse");
                }


                bool FinalResuls = false;
                for (int i = 0; i < Result.Length; i++)
                {
                    if (Result[i])
                    {
                        FinalResuls = true;
                    }
                    else
                    {
                        FinalResuls = true;
                        ShowErrorModal("Some Transactions might have been incompleted");
                        break;
                    }
                }
                if (FinalResuls)
                {
                    ShowErrorModal("Journal Successfully Saved");
                    DeleteAllRowsFromGrid();
                    ClearTextBoxes(Page);
                    HidePreviewModal();

                    // Response.Redirect("~/Pages/Main.aspx");
                }
            }
            catch
            {
            }
        }
コード例 #6
0
        private int SaveOrders()
        {
            try
            {
                Classes.CDefaultCashAccount cda = new Classes.CDefaultCashAccount();
                Classes.CDefaultAccount     cba = new Classes.CDefaultAccount();

                int    OrderId            = 0;
                string OrderNo            = txtOrderNo.Text;
                string OrderName          = txtOrderName.Text;
                string OrderDescription   = txtOrderDescription.Text;
                string OrderDate          = txtOrderDate.Text;
                string OrderDeliveryDate  = txtDeliveryOfOrderDate.Text;
                string TotalCost          = ReturnTotalOrderCost().ToString();
                string OrderType          = ddlOrderType.SelectedValue;
                string VendorId           = ddlVendor.SelectedValue;
                string ClientId           = ddlCustomer.SelectedValue;
                string WareHouseId        = Session["WareHouse"].ToString();
                string ModeOfPayment      = ddlModeOfPayment.SelectedItem.Text;
                string Installments       = txtInstallments.Text;
                string InstallmentDueDate = txtIntallmentDueDate.Text;
                if (OrderType == "1")
                {
                    OrderType = "Order To Client";
                }
                else if (OrderType == "2")
                {
                    OrderType = "Order To Vendor";
                }
                else
                {
                    return(-2);
                }
                if (ModeOfPayment == "Please Select")
                {
                    return(-8);
                }
                Models.MOrders mr = new Models.MOrders();
                mr.OrdersNo           = OrderNo;
                mr.OrderName          = OrderName;
                mr.OrderDescription   = OrderDescription;
                mr.Orderdate          = OrderDate;
                mr.deliverydate       = OrderDeliveryDate;
                mr.TotalCost          = TotalCost;
                mr.OrderType          = OrderType;
                mr.eDate              = DateTime.Now.ToShortDateString();
                mr.FiscalYearld       = Session["FiscalYear"].ToString();
                mr.WareHouseId        = WareHouseId;
                mr.ModeOfPayment      = ModeOfPayment;
                mr.Installments       = Installments;
                mr.InstallmentDueDate = InstallmentDueDate;

                if (OrderType.EndsWith("Vendor"))
                {
                    mr.venorld  = VendorId;
                    mr.ClientId = "-1";
                    if (Convert.ToInt32(VendorId) < 0)
                    {
                        return(-5);
                    }
                }
                else
                {
                    if (cbGrantor.Checked)
                    {
                        string GrantorName = txtGrantorInfo.Text;
                        mr.GrantorName = GrantorName;
                    }

                    mr.ClientId = ClientId;
                    mr.venorld  = "-1";
                    if (Convert.ToInt32(ClientId) < 0)
                    {
                        return(-6);
                    }
                }
                Classes.COrders co = new Classes.COrders();
                if (Convert.ToInt32(WareHouseId) < 0)
                {
                    return(-7);
                }

                //Saving Order
                if (co.Save(mr) < 0)
                {
                    return(-1);
                }

                OrderId = co.GetLastOrderID();
                if (OrderId < 0)
                {
                    return(-3);
                }
                //Saving Order Products

                #region objects
                Models.MOrdersLine       mor = new Models.MOrdersLine();
                Models.MSaleTransactions ms  = new Models.MSaleTransactions();
                Classes.CSaleTransations ct  = new Classes.CSaleTransations();
                Classes.COrderOnline     cor = new Classes.COrderOnline();
                Models.MInventory        mi  = new Models.MInventory();
                Classes.CInventory       ci  = new Classes.CInventory();
                float OrderTotalCost         = 0;

                #endregion
                for (int i = 0; i < grdProducts.Rows.Count; i++)
                {
                    #region objects initializing
                    mor = new Models.MOrdersLine();
                    ms  = new Models.MSaleTransactions();
                    ct  = new Classes.CSaleTransations();
                    cor = new Classes.COrderOnline();
                    mi  = new Models.MInventory();
                    ci  = new Classes.CInventory();
                    DropDownList ddlProduct = (DropDownList)grdProducts.Rows[i].FindControl("ddlProducts");
                    TextBox      txtCp      = (TextBox)grdProducts.Rows[i].FindControl("txtCp");
                    TextBox      txtSp      = (TextBox)grdProducts.Rows[i].FindControl("txtSp");
                    TextBox      txtUnits   = (TextBox)grdProducts.Rows[i].FindControl("txtUnits");
                    TextBox      txtTotal   = (TextBox)grdProducts.Rows[i].FindControl("txtTotal");
                    string       ProductId  = ddlProduct.SelectedValue;
                    string       CostPrice  = txtCp.Text;
                    string       SalePrice  = txtSp.Text;
                    string       TotalUnits = txtUnits.Text;
                    string       totalCost  = (Convert.ToInt32(TotalUnits) * Convert.ToInt32(SalePrice)).ToString();
                    OrderTotalCost += Convert.ToSingle(totalCost);
                    #endregion

                    //OrderLine
                    #region OrderLine
                    mor.OrderId   = OrderId.ToString();
                    mor.ProductId = ProductId;
                    if (OrderType.EndsWith("Vendor"))
                    {
                        mor.SalePrice = CostPrice;
                    }
                    else
                    {
                        mor.SalePrice = SalePrice;
                    }
                    mor.unit             = TotalUnits;
                    mor.totalProductCost = totalCost;
                    mor.eDate            = DateTime.Now.ToShortDateString();
                    if (cor.Save(mor) < 0)
                    {
                        return(-3);
                    }
                    #endregion

                    //Sale transaction
                    #region Sale Transaction

                    ms.ProductID   = ProductId;
                    ms.clientID    = ClientId;
                    ms.CostPrice   = CostPrice;
                    ms.SalePrice   = SalePrice;
                    ms.units       = TotalUnits;
                    ms.clientID    = ClientId;
                    ms.VendorID    = VendorId;
                    ms.date        = Convert.ToDateTime(txtOrderDate.Text);
                    ms.WareHouseId = WareHouseId;
                    ms.OrderId     = OrderId.ToString();
                    if (OrderType.EndsWith("Vendor"))
                    {
                        ms.transactionType = Common.Constants.SaleTransactions.Addition.ToString();
                    }
                    else
                    {
                        ms.transactionType = Common.Constants.SaleTransactions.Deduction.ToString();
                    }


                    //sale transaction
                    if (ct.Save(ms) < 0)
                    {
                        return(-1);
                    }
                    #endregion


                    //Inventory
                    #region Inventory
                    mi.ProductId    = ProductId;
                    mi.WareHouseld  = WareHouseId;
                    mi.Quantity     = TotalUnits;
                    mi.FiscalYearld = Session["FiscalYear"].ToString();
                    mi.Date         = Convert.ToDateTime(OrderDate);
                    mi.Cost         = CostPrice;
                    if (OrderType.EndsWith("Vendor"))
                    {
                        //  mi.Cost = CostPrice;
                        if (ci.Save(mi, Common.Constants.SaleTransactions.Addition) < 0)
                        {
                            return(-4);
                        }
                    }
                    else
                    {
                        //   mi.Cost = SalePrice;
                        if (ci.Save(mi, Common.Constants.SaleTransactions.Deduction) < 0)
                        {
                            return(-4);
                        }
                    }
                    #endregion

                    //Accounts
                    #region Accounts
                    if (OrderType.Contains("Vendor"))
                    {
                        Classes.CJournal cj = new Classes.CJournal();
                        Models.MJournal  mj = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.MerchandiseInventory).ToString();
                        mj.amount = totalCost;
                        mj.des    = "Order Of Inventory for Vendor of Product Id [" + ProductId + "] units [" + TotalUnits + "] ";
                        mj.e_date = (OrderDate);
                        mj.type   = Common.Constants.Accounts.Type.Debit.ToString();
                        cj.Save(mj);

                        mj        = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.AccountsPayable).ToString();
                        mj.amount = totalCost;
                        mj.des    = "Order Of Inventory for Vendor of Product Id [" + ProductId + "] units [" + TotalUnits + "] ";
                        mj.e_date = (OrderDate);
                        mj.type   = Common.Constants.Accounts.Type.Credit.ToString();
                        cj.Save(mj);
                    }
                    else if (OrderType.Contains("Client"))
                    {
                        Classes.CJournal cj = new Classes.CJournal();
                        Models.MJournal  mj = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.AccountsRecievalbes).ToString();
                        mj.amount = totalCost;
                        mj.des    = "Order Of Inventory for Client of Product Id [" + ProductId + "] units [" + TotalUnits + "] ";
                        mj.e_date = (OrderDate);
                        mj.type   = Common.Constants.Accounts.Type.Debit.ToString();
                        cj.Save(mj);

                        cj        = new Classes.CJournal();
                        mj        = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.Sales).ToString();
                        mj.amount = totalCost;
                        mj.des    = "Order Of Inventory for Client of Product Id [" + ProductId + "] units [" + TotalUnits + "] ";
                        mj.e_date = (OrderDate);
                        mj.type   = Common.Constants.Accounts.Type.Credit.ToString();
                        cj.Save(mj);


                        cj        = new Classes.CJournal();
                        mj        = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.CostOfGoodsSold).ToString();
                        mj.amount = totalCost;
                        mj.des    = "Order Of Inventory for Client of Product Id [" + ProductId + "] units [" + TotalUnits + "] ";
                        mj.e_date = (OrderDate);
                        mj.type   = Common.Constants.Accounts.Type.Debit.ToString();
                        cj.Save(mj);

                        cj        = new Classes.CJournal();
                        mj        = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.MerchandiseInventory).ToString();
                        mj.amount = totalCost;
                        mj.des    = "Order Of Inventory for Client of Product Id [" + ProductId + "] units [" + TotalUnits + "] ";
                        mj.e_date = (OrderDate);
                        mj.type   = Common.Constants.Accounts.Type.Credit.ToString();
                        cj.Save(mj);
                    }
                    #endregion
                }

                //Payments
                #region Payments
                Classes.CPayment cap           = new Classes.CPayment();
                Models.MPayments map           = new Models.MPayments();
                string           TransactionId = ct.GetLastTransactionId().ToString();
                if (ddlOrderType.SelectedItem.Text.Contains("Vendor"))
                {
                    map.ClientId = -1;
                    map.VendorId = Convert.ToInt32(VendorId);
                }
                else if (ddlOrderType.SelectedItem.Text.Contains("Client"))
                {
                    map.ClientId = Convert.ToInt32(ClientId);
                    map.VendorId = -1;
                }
                map.TransactionId = Convert.ToInt32(TransactionId);
                map.Paid          = "0";
                map.TotalCost     = OrderTotalCost.ToString();
                map.OrderId       = OrderId;
                map.PaymentType   = Common.Constants.PaymentTypes.Partial.ToString();
                map.Paymentstate  = Common.Constants.PaymentState.NotPaid.ToString();
                if (cap.Save(map) < 0)
                {
                    return(-4);
                }
                #endregion

                return(1);
            }
            catch
            {
                return(-1);
            }
        }
コード例 #7
0
ファイル: CInventory.cs プロジェクト: centhacker/RetailSystem
        public int Save(Models.MInventory model, Common.Constants.SaleTransactions transaction)
        {
            Common.Logger l         = new Common.Logger();
            string        ClassName = "CInventory";

            try
            {
                string              totalUnitsofProducts = string.Empty;
                DB.Inventory        bs = new DB.Inventory();
                DB.InventoryBalance iv = new DB.InventoryBalance();
                switch (transaction)
                {
                    #region Addition Indentory
                case Common.Constants.SaleTransactions.Addition:
                {
                    #region Updating Inventory
                    var query = (from o in obj.Inventories
                                 where Convert.ToInt32(model.WareHouseld) == o.WareHouseId &&
                                 o.ProductId == Convert.ToInt32(model.ProductId) &&
                                 o.Cost == model.Cost
                                 select o.Quantity).FirstOrDefault();

                    if (query == null)
                    {
                        totalUnitsofProducts = model.Quantity;
                        //Inventory
                        bs.ProductId    = int.Parse(model.ProductId);
                        bs.WareHouseId  = int.Parse(model.WareHouseld);
                        bs.Cost         = model.Cost;
                        bs.date         = model.Date;
                        bs.Quantity     = totalUnitsofProducts;
                        bs.FiscalYearId = int.Parse(model.FiscalYearld);
                        l.Print(ClassName, Common.LogPointer.Info.ToString(), "Model Values id[" + model.id + "] ProductId[" + model.ProductId + "] WareHouseId[" + model.WareHouseld + "] Cost[" + model.Cost + "] Quantity[ " + model.Cost + "] FiscalYearId[ " + model.FiscalYearld + " ] ");
                        obj.Inventories.InsertOnSubmit(bs);
                        obj.SubmitChanges();
                        l.Print(ClassName, Common.LogPointer.Info.ToString(), "Record Inserted Successfully");
                    }
                    else
                    {
                        totalUnitsofProducts = query;
                        float Quantity = 0;
                        Quantity = Convert.ToSingle(totalUnitsofProducts)
                                   + Convert.ToSingle(model.Quantity);
                        var Data = (from o in obj.Inventories
                                    where Convert.ToInt32(model.WareHouseld) == o.WareHouseId &&
                                    o.ProductId == Convert.ToInt32(model.ProductId) &&
                                    o.Cost == model.Cost
                                    select o);
                        foreach (var item in Data)
                        {
                            item.ProductId   = Convert.ToInt32(model.ProductId);
                            item.Quantity    = Convert.ToString(Quantity);
                            item.Cost        = model.Cost;
                            item.WareHouseId = Convert.ToInt32(model.WareHouseld);
                            item.date        = model.Date;
                        }


                        obj.SubmitChanges();
                    }
                    #endregion

                    #region updating Inventory Balance
                    var invenotryBalance = (from o in obj.InventoryBalances
                                            where o.ProductsId == Convert.ToInt32(model.ProductId) &&
                                            o.WarehouseId == Convert.ToInt32(model.WareHouseld)
                                            orderby o.id ascending
                                            select o);
                    if (!invenotryBalance.Any())
                    {
                        iv.Date              = Convert.ToDateTime(model.Date);
                        iv.ProductsId        = Convert.ToInt32(model.ProductId);
                        iv.WarehouseId       = Convert.ToInt32(model.WareHouseld);
                        iv.PurchaseUnitsCost = model.Cost;
                        iv.PurchaseUnits     = model.Quantity;
                        float PurchaseTotal = Convert.ToSingle(Convert.ToSingle(model.Cost) * Convert.ToSingle(model.Quantity));
                        iv.PurchaseTotal    = PurchaseTotal.ToString();
                        iv.BalanceUnitsCost = model.Cost;
                        iv.BalanceUnits     = model.Quantity;
                        iv.BalanceTotal     = PurchaseTotal.ToString();
                        obj.InventoryBalances.InsertOnSubmit(iv);
                        obj.SubmitChanges();
                    }
                    else
                    {
                        float oldUnits = 0, oldCost = 0, oldTotal = 0,
                              newTotal = 0, newUnits = 0, newCost = 0;
                        foreach (var item in invenotryBalance)
                        {
                            oldUnits = Convert.ToSingle(item.BalanceUnits);
                            oldCost  = Convert.ToSingle(item.BalanceUnitsCost);
                            oldTotal = Convert.ToSingle(item.BalanceTotal);
                            newUnits = oldUnits + Convert.ToSingle(model.Quantity);
                            newCost  = Convert.ToSingle(model.Cost);
                            newTotal = Convert.ToSingle(newUnits * newCost);
                        }
                        iv.Date              = Convert.ToDateTime(model.Date);
                        iv.ProductsId        = Convert.ToInt32(model.ProductId);
                        iv.WarehouseId       = Convert.ToInt32(model.WareHouseld);
                        iv.PurchaseUnitsCost = model.Cost;
                        iv.PurchaseUnits     = model.Quantity;
                        float PurchaseTotal = Convert.ToSingle(Convert.ToSingle(model.Cost) * Convert.ToSingle(model.Quantity));
                        iv.PurchaseTotal    = PurchaseTotal.ToString();
                        iv.BalanceUnitsCost = newCost.ToString();
                        iv.BalanceUnits     = newUnits.ToString();
                        iv.BalanceTotal     = newTotal.ToString();
                        obj.InventoryBalances.InsertOnSubmit(iv);
                        obj.SubmitChanges();
                    }


                    #endregion

                    break;
                }
                    #endregion

                    #region Deduction Indentory

                case Common.Constants.SaleTransactions.Deduction:
                {
                    #region Updating Inventory
                    var query = (from o in obj.Inventories
                                 where Convert.ToInt32(model.WareHouseld) == o.WareHouseId &&
                                 o.ProductId == Convert.ToInt32(model.ProductId) &&
                                 o.Cost == model.Cost
                                 orderby o.date
                                 select o.Quantity).FirstOrDefault();
                    if (query == null)
                    {
                        return(0);
                    }
                    else
                    {
                        totalUnitsofProducts = query;
                        float Quantity = 0;
                        Quantity = Convert.ToSingle(totalUnitsofProducts)
                                   - Convert.ToSingle(model.Quantity);
                        if (Quantity < 0)
                        {
                            //Quantity not found in warehouse/Invenotry
                            return(0);
                        }

                        var Data = (from o in obj.Inventories
                                    where Convert.ToInt32(model.WareHouseld) == o.WareHouseId &&
                                    o.ProductId == Convert.ToInt32(model.ProductId) &&
                                    model.Cost == model.Cost
                                    select o);
                        foreach (var item in Data)
                        {
                            item.ProductId   = Convert.ToInt32(model.ProductId);
                            item.Quantity    = Convert.ToString(Quantity);
                            item.Cost        = model.Cost;
                            item.WareHouseId = Convert.ToInt32(model.WareHouseld);
                            bs.date          = model.Date;
                        }

                        obj.SubmitChanges();
                    }
                    #endregion

                    #region Updating Inventory Balance
                    var invenotryBalance = (from o in obj.InventoryBalances
                                            where o.ProductsId == Convert.ToInt32(model.ProductId) &&
                                            o.WarehouseId == Convert.ToInt32(model.WareHouseld)
                                            orderby o.id ascending
                                            select o);
                    if (!invenotryBalance.Any())
                    {
                        iv.Date          = Convert.ToDateTime(model.Date);
                        iv.ProductsId    = Convert.ToInt32(model.ProductId);
                        iv.WarehouseId   = Convert.ToInt32(model.WareHouseld);
                        iv.SaleUnitsCost = model.Cost;
                        iv.SaleUnits     = model.Quantity;
                        float PurchaseTotal = Convert.ToSingle(Convert.ToSingle(model.Cost) * Convert.ToSingle(model.Quantity));
                        iv.SaleTotal        = PurchaseTotal.ToString();
                        iv.BalanceUnitsCost = model.Cost;
                        iv.BalanceUnits     = model.Quantity;
                        iv.BalanceTotal     = PurchaseTotal.ToString();
                        obj.InventoryBalances.InsertOnSubmit(iv);
                        obj.SubmitChanges();
                    }
                    else
                    {
                        float oldUnits = 0, oldCost = 0, oldTotal = 0,
                              newTotal = 0, newUnits = 0, newCost = 0;
                        foreach (var item in invenotryBalance)
                        {
                            oldUnits = Convert.ToSingle(item.BalanceUnits);
                            oldCost  = Convert.ToSingle(item.BalanceUnitsCost);
                            oldTotal = Convert.ToSingle(item.BalanceTotal);
                            newUnits = oldUnits - Convert.ToSingle(model.Quantity);
                            newCost  = Convert.ToSingle(model.Cost);
                            newTotal = Convert.ToSingle(newUnits * newCost);
                        }
                        iv.Date          = Convert.ToDateTime(model.Date);
                        iv.ProductsId    = Convert.ToInt32(model.ProductId);
                        iv.WarehouseId   = Convert.ToInt32(model.WareHouseld);
                        iv.SaleUnitsCost = model.Cost;
                        iv.SaleUnits     = model.Quantity;
                        float PurchaseTotal = Convert.ToSingle(Convert.ToSingle(model.Cost) * Convert.ToSingle(model.Quantity));
                        iv.SaleTotal        = PurchaseTotal.ToString();
                        iv.BalanceUnitsCost = newCost.ToString();
                        iv.BalanceUnits     = newUnits.ToString();
                        iv.BalanceTotal     = newTotal.ToString();
                        obj.InventoryBalances.InsertOnSubmit(iv);
                        obj.SubmitChanges();
                    }


                    #endregion

                    break;
                }

                    #endregion

                    #region Transfer Inventory
                case Common.Constants.SaleTransactions.Transfer:
                {
                    break;
                }

                    #endregion

                default:
                {
                    totalUnitsofProducts = "0";
                    break;
                }
                }



                return(1);
            }
            catch (Exception ex)
            {
                l.Print(ClassName, Common.LogPointer.Error.ToString(), ex.ToString());
                return(-1);
            }
        }
コード例 #8
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //Saving Journal
            try
            {
                #region Objects
                Classes.CBankOfAccount      cab  = new Classes.CBankOfAccount();
                Classes.CAccountTransaction cat  = new Classes.CAccountTransaction();
                Classes.CSaleTransations    ct   = new Classes.CSaleTransations();
                Classes.CDefaultAccount     df   = new Classes.CDefaultAccount();
                Classes.CInventory          ci   = new Classes.CInventory();
                Classes.CPayment            cpay = new Classes.CPayment();
                Classes.CPaymentLine        cpl  = new Classes.CPaymentLine();
                Classes.CPaymentContainer   cpc  = new Classes.CPaymentContainer();
                Models.MInventory           mi   = new Models.MInventory();
                Models.MAccountTransaction  mat  = new Models.MAccountTransaction();
                Models.MSaleTransactions    ms   = new Models.MSaleTransactions();
                Models.MPayments            mpay = new Models.MPayments();
                Models.PaymentContainer     mpc  = new Models.PaymentContainer();
                Models.PaymentLine          mpl  = new Models.PaymentLine();
                #endregion


                string WareHouseId = ddlWareHouse.SelectedValue;
                //   float Discount = Convert.ToSingle(txtDiscount.Text);
                //   Discount = Discount / grdSales.Rows.Count;
                if (Convert.ToInt32(WareHouseId) > 0)
                {
                    #region Start Saving

                    for (int i = 0; i < grdSales.Rows.Count; i++)
                    {
                        DropDownList ddlProduct = (DropDownList)grdSales.Rows[i].FindControl("ddlProducts");
                        TextBox      txtCp      = (TextBox)grdSales.Rows[i].FindControl("txtCp");
                        Label        txtVendor  = (Label)grdSales.Rows[i].FindControl("txtVendor");
                        TextBox      txtUnits   = (TextBox)grdSales.Rows[i].FindControl("txtUnits");
                        TextBox      txtTotal   = (TextBox)grdSales.Rows[i].FindControl("txtTotal");

                        string   ProductId     = ddlProduct.SelectedValue;
                        string   CostPrice     = txtCp.Text;
                        string[] VendorDetails = txtVendor.Text.Split('-');
                        string   VendorId      = VendorDetails[0];
                        string   TotalUnits    = txtUnits.Text;
                        string   totalCost     = (Convert.ToInt32(TotalUnits) * Convert.ToInt32(CostPrice)).ToString();
                        totalCost          = Convert.ToSingle(Convert.ToSingle(totalCost)).ToString();
                        ms.ProductID       = ProductId;
                        ms.CostPrice       = CostPrice;
                        ms.units           = TotalUnits;
                        ms.date            = Convert.ToDateTime(txtDate.Text);
                        ms.transactionType = Common.Constants.SaleTransactions.Addition.ToString();
                        ms.date            = Convert.ToDateTime(txtDate.Text);
                        ms.VendorID        = VendorId;
                        ms.OrderId         = "-1";
                        ms.WareHouseId     = WareHouseId;
                        ms.clientID        = "-1";
                        ms.Discount        = "0";
                        //sale transaction
                        if (ct.Save(ms) > 0)
                        {
                            mi.WareHouseld  = WareHouseId;
                            mi.Cost         = CostPrice;
                            mi.Quantity     = TotalUnits;
                            mi.ProductId    = ProductId;
                            mi.FiscalYearld = "1";
                            mi.Date         = Convert.ToDateTime(txtDate.Text);

                            //inventory
                            int retVal = ci.Save(mi, Common.Constants.SaleTransactions.Addition);
                            if (retVal > 0)
                            {
                                //dance
                            }
                            else if (retVal == 0)
                            {
                                ShowErrorModal("Not enough units");
                            }
                            else
                            {
                                ShowErrorModal("There was Error Saving the Journal");
                                break;
                            }
                        }
                        else
                        {
                            ShowErrorModal("There was Error Saving the Journal");
                            break;
                        }
                    }

                    ShowErrorModal("Successfully Saved Journal");
                    DeleteAllRowsFromGrid();
                    ClearTextBoxes(Page);
                    HidePreviewModal();
                    #endregion
                }
                else
                {
                    ShowErrorModal("Please Select Warehouse");
                }
            }
            catch
            {
            }
        }