Exemplo n.º 1
0
        public int ProcessCommission(string[] data)
        {
            int i = 0;

            foreach (string SaleID in data)
            {
                int      TotalCommission = GetCommission(SaleID);
                string   BusinessID      = GetBusinessID(SaleID);
                DateTime LastUpdated     = DateTime.Now;
                var      Validation      = GetCurrentCommision(BusinessID);
                int      NewBalance;
                if (Validation.ValidChecker.Length > 1)
                {
                    string[] validChecker = SystemTools.Decrypt(Validation.ValidChecker.ToString().Trim()).Split(',');
                    DateTime validDate    = Convert.ToDateTime(validChecker[0]);
                    int      validAmount  = int.Parse(validChecker[1]);

                    if (validAmount != Convert.ToInt32(Validation.AvailableBalance) && validDate != Validation.DateUpdated)
                    {
                        return(99);
                    }
                    NewBalance = validAmount + TotalCommission;
                }
                else
                {
                    NewBalance = 0 + TotalCommission;
                }

                string NewValidChecker = SystemTools.EncryptPass(LastUpdated.ToString("yyyy-MM-dd HH:mm:ss") + "," + NewBalance);
                try
                {
                    using (SqlConnection con = new SqlConnection(VendorConn))
                    {
                        con.Open();
                        using (SqlCommand com = new SqlCommand("UPDATE tbl_comm set actual_bal=actual_bal-@TotalCommission,available_bal=@NewBalance,ValidChecker=@NewValidChecker,DateUpdated=@DateUpdated WHERE business_id=@BusinessID", con))
                        {
                            com.Parameters.AddWithValue("@TotalCommission", TotalCommission);
                            com.Parameters.AddWithValue("@NewBalance", NewBalance);
                            com.Parameters.AddWithValue("@NewValidChecker", NewValidChecker);
                            com.Parameters.AddWithValue("@DateUpdated", LastUpdated);
                            com.Parameters.AddWithValue("@BusinessID", BusinessID);
                            i = com.ExecuteNonQuery();
                        }
                    }
                    SQLExecutor("Update tbl_sales_details set status=1 where sale_id='" + SaleID + "'");
                }
                catch (Exception ex)
                {
                }
            }
            return(i);
        }