In this when I try to insert the data it absolutely inserts the data in database tables, but in the tblTransaction table the data is not inserting.
This is the SaleEntry.cs file to handle the insertion (C# Code)
public class SaleEntry
{
private CloudErpVEntities db = new CloudErpVEntities();
public string selectcustomerid = string.Empty;
DataTable dtEntries = null;
public string ConfirmSale(int CompanyID, int BranchID, int UserID, string InvoiceNo, string CustomerInvoiceID, float Amount, string CustomerID, string Customername, bool isPayment)
{
try
{
dtEntries = null;
string saletitle = "Sale To " + Customername.Trim();
var financialCheck = DatabaseQuery.Retrive("select top 1 FinancialYearID from tblFinancialYear where IsActive = 1");
string FinancialYearID = (financialCheck != null ? Convert.ToString(financialCheck.Rows[0][0]) : string.Empty);
if (string.IsNullOrEmpty(FinancialYearID))
{
return "Your Company Financial Year is not Set Please Contact to Adminstrator!";
}`
string successmessage = "Sale Success";
string AccountHeadID = string.Empty;
string AccountControlID = string.Empty;
string AccountSubControlID = string.Empty;
var saleAccount = db.tblAccountSettings.Where(a => a.AccountActivityID == 5 && a.CompanyID == CompanyID && a.BranchID == BranchID).FirstOrDefault();
//Credit Entry Sale
AccountHeadID = Convert.ToString(saleAccount.AccountHeadID);
AccountControlID = Convert.ToString(saleAccount.AccountControlID);
AccountSubControlID = Convert.ToString(saleAccount.AccountSubControlID);
string transectiontitle = string.Empty;
transectiontitle = "Sale To " + Customername.Trim();
//SetEntries(FinancialYearID, AccountHeadID, AccountControlID, AccountSubControlID, InvoiceNo, UserID.ToString(), "0", Convert.ToString(Amount), DateTime.Now, transectiontitle);
SetEntries(FinancialYearID, AccountHeadID, AccountSubControlID, AccountSubControlID, CompanyID.ToString(), BranchID.ToString(), InvoiceNo, UserID.ToString(), Convert.ToString(Amount), "0", DateTime.Now, transectiontitle);
//Debit Entry Sale
saleAccount = db.tblAccountSettings.Where(a => a.AccountActivityID == 8 && a.CompanyID == CompanyID && a.BranchID == BranchID).FirstOrDefault();
if (saleAccount == null)
{
return "Sale Account (i.e. Sale Payment Pending/Succeed) not found in your <b>Account Flow</b>.";
}
AccountHeadID = Convert.ToString(saleAccount.AccountHeadID);
AccountControlID = Convert.ToString(saleAccount.AccountControlID);
AccountSubControlID = Convert.ToString(saleAccount.AccountSubControlID);
transectiontitle = Customername.Trim() + " , Sale Payment is Pending!";
//SetEntries(FinancialYearID, AccountHeadID, AccountControlID, AccountSubControlID, InvoiceNo, UserID.ToString(), "0", Convert.ToString(Amount), DateTime.Now, transectiontitle);
SetEntries(FinancialYearID, AccountHeadID, AccountSubControlID, AccountSubControlID, CompanyID.ToString(), BranchID.ToString(), InvoiceNo, UserID.ToString(), "0", Convert.ToString(Amount), DateTime.Now, transectiontitle);
if (isPayment == true)
{
string payinvoicenno = "INP" + DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond;
saleAccount = db.tblAccountSettings.Where(a => a.AccountActivityID == 8 && a.CompanyID == CompanyID && a.BranchID == BranchID).FirstOrDefault();
AccountHeadID = Convert.ToString(saleAccount.AccountHeadID);
AccountControlID = Convert.ToString(saleAccount.AccountControlID);
AccountSubControlID = Convert.ToString(saleAccount.AccountSubControlID);
transectiontitle = "Sale Payment Paid By " + Customername;
SetEntries(FinancialYearID, AccountHeadID, AccountSubControlID, AccountSubControlID, CompanyID.ToString(), BranchID.ToString(), payinvoicenno, UserID.ToString(), Convert.ToString(Amount), "0", DateTime.Now, transectiontitle);
saleAccount = db.tblAccountSettings.Where(a => a.AccountActivityID == 12 && a.CompanyID == CompanyID && a.BranchID == BranchID).FirstOrDefault();
AccountHeadID = Convert.ToString(saleAccount.AccountHeadID);
AccountControlID = Convert.ToString(saleAccount.AccountControlID);
AccountSubControlID = Convert.ToString(saleAccount.AccountSubControlID);
transectiontitle = Customername + " , Sale Payment is Succesed!";
SetEntries(FinancialYearID, AccountHeadID, AccountControlID, AccountSubControlID, CompanyID.ToString(), BranchID.ToString(), payinvoicenno, UserID.ToString(), "0", Convert.ToString(Amount), DateTime.Now, transectiontitle);
string paymentquery = string.Format("insert into tblCustomerPayment(CustomerID,CustomerInvoiceID,UserID,invoiceNo,TotalAmount,PaidAmount,RemainingBalance,CompanyID,BranchID) " +
"values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
CustomerID, CustomerInvoiceID, UserID, payinvoicenno, Amount, Amount, "0", CompanyID, BranchID);
DatabaseQuery.Insert(paymentquery);
successmessage = successmessage + " with Payment.";
}
foreach (DataRow entryrow in dtEntries.Rows)
{
string entryquery = string.Format("insert into tblTransaction(FinancialYearID,AccountHeadID,AccountControlID,AccountSubControlID,UserID,InvoiceNo,Credit,Debit,TransectionDate,TransactionTitle,CompanyID,BranchID) " +
"values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')",
Convert.ToString(entryrow[0]), Convert.ToString(entryrow[1]), Convert.ToString(entryrow[2]), Convert.ToString(entryrow[3]), Convert.ToString(entryrow[4]), Convert.ToString(entryrow[5]), Convert.ToString(entryrow[6]), Convert.ToString(entryrow[7]), (entryrow[8]), Convert.ToString(entryrow[9]), CompanyID, BranchID);
DatabaseQuery.Insert(entryquery);
}
return successmessage;
}
catch (Exception ex)
{
return $"Unexpected Error: {ex.Message}. Please try Again!";
}
}
private void SetEntries(
string FinancialYearID, string AccountControlID,
string AccountSubControlID, string AccountHeadID,
string CompanyID, string BranchID, string InvoiceNo,
string UserID, string Credit, string Debit,
DateTime TransacctionDate, string TransactionTitle)
{
if (dtEntries == null)
{
dtEntries = new DataTable();
dtEntries.Columns.Add("FinancialYearID");
dtEntries.Columns.Add("AccountControlID");
dtEntries.Columns.Add("AccountSubControlID");
dtEntries.Columns.Add("AccountHeadID");
dtEntries.Columns.Add("CompanyID");
dtEntries.Columns.Add("BranchID");
dtEntries.Columns.Add("InvoiceNo");
dtEntries.Columns.Add("UserID");
dtEntries.Columns.Add("Credit");
dtEntries.Columns.Add("Debit");
dtEntries.Columns.Add("TransacctionDate");
dtEntries.Columns.Add("TransactionTitle");
}
if (dtEntries != null)
{
dtEntries.Rows.Add(
FinancialYearID,
AccountControlID,
AccountSubControlID,
AccountHeadID,
CompanyID,
BranchID,
InvoiceNo,
UserID,
Credit,
Debit,
TransacctionDate,
TransactionTitle);
}
}
}
Query of inserting data in transaction table
foreach (DataRow entryrow in dtEntries.Rows)
{
string entryquery = string.Format("insert into tblTransaction(FinancialYearID,AccountHeadID,AccountControlID,AccountSubControlID,UserID,InvoiceNo,Credit,Debit,TransectionDate,TransactionTitle,CompanyID,BranchID) " +
"values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')",
Convert.ToString(entryrow[0]), Convert.ToString(entryrow[1]), Convert.ToString(entryrow[2]), Convert.ToString(entryrow[3]), Convert.ToString(entryrow[4]), Convert.ToString(entryrow[5]), Convert.ToString(entryrow[6]), Convert.ToString(entryrow[7]), (entryrow[8]), Convert.ToString(entryrow[9]), CompanyID, BranchID);
DatabaseQuery.Insert(entryquery);
}
Another other query of inserting the payment details is works perfect.
IF any addition information need please let me know.
9
foreach (DataRow entryrow in dtEntries.Rows)
{
string entryquery = string.Format("insert into tblTransaction(FinancialYearID,AccountHeadID,AccountControlID,AccountSubControlID,UserID,InvoiceNo,Credit,Debit,TransectionDate,TransactionTitle,CompanyID,BranchID) " +
"values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')",
Convert.ToString(entryrow[0]), Convert.ToString(entryrow[1]), Convert.ToString(entryrow[2]), Convert.ToString(entryrow[3]), Convert.ToString(entryrow[4]), Convert.ToString(entryrow[5]), Convert.ToString(entryrow[6]), Convert.ToString(entryrow[7]), (entryrow[8]), Convert.ToString(entryrow[9]), CompanyID, BranchID);
DatabaseQuery.Insert(entryquery);
}
- Here you are making all are string type that not properly converted to db column types
- Please check the column datatype so that it will not fail the insertion