예제 #1
0
        protected void btnPreview_Click(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                int ClientId    = Convert.ToInt32(ddlClient.SelectedValue);
                int WareHouseID = Convert.ToInt32(ddlWareHouse.SelectedValue);
                if (ClientId > 0)
                {
                    if (WareHouseID > 0)
                    {
                        if (grdSales.Rows.Count > 0)
                        {
                            string retVal = CheckInventoryForproducts();

                            if (retVal == "Successfull")
                            {
                                Classes.CDefaultAccount cd = new Classes.CDefaultAccount();
                                if (cd.ReturnSaleDefaultAccount(Convert.ToInt32(Session["WareHouse"])) > 0)
                                {
                                    ShowPreviewModal();
                                }
                                else
                                {
                                    ShowErrorModal("Default Account for sales not set, Kindly Set it in Accounts");
                                }
                            }
                            else
                            {
                                ShowErrorModal(retVal);
                            }
                        }
                        else
                        {
                            ShowErrorModal("Please Add some rows to journal");
                        }
                    }
                    else
                    {
                        ShowErrorModal("Please select WareHouse");
                    }
                }
                else
                {
                    ShowErrorModal("Please select Client");
                }
            }
        }
예제 #2
0
        private int SavePayment(string Type)
        {
            switch (Type)
            {
            case "Client":
            {
                string PaymentId         = lblSalesPaymentId.Text;
                string OrderId           = lblSalesOrderID.Text;
                string totalCost         = lblSalesTotalCost.Text;
                string CurrentAmountPaid = txtSalesAmount.Text;
                string AccountId         = ddlSaleAccount.SelectedValue;
                if (cbSalesDefault.Checked)
                {
                    Classes.CDefaultAccount df = new Classes.CDefaultAccount();
                    AccountId = df.ReturnSaleDefaultAccount(Convert.ToInt32(Session["WareHouse"])).ToString();
                }
                float  AmountRemaining = Convert.ToSingle(totalCost) - (Convert.ToSingle(CurrentAmountPaid) + Convert.ToSingle(lblSalesAmountPaid.Text));
                string RemainingAmount = AmountRemaining.ToString();
                string DatePaid        = txtSalesDate.Text;
                return(ProcessPayments(PaymentId, OrderId, totalCost, CurrentAmountPaid, AccountId
                                       , AmountRemaining, RemainingAmount, DatePaid, Type));
            }

            case "Vendor":
            {
                string PaymentId         = lblPurchasePaymentId.Text;
                string OrderId           = lblPurchaseOrderId.Text;
                string totalCost         = lblPurchaseTotalCost.Text;
                string CurrentAmountPaid = txtPurchaseAmount.Text;
                string AccountId         = ddlPurchaseAccount.SelectedValue;
                if (cbPurchases.Checked)
                {
                    Classes.CDefaultAccount df = new Classes.CDefaultAccount();
                    AccountId = df.ReturnPurchaseDefaultAccount(Convert.ToInt32(Session["WareHouse"])).ToString();
                }
                float  AmountRemaining = Convert.ToSingle(totalCost) - (Convert.ToSingle(CurrentAmountPaid) + Convert.ToSingle(lblPurchaseAmountPaid.Text));
                string RemainingAmount = AmountRemaining.ToString();
                string DatePaid        = txtPurchaseDate.Text;
                return(ProcessPayments(PaymentId, OrderId, totalCost, CurrentAmountPaid, AccountId
                                       , AmountRemaining, RemainingAmount, DatePaid, Type));
            }

            default:
                return(-1);
            }
        }
예제 #3
0
        private void BindAccountNames()
        {
            Classes.CDefaultAccount    cdf = new Classes.CDefaultAccount();
            Classes.CBankOfAccount     cba = new Classes.CBankOfAccount();
            List <Models.MBankAccount> ListSalesAccounts    = new List <Models.MBankAccount>();
            List <Models.MBankAccount> ListPurchaseAccounts = new List <Models.MBankAccount>();
            int SalesAccount = cdf.ReturnSaleDefaultAccount(Convert.ToInt32(Session["WareHouse"]));

            if (SalesAccount < 0)
            {
                lblSalesAccount.Text = "No Default Account Set";
            }
            else
            {
                ListSalesAccounts = cba.GetAllbyid(SalesAccount);
                if (ListSalesAccounts.Count == 0)
                {
                    lblSalesAccount.Text = "No Default Account Set";
                }
                else
                {
                    lblSalesAccount.Text = ListSalesAccounts[0].Accounttitle + "-" + ListSalesAccounts[0].accountNumber;
                }
            }
            int PurchaseAccount = cdf.ReturnPurchaseDefaultAccount(Convert.ToInt32(Session["WareHouse"]));

            if (PurchaseAccount < 0)
            {
                lblPurchaseAccount.Text = "No Default Account Set";
            }
            else
            {
                ListPurchaseAccounts = cba.GetAllbyid(PurchaseAccount);
                if (ListPurchaseAccounts.Count == 0)
                {
                    lblPurchaseAccount.Text = "No Default Account Set";
                }
                else
                {
                    lblPurchaseAccount.Text = ListPurchaseAccounts[0].Accounttitle + "-" + ListPurchaseAccounts[0].accountNumber;
                }
            }
        }
예제 #4
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
            {
            }
        }