Beispiel #1
0
        /// <summary>
        /// get closing data from id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ClosingProperty GetClosingDataWithId(int id)
        {
            ClosingProperty result = new ClosingProperty();
            string          sql    = @"SELECT * FROM closing WHERE closing_id = @id";

            MySqlCommand command = new MySqlCommand(sql, conn);

            command.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)).Value = id;

            command.Prepare();

            MySqlDataReader reader = command.ExecuteReader();

            object[] tempResult = new object[4];

            while (reader.Read())
            {
                tempResult[0] = reader.GetInt32("closing_id");
                tempResult[1] = reader.GetDateTime("date");
                tempResult[2] = reader.GetString("closing_type");
                tempResult[3] = reader.GetDouble("total_nominal");

                result = new ClosingProperty(tempResult);
            }

            reader.Close();
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// generete the closing view
        /// </summary>
        /// <param name="closing"></param>
        void GenerateTree(ClosingProperty closing)
        {
            treeViewSpecificClosing.Nodes.Clear();
            TreeNode tNode;

            tNode = treeViewSpecificClosing.Nodes.Add("Closing ID : " + closing.id + " (Total Nominal : Rp " +
                                                      closing.TotalNominal + ") | Type : " + closing.ClosingType);

            AgentClosing[] agents = Connection.Instance.GetAgentClosingDataFromClosingData(closing.id.ToString());

            for (int i = 0; i < agents.Length; i++)
            {
                treeViewSpecificClosing.Nodes[0].Nodes.Add(i + ". " + agents[i].AgentID + " (Rp " + agents[i].Nominal + ") - " + agents[i].Unit + " units");

                Commission[] commissions = Connection.Instance.GetCommissionDataFromAgentAndClosing(agents[i].AgentID, agents[i].ClosingID);

                for (int j = 0; j < commissions.Length; j++)
                {
                    treeViewSpecificClosing.Nodes[0].Nodes[i].Nodes.Add(commissions[j].CommissionLevel + " : " +
                                                                        commissions[j].AgentID + " (Rp " + commissions[j].CommissionNominal + ") Level : " + commissions[j].CommissionLevelValue);
                }
            }
            treeViewSpecificClosing.ExpandAll();
        }
Beispiel #3
0
        private void comboBoxClosingID_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            ClosingProperty globalClosing = Connection.Instance.GetClosingDataWithId(int.Parse(comboBoxClosingID.SelectedValue.ToString().TrimStart('0')));

            GenerateTree(globalClosing);
        }
        /// <summary>
        /// inserting the closing, agent closing, and commission
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonInsertComissionSave_Click(object sender, EventArgs e)
        {
            double temp  = 0;
            double temp2 = 0;

            for (int i = 0; i < ParticipatedAgents.Count; i++)
            {
                temp  += ParticipatedAgents[i].nominal.GetValue();
                temp2 += double.Parse(ParticipatedAgents[i].unit.Text);
            }

            if (temp > myTextBoxTotalNominal.GetValue())
            {
                MessageBox.Show("Nominal in agents closing is higher than total nominal. Please check again");
                return;
            }

            if (temp2 > 1)
            {
                MessageBox.Show("Total unit cannot be more than 1");
                return;
            }

            ClosingProperty closing = new ClosingProperty();

            closing.DateClosed   = dateTimePickerInsertCommission.Value;
            closing.ClosingType  = radioButtonClosingProperty.Checked ? TypeOfClosing.Property.ToString() : TypeOfClosing.Loan.ToString();
            closing.TotalNominal = myTextBoxTotalNominal.GetValue();

            Connection.Instance.InsertNewClosing(closing.GetClosingData());

            for (int i = 0; i < ParticipatedAgents.Count; i++)
            {
                AgentClosing agentClosing = new AgentClosing();
                if (radioButtonClosingProperty.Checked)
                {
                    agentClosing.Unit = double.Parse(ParticipatedAgents[i].unit.Text);
                }
                else
                {
                    agentClosing.Unit = 0;
                }

                agentClosing.Nominal   = ParticipatedAgents[i].nominal.GetValue();
                agentClosing.AgentID   = ParticipatedAgents[i].agent.ID;
                agentClosing.ClosingID = nextClosingID;

                string currentAgentID = "";

                Connection.Instance.InsertNewAgentClosing(agentClosing.GetAgentClosingData());
                bool principalFirst = false;
                bool viceFirst      = false;

                if (ParticipatedAgents[i].agent.ID == new Agent(Connection.Instance.GetAgentData(new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(ParticipatedAgents[i].agent.BranchID, PrincipalOrVice.Principal)).AgentID, TempData.ID)).ID)
                {
                    principalFirst = true;
                }
                else if (ParticipatedAgents[i].agent.ID == new Agent(Connection.Instance.GetAgentData(new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(ParticipatedAgents[i].agent.BranchID, PrincipalOrVice.VicePrincipal)).AgentID, TempData.ID)).ID)
                {
                    viceFirst = true;
                }
                bool principalTaken = false;
                bool viceTaken      = false;
                for (int j = 0; j < 5; j++)
                {
                    Commission       commission = new Commission();
                    PrincipalAndVice princi     = new PrincipalAndVice();
                    PrincipalAndVice vicePrinci = new PrincipalAndVice();

                    commission.AgentClosingID = ParticipatedAgents[i].agent.ID;
                    if (j == 0)
                    {
                        currentAgentID             = Connection.Instance.GetUplineIDFromAgentID(ParticipatedAgents[i].agent.ID);
                        commission.CommissionLevel = Helper.Upline1;
                        if (currentAgentID != Connection.Instance.GetEmptyAgent())
                        {
                            princi     = new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(Connection.Instance.GetBranchIDFromAgentID(currentAgentID), PrincipalOrVice.Principal));
                            vicePrinci = new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(Connection.Instance.GetBranchIDFromAgentID(currentAgentID), PrincipalOrVice.VicePrincipal));
                        }

                        if (currentAgentID == princi.AgentID)
                        {
                            if (!principalFirst && !viceFirst)
                            {
                                commission.AgentID = Connection.Instance.GetEmptyAgent();
                            }
                            else
                            {
                                commission.AgentID = currentAgentID;
                            }
                            principalTaken = true;
                        }
                        else if (currentAgentID == vicePrinci.AgentID)
                        {
                            if (!principalFirst && !viceFirst)
                            {
                                commission.AgentID = Connection.Instance.GetEmptyAgent();
                            }
                            else
                            {
                                commission.AgentID = currentAgentID;
                            }
                            viceTaken = true;
                        }
                        else
                        {
                            commission.AgentID = currentAgentID;
                        }
                    }
                    else if (j == 1)
                    {
                        currentAgentID             = Connection.Instance.GetUplineIDFromAgentID(currentAgentID);
                        commission.CommissionLevel = Helper.Upline2;
                        if (currentAgentID != Connection.Instance.GetEmptyAgent())
                        {
                            princi     = new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(Connection.Instance.GetBranchIDFromAgentID(currentAgentID), PrincipalOrVice.Principal));
                            vicePrinci = new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(Connection.Instance.GetBranchIDFromAgentID(currentAgentID), PrincipalOrVice.VicePrincipal));
                        }

                        if (currentAgentID == princi.AgentID)
                        {
                            if (!principalFirst && !viceFirst)
                            {
                                commission.AgentID = Connection.Instance.GetEmptyAgent();
                            }
                            else
                            {
                                commission.AgentID = currentAgentID;
                            }
                            principalTaken = true;
                        }
                        else if (currentAgentID == vicePrinci.AgentID)
                        {
                            if (!principalFirst && !viceFirst)
                            {
                                commission.AgentID = Connection.Instance.GetEmptyAgent();
                            }
                            else
                            {
                                commission.AgentID = currentAgentID;
                            }
                            viceTaken = true;
                        }
                        else
                        {
                            commission.AgentID = currentAgentID;
                        }
                    }
                    else if (j == 2)
                    {
                        currentAgentID             = Connection.Instance.GetUplineIDFromAgentID(currentAgentID);
                        commission.CommissionLevel = Helper.Upline3;
                        if (currentAgentID != Connection.Instance.GetEmptyAgent())
                        {
                            princi     = new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(Connection.Instance.GetBranchIDFromAgentID(currentAgentID), PrincipalOrVice.Principal));
                            vicePrinci = new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(Connection.Instance.GetBranchIDFromAgentID(currentAgentID), PrincipalOrVice.VicePrincipal));
                        }
                        if (currentAgentID == princi.AgentID)
                        {
                            if (!principalFirst && !viceFirst)
                            {
                                commission.AgentID = Connection.Instance.GetEmptyAgent();
                            }
                            else
                            {
                                commission.AgentID = currentAgentID;
                            }
                            principalTaken = true;
                        }
                        else if (currentAgentID == vicePrinci.AgentID)
                        {
                            if (!principalFirst && !viceFirst)
                            {
                                commission.AgentID = Connection.Instance.GetEmptyAgent();
                            }
                            else
                            {
                                commission.AgentID = currentAgentID;
                            }
                            viceTaken = true;
                        }
                        else
                        {
                            commission.AgentID = currentAgentID;
                        }
                    }
                    else if (j == 3)
                    {
                        currentAgentID             = new Agent(Connection.Instance.GetAgentData(new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(ParticipatedAgents[i].agent.BranchID, PrincipalOrVice.Principal)).AgentID, TempData.ID)).ID;
                        commission.CommissionLevel = Helper.Principal;

                        if (principalTaken || principalFirst)
                        {
                            commission.AgentID = Connection.Instance.GetEmptyAgent();
                        }
                        else
                        {
                            commission.AgentID = currentAgentID;
                        }
                    }
                    else if (j == 4)
                    {
                        currentAgentID             = new Agent(Connection.Instance.GetAgentData(new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(ParticipatedAgents[i].agent.BranchID, PrincipalOrVice.VicePrincipal)).AgentID, TempData.ID)).ID;
                        commission.CommissionLevel = Helper.VicePrincipal;
                        //   MessageBox.Show("Vice taken : " + viceTaken.ToString() + ", viceFirst : " + viceFirst.ToString());
                        if (viceTaken || viceFirst)
                        {
                            commission.AgentID = Connection.Instance.GetEmptyAgent();
                        }
                        else
                        {
                            commission.AgentID = currentAgentID;
                        }
                    }

                    commission.CommissionLevelValue = Connection.Instance.GetCommissionLevelValue(commission.CommissionLevel);

                    if (Connection.Instance.CheckActiveAgent(commission.AgentID, TempData.ID))
                    {
                        commission.CommissionNominal = ParticipatedAgents[i].nominal.GetValue() * commission.CommissionLevelValue / 100;
                    }
                    else
                    {
                        commission.CommissionNominal = 0;
                    }

                    commission.ClosingID = nextClosingID;

                    Connection.Instance.InsertNewCommission(commission.GetCommissionData());
                }
            }
        }