public DataSet ProfitAndLossAnalysis(DateTime dtFromdate, DateTime dtTodate) { DataSet dset = new DataSet(); try { dset = spFinancialStatement.ProfitAndLossAnalysis(dtFromdate, dtTodate); } catch (Exception ex) { MessageBox.Show("FS8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(dset); }
/// <summary> /// Function to fill Datagridview /// </summary> public void Gridfill() { try { if (!isFormLoad) { DateValidation objValidation = new DateValidation(); objValidation.DateValidationFunction(txtFromDate); if (txtFromDate.Text == string.Empty) { txtFromDate.Text = PublicVariables._dtFromDate.ToString("dd-MMM-yyyy"); } objValidation.DateValidationFunction(txtToDate); if (txtToDate.Text == string.Empty) { txtToDate.Text = PublicVariables._dtToDate.ToString("dd-MMM-yyyy"); } Font newFont = new Font(dgvProfitAndLoss.Font, FontStyle.Bold); CurrencyInfo InfoCurrency = new CurrencyInfo(); CurrencySP SpCurrency = new CurrencySP(); InfoCurrency = SpCurrency.CurrencyView(1); int inDecimalPlaces = InfoCurrency.NoOfDecimalPlaces; dgvProfitAndLoss.Rows.Clear(); FinancialStatementSP spFinancial = new FinancialStatementSP(); DataTable dtblFinancial = new DataTable(); DataSet DsetProfitAndLoss = new DataSet(); SettingsInfo infoSettings = new SettingsInfo(); SettingsSP SpSettings = new SettingsSP(); //---------check calculation method if (SpSettings.SettingsStatusCheck("StockValueCalculationMethod") == "FIFO") { calculationMethod = "FIFO"; } else if (SpSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Average Cost") { calculationMethod = "Average Cost"; } else if (SpSettings.SettingsStatusCheck("StockValueCalculationMethod") == "High Cost") { calculationMethod = "High Cost"; } else if (SpSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Low Cost") { calculationMethod = "Low Cost"; } else if (SpSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Last Purchase Rate") { calculationMethod = "Last Purchase Rate"; } DsetProfitAndLoss = spFinancial.ProfitAndLossAnalysis(DateTime.Parse(txtFromDate.Text), DateTime.Parse(txtToDate.Text)); //---- Opening Stock dgvProfitAndLoss.Rows.Add(); decimal dcOpeningStock = spFinancial.StockValueGetOnDate(DateTime.Parse(txtFromDate.Text), DateTime.Parse(txtToDate.Text), calculationMethod, true, false); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtExpenses"].Value = "Opening Stock"; if (dcOpeningStock > 0) { dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = Math.Round(dcOpeningStock, inDecimalPlaces); } else { dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = -(Math.Round(dcOpeningStock, inDecimalPlaces)); } //Closing Stock decimal dcClosingStock = 0; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtIncome"].Value = "Closing Stock"; dcClosingStock = spFinancial.StockValueGetOnDate(DateTime.Parse(txtToDate.Text), calculationMethod, false, false); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = Math.Round(dcClosingStock, inDecimalPlaces); /// ---Purchase Account - Debit dtblFinancial = new DataTable(); dtblFinancial = DsetProfitAndLoss.Tables[0]; dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtExpenses"].Value = "Purchase Accounts"; decimal dcPurchaseAccount = 0m; if (dtblFinancial.Rows.Count > 0) { foreach (DataRow rw in dtblFinancial.Rows) { decimal dcBalance = decimal.Parse(rw["Debit"].ToString().ToString()); dcPurchaseAccount += dcBalance; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtGroupId1"].Value = "11"; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = dcPurchaseAccount.ToString(); //---Sales Account -Credit dtblFinancial = new DataTable(); dtblFinancial = DsetProfitAndLoss.Tables[1]; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtIncome"].Value = "Sales Accounts"; decimal dcSalesAccount = 0m; if (dtblFinancial.Rows.Count > 0) { foreach (DataRow rw in dtblFinancial.Rows) { decimal dcBalance = decimal.Parse(rw["Credit"].ToString().ToString()); dcSalesAccount += dcBalance; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtGroupId2"].Value = "10"; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = dcSalesAccount.ToString(); dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows.Add(); //---Direct Expense dtblFinancial = new DataTable(); dtblFinancial = DsetProfitAndLoss.Tables[2]; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtExpenses"].Value = "Direct Expenses"; decimal dcDirectExpense = 0m; if (dtblFinancial.Rows.Count > 0) { foreach (DataRow rw in dtblFinancial.Rows) { decimal dcBalance = Convert.ToDecimal(rw["Debit"].ToString()); dcDirectExpense += dcBalance; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtGroupId1"].Value = "13"; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = dcDirectExpense.ToString(); //----Direct Income dtblFinancial = new DataTable(); dtblFinancial = DsetProfitAndLoss.Tables[3]; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtIncome"].Value = "Direct Incomes"; decimal dcDirectIncoome = 0m; if (dtblFinancial.Rows.Count > 0) { foreach (DataRow rw in dtblFinancial.Rows) { decimal dcBalance = Convert.ToDecimal(rw["Credit"].ToString()); dcDirectIncoome += dcBalance; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtGroupId2"].Value = "12"; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = dcDirectIncoome.ToString(); dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = "_______________________"; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = "_______________________"; dgvProfitAndLoss.Rows.Add(); decimal dcTotalExpense = 0; decimal dcTotalIncome = 0; dcTotalExpense = dcOpeningStock + dcPurchaseAccount + dcDirectExpense; dcTotalIncome = dcClosingStock + dcSalesAccount + dcDirectIncoome; dcTotalExpense = Math.Round(dcTotalExpense, inDecimalPlaces); dcTotalIncome = Math.Round(dcTotalIncome, inDecimalPlaces); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].DefaultCellStyle.Font = newFont; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtExpenses"].Value = "Total"; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtIncome"].Value = "Total"; decimal dcGrossProfit = 0; decimal dcGrossLoss = 0; if (dcTotalExpense > dcTotalIncome) { dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = dcTotalExpense.ToString(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = dcTotalExpense.ToString(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtIncome"].Value = "Gross Loss b/d "; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtAmount2"].Value = dcTotalExpense - dcTotalIncome; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtAmount2"].Style.ForeColor = Color.Red; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtIncome"].Style.ForeColor = Color.Red; dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtExpenses"].Value = "Gross Loss b/d "; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = dcTotalExpense - dcTotalIncome; dcGrossLoss = dcTotalExpense - dcTotalIncome; } else { dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = dcTotalIncome.ToString(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = dcTotalIncome.ToString(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtExpenses"].Value = "Gross Profit c/d "; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtAmount1"].Value = dcTotalIncome - dcTotalExpense; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtAmount1"].Style.ForeColor = Color.Green; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtExpenses"].Style.ForeColor = Color.Green; dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtIncome"].Value = "Gross Profit c/d "; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = dcTotalIncome - dcTotalExpense; dcGrossProfit = dcTotalIncome - dcTotalExpense; } dgvProfitAndLoss.Rows.Add(); ///------Indirect Expense dtblFinancial = new DataTable(); dtblFinancial = DsetProfitAndLoss.Tables[4]; dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtExpenses"].Value = "Indirect Expenses"; decimal dcIndirectExpense = 0; if (dtblFinancial.Rows.Count > 0) { foreach (DataRow rw in dtblFinancial.Rows) { decimal dcBalance = Convert.ToDecimal(rw["Debit"].ToString()); dcIndirectExpense += dcBalance; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtGroupId1"].Value = "15"; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = dcIndirectExpense.ToString(); ///---Indirect Income dtblFinancial = new DataTable(); dtblFinancial = DsetProfitAndLoss.Tables[5]; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtIncome"].Value = "Indirect Incomes"; decimal dcIndirectIncome = 0m; if (dtblFinancial.Rows.Count > 0) { foreach (DataRow rw in dtblFinancial.Rows) { decimal dcBalance = Convert.ToDecimal(rw["Credit"].ToString()); dcIndirectIncome += dcBalance; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtGroupId2"].Value = "14"; } dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = dcIndirectIncome.ToString(); //---- Calculating Grand total decimal dcGrandTotalExpense = dcGrossLoss + dcIndirectExpense; decimal dcGrandTotalIncome = dcGrossProfit + dcIndirectIncome; dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = "_______________________"; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = "_______________________"; dgvProfitAndLoss.Rows.Add(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtExpenses"].Value = "Grand Total"; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtIncome"].Value = "Grand Total"; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].DefaultCellStyle.Font = newFont; if (dcGrandTotalExpense > dcGrandTotalIncome) { dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = dcGrandTotalExpense.ToString(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = dcGrandTotalExpense.ToString(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtIncome"].Value = "Net Loss "; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtAmount2"].Value = dcGrandTotalExpense - dcGrandTotalIncome; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtIncome"].Style.ForeColor = Color.Red; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtAmount2"].Style.ForeColor = Color.Red; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].DefaultCellStyle.Font = newFont; decgranExTotal = dcGrandTotalExpense; } else { dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = dcGrandTotalIncome.ToString(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = dcGrandTotalIncome.ToString(); dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtExpenses"].Value = "Net Profit"; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtAmount1"].Value = dcGrandTotalIncome - dcGrandTotalExpense; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtExpenses"].Style.ForeColor = Color.Green; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].Cells["dgvtxtAmount1"].Style.ForeColor = Color.Green; dgvProfitAndLoss.Rows[dgvProfitAndLoss.Rows.Count - 3].DefaultCellStyle.Font = newFont; decgranIncTotal = dcGrandTotalIncome; } if (dgvProfitAndLoss.Columns.Count > 0) { dgvProfitAndLoss.Columns["dgvtxtAmount1"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dgvProfitAndLoss.Columns["dgvtxtAmount2"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; } if (inCurrenRowIndex >= 0 && dgvProfitAndLoss.Rows.Count > 0 && inCurrenRowIndex < dgvProfitAndLoss.Rows.Count) { if (dgvProfitAndLoss.Rows[inCurrenRowIndex].Cells[inCurrentColunIndex].Visible) { dgvProfitAndLoss.CurrentCell = dgvProfitAndLoss.Rows[inCurrenRowIndex].Cells[inCurrentColunIndex]; } else { dgvProfitAndLoss.CurrentCell = dgvProfitAndLoss.Rows[inCurrenRowIndex].Cells["dgvtxtExpenses"]; } dgvProfitAndLoss.CurrentCell.Selected = true; } inCurrenRowIndex = 0; } } catch (Exception ex) { MessageBox.Show("PAL :01" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }