コード例 #1
0
        private void CalculateDealValue()
        {
            try
            {
                if (Conn.State == ConnectionState.Closed)
                {
                    Conn.Open();
                }
                double Consideration, Commission, GrossCommission, BasicCharges, StampDuty = 0, Vat, SecLevy, ZSELevy, InvestorProtection, CapitalGains = 0, NMIRebate, CSDLevy;
                double Price;
                double DealValue = 0;
                double Qty       = 0;
                //int DocNo;
                string   DealType = "", DealNo = "";
                string   ClientNo = "", Asset = "";
                string   Reference = "";
                DateTime CertDueBy;

                if (ValidateInput() == false)
                {
                    return;
                }

                if (rdoSell.Checked)
                {
                    DealType = "SELL";
                    //DealNo = "S/" + GetDealNo();
                    //CapitalGains = BusLib.CalculateCapitalGains(Consideration, CapitalRate);
                }
                else if (rdoBuy.Checked)
                {
                    DealType = "BUY";
                    //DealNo = "B/" + GetDealNo();
                    // StampDuty = BusLib.CalculateStampDuty(Consideration, StampDutyRate);
                }
                else if (rdoBookover.Checked)
                {
                    DealType = "BOVER";
                    //DealNo = "B/" + GetDealNo();
                    // StampDuty = BusLib.CalculateStampDuty(Consideration, StampDutyRate);
                }

                //Reference = txtReference.Text;
                //ClientNo = txtClientNo.Text;
                Price     = double.Parse(txtPrice.Text);
                Qty       = double.Parse(txtQty.Text);
                CertDueBy = GetSettlementDate(DealDate);
                Asset     = cmbAsset.Text;

                Consideration = BusLib.CalculateConsideration(Qty, Price);


                GetRates(ClientNo);
                if (DealType == "SELL")
                {
                    CapitalGains = BusLib.CalculateCapitalGains(Consideration, CapitalRate);
                }
                else if (DealType == "BUY")
                {
                    StampDuty = BusLib.CalculateStampDuty(Consideration, StampDutyRate);
                }

                //if (chkRemoveCommission.Checked)
                //{

                //    GrossCommission = 0;
                //    Commission = 0;
                //    NMIRebate = 0;
                //}
                //else
                //{
                //    GrossCommission = BusLib.CalculateCommission(Consideration, CommRate);
                //    Commission = (1 - NMIRebateRate) * GrossCommission;
                //    NMIRebate = NMIRebateRate * GrossCommission;
                //}
                //if (chkRemoveBasicCharges.Checked)
                //{
                //    BasicCharges = 0;
                //}
                //else
                //    BasicCharges = BCRate;

                BasicCharges    = BCRate;
                GrossCommission = BusLib.CalculateCommission(Consideration, CommRate);
                Commission      = (1 - NMIRebateRate) * GrossCommission;
                NMIRebate       = NMIRebateRate * GrossCommission;

                Vat = BusLib.CalculateVAT(GrossCommission + BasicCharges, VatRate);

                InvestorProtection = BusLib.CalculateInvestorProtection(Consideration, InvestorRate);
                SecLevy            = BusLib.CalculateSecLevy(Consideration, SecLevyRate);
                ZSELevy            = BusLib.CalculateZSELevy(Consideration, ZSELevyRate);
                CSDLevy            = CalculateCSDLevy(Consideration, CSDLevyRate);

                if (DealType == "SELL")
                {
                    DealValue = Consideration - (Vat + GrossCommission + StampDuty + BasicCharges + SecLevy + CapitalGains + InvestorProtection + ZSELevy + CSDLevy);
                }
                else if (DealType == "BUY")
                {
                    DealValue = Consideration + (Vat + GrossCommission + StampDuty + BasicCharges + SecLevy + CapitalGains + InvestorProtection + ZSELevy + CSDLevy);
                }
                else if (DealType == "BOVER")
                {
                    DealValue = Consideration + (Vat + GrossCommission + StampDuty + BasicCharges + SecLevy + CapitalGains + InvestorProtection + ZSELevy + CSDLevy);
                }

                txtDealValue.Text     = Math.Round((float)DealValue, 2).ToString();
                txtConsideration.Text = Math.Round((float)Consideration, 2).ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Falcon", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //ScreenShot.EmailScreenShot(ex.ToString());
            }
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (Conn.State == ConnectionState.Closed)
                {
                    Conn.Open();
                }
                double Consideration, Commission, GrossCommission, BasicCharges, StampDuty = 0, Vat, SecLevy, ZSELevy, InvestorProtection, CapitalGains = 0, NMIRebate, CSDLevy;
                double Price;
                double DealValue = 0;
                double Qty       = 0;
                //int DocNo;
                string   DealType = "", DealNo = "";
                string   ClientNo = "", Asset = "";
                string   Reference = "";
                DateTime CertDueBy;
                if (BusLib.TimeoutUsers(CurrentUser, false, Text) == true)
                {
                    MessageBox.Show("Your session has expired. Please, login again to use the system", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                //if (BusLib.HasAccess(CurrentUser, "Post Deal Adjustments") == false)
                //{
                //    MessageBox.Show("You do not have permission to perform the selected task!", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //    return;
                //}

                if (dtDealDate.Text == "")
                {
                    MessageBox.Show("Please enter deal date", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    //dtpDealDate.Focus();
                    return;
                }
                //commented 03092014 ABC
                //if (BusLib.IsPeriodLocked(Convert.ToDateTime(dtpDealDate.Text)))
                if (BusLib.IsPeriodLocked(dtDealDate.DateTime))
                {
                    MessageBox.Show("Accounting period currently locked. If you are not the one who locked it, please contact your administrator", "Locked Accounting Period", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    dtDealDate.Focus();
                    return;
                }

                #region Check Permissions for Removing Charges
                //if ((chkRemoveBasicCharges.Checked) || (chkRemoveCommission.Checked))
                //{
                //    if (BusLib.HasAccess(CurrentUser, "Remove Charges") == false)
                //    {
                //        MessageBox.Show("You do not have permission to perform the selected task!", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //        return;
                //    }
                //}
                #endregion


                #region Check Permissions for Removing Charges
                //if ((chkRemoveBasicCharges.Checked) || (chkRemoveCommission.Checked))
                //{
                //    if (BusLib.HasAccess(CurrentUser, "Remove Charges") == false)
                //    {
                //        MessageBox.Show("You do not have permission to perform the selected task!", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //        return;
                //    }
                //}
                #endregion


                //if (ValidateInput() == false)
                //{
                //   return;
                //}


                if (rdoSell.Checked)
                {
                    DealType = "SELL";
                }
                else if (rdoBuy.Checked)
                {
                    DealType = "BUY";
                }

                ClientNo = ClassGenLib.selectedClient;
                //Price=double.Parse(txtPrice.Text);
                txtPrice.Text = txtPrice.Text.Replace(',', '.');
                Price         = Convert.ToDouble(txtPrice.Text);
                Qty           = double.Parse(txtQty.Text);
                CertDueBy     = GetSettlementDate(dtDealDate.DateTime);
                Asset         = cmbAsset.Text;

                Consideration = BusLib.CalculateConsideration(Qty, Price);


                GetRates(ClientNo);
                if (DealType == "SELL")
                {
                    CapitalGains = BusLib.CalculateCapitalGains(Consideration, CapitalRate);
                }
                else if (DealType == "BUY")
                {
                    StampDuty = BusLib.CalculateStampDuty(Consideration, StampDutyRate);
                }

                //if (chkRemoveCommission.Checked)
                //{

                //    #region Check Permissions for Removing Charges
                //    if ((chkRemoveBasicCharges.Checked) || (chkRemoveCommission.Checked))
                //    {
                //        if (BusLib.HasAccess(CurrentUser, "Remove Charges") == false)
                //        {
                //            MessageBox.Show("You do not have permission to perform the selected task!", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //            return;
                //        }
                //    }
                //    #endregion
                //    GrossCommission = 0;
                //    Commission = 0;
                //    NMIRebate = 0;
                //}
                //else
                {
                    GrossCommission = BusLib.CalculateCommission(Consideration, CommRate);
                    Commission      = (1 - NMIRebateRate) * GrossCommission;
                    NMIRebate       = NMIRebateRate * GrossCommission;
                }
                //if (chkRemoveBasicCharges.Checked)
                //{
                //    #region Check Permissions for Removing Charges
                //    if ((chkRemoveBasicCharges.Checked) || (chkRemoveCommission.Checked))
                //    {
                //        if (BusLib.HasAccess(CurrentUser, "Remove Charges") == false)
                //        {
                //            MessageBox.Show("You do not have permission to perform the selected task!", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //            return;
                //        }
                //    }
                //    #endregion
                //      BasicCharges = 0;
                //}
                //else
                BasicCharges = BCRate;

                /*
                 * PROPRIETARY ACCOUNT CUSTOMIZATION FOR ABC STOCKBROKERS
                 */
                SqlCommand cmdProprietary = new SqlCommand("select isnull(count(clientno), 0) from clients where clientno = '" + ClientNo + "' and category = 'PROPRIETARY'", Conn);
                int        cntProprietary = Convert.ToInt16(cmdProprietary.ExecuteScalar());
                if (cntProprietary > 0)
                {
                    cmdProprietary.CommandText = "select commission, vat from clientcategory where clientcategory = 'OTHER'";
                    SqlDataReader rdProp          = cmdProprietary.ExecuteReader();
                    double        commProprietary = 0;
                    double        vatProprietary  = 0;
                    while (rdProp.Read())
                    {
                        commProprietary = Convert.ToDouble(rdProp[0].ToString());
                        vatProprietary  = Convert.ToDouble(rdProp[1].ToString());
                    }
                    rdProp.Close();
                    Vat = Consideration * commProprietary * vatProprietary / 10000;
                }
                else
                {
                    Vat = BusLib.CalculateVAT(GrossCommission + BasicCharges, VatRate);
                }

                //check if the system is configured to capture CSD Number for a deal
                cmdProprietary.CommandText = "select CaptureCSDNo from tblSystemParams";
                sbyte CaptureCSD = Convert.ToSByte(cmdProprietary.ExecuteScalar());
                InvestorProtection = BusLib.CalculateInvestorProtection(Consideration, InvestorRate);
                SecLevy            = BusLib.CalculateSecLevy(Consideration, SecLevyRate);
                ZSELevy            = BusLib.CalculateZSELevy(Consideration, ZSELevyRate);
                CSDLevy            = CalculateCSDLevy(Consideration, CSDLevyRate);

                if (DealType == "SELL")
                {
                    DealValue = Consideration - (Vat + GrossCommission + StampDuty + BasicCharges + SecLevy + CapitalGains + InvestorProtection + ZSELevy + CSDLevy);
                }
                else if (DealType == "BUY")
                {
                    DealValue = Consideration + (Vat + GrossCommission + StampDuty + BasicCharges + SecLevy + CapitalGains + InvestorProtection + ZSELevy + CSDLevy);
                }

                if (rdoBookover.Checked == false)
                {
                    using (SqlCommand NewDealCmd = new SqlCommand())
                    {
                        SqlCommand cmdPost = new SqlCommand("spPostDeal", Conn);
                        cmdPost.CommandType    = CommandType.StoredProcedure;
                        cmdPost.CommandTimeout = 12000;
                        SqlParameter p1  = new SqlParameter("@dealdate", dtDealDate.Text);
                        SqlParameter p2  = new SqlParameter("@clientno", ClassGenLib.selectedClient);
                        SqlParameter p3  = new SqlParameter("@dealtype", DealType);
                        SqlParameter p4  = new SqlParameter("@qty", txtQty.Text);
                        SqlParameter p5  = new SqlParameter("@price", Price);
                        SqlParameter p6  = new SqlParameter("@asset", cmbAsset.Text.Substring(0, cmbAsset.Text.IndexOf("|") - 1));
                        SqlParameter p7  = new SqlParameter("@csdnumber", txtCSD.Text);
                        SqlParameter p8  = new SqlParameter("@user", ClassGenLib.username);
                        SqlParameter p9  = new SqlParameter("@noncustodial", chkCustodial.Checked);
                        SqlParameter p10 = new SqlParameter("@bookover", false);

                        cmdPost.Parameters.Add(p1); cmdPost.Parameters.Add(p2);
                        cmdPost.Parameters.Add(p3); cmdPost.Parameters.Add(p4);
                        cmdPost.Parameters.Add(p5); cmdPost.Parameters.Add(p6);
                        cmdPost.Parameters.Add(p7); cmdPost.Parameters.Add(p8);
                        cmdPost.Parameters.Add(p9); cmdPost.Parameters.Add(p10);

                        cmdPost.ExecuteNonQuery();

                        chkCustodial.Checked = false;
                    }
                }

                if (rdoBookover.Checked == true)
                {
                    using (SqlCommand NewDealCmd = new SqlCommand())
                    {
                        //post BUY deal
                        SqlCommand cmdPost = new SqlCommand("spPostDeal", Conn);
                        cmdPost.CommandType    = CommandType.StoredProcedure;
                        cmdPost.CommandTimeout = 12000;
                        SqlParameter p1  = new SqlParameter("@dealdate", dtDealDate.Text);
                        SqlParameter p2  = new SqlParameter("@clientno", Buyer);
                        SqlParameter p3  = new SqlParameter("@dealtype", "BUY");
                        SqlParameter p4  = new SqlParameter("@qty", txtQty.Text);
                        SqlParameter p5  = new SqlParameter("@price", Price);
                        SqlParameter p6  = new SqlParameter("@asset", cmbAsset.Text.Substring(0, cmbAsset.Text.IndexOf("|") - 1));
                        SqlParameter p7  = new SqlParameter("@csdnumber", CSDBuy);
                        SqlParameter p8  = new SqlParameter("@user", ClassGenLib.username);
                        SqlParameter p9  = new SqlParameter("@noncustodial", chkCustodial.Checked);
                        SqlParameter p10 = new SqlParameter("@bookover", true);

                        cmdPost.Parameters.Add(p1); cmdPost.Parameters.Add(p2);
                        cmdPost.Parameters.Add(p3); cmdPost.Parameters.Add(p4);
                        cmdPost.Parameters.Add(p5); cmdPost.Parameters.Add(p6);
                        cmdPost.Parameters.Add(p7); cmdPost.Parameters.Add(p8);
                        cmdPost.Parameters.Add(p9); cmdPost.Parameters.Add(p10);

                        cmdPost.ExecuteNonQuery();

                        //post SELL deal
                        p2.Value = Seller;
                        p3.Value = "SELL";
                        p7.Value = CSDSell;

                        cmdPost.ExecuteNonQuery();
                        chkCustodial.Checked = false;
                    }
                }

                MessageBox.Show("Deal(s) posted successfully", "Deal Adjusted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                rdoBookover.Checked = false;

                ClearForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Falcon", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //ScreenShot.EmailScreenShot(ex.ToString());
            }
        }