public BillingDataTypes.PendingPaymentDataType TransformBillToPending(BillingDataTypes.BillingDataType _DataIn) { BillingDataTypes.PendingPaymentDataType _TransForm = new BillingDataTypes.PendingPaymentDataType(); _TransForm.AccountID = _DataIn.AccountID; _TransForm.AccPeriod = _DataIn.AccPeriod; _TransForm.BillNo = _DataIn.BillNo; _TransForm.BillStatus = 0; _TransForm.CompanyID = _DataIn.CompanyID ; _TransForm.Cr = _DataIn.Cr ; _TransForm.CurRate = _DataIn.CurRate; _TransForm.Description = _DataIn.Description; _TransForm.FCr = _DataIn.FCr; _TransForm.PayedAmount =0; _TransForm.Supplier = _DataIn.PayToID; _TransForm.TobePayDate = _DataIn.TobePayDate; _TransForm.BillDate = _DataIn.TrDate; return _TransForm; }
public string DoBillTransaction(BillingDataTypes.BillingDataType _SaveData) { Billing MyBill= new Billing(IsLocalLoging); try { MySql.Data.MySqlClient.MySqlTransaction Mytrans; MySqlConnection CurCon = new MySqlConnection(); CurCon = Mycommon.AccountConnection; string respond = ""; decimal FullPayment = 0; if (CurCon.State == ConnectionState.Open) { CurCon.Close(); CurCon.Open(); } else { CurCon.Open(); } Mytrans = Mycommon.AccountConnection.BeginTransaction(); MySqlCommand oSqlCommand = new MySqlCommand(); string MainAccountRef = "", TrReference = "", PVNNumber = ""; MainAccountRef = GetAccReference(_SaveData.AccountID, CurCon); int Counter = 0; string DrAccRef = ""; string macAdd = MyGeneral.GetMACAddress(); foreach (BillingDataTypes.BillingDetailsDataType _OneData in _SaveData.BillingDetails) { AccountTransactionType.AccountTransactionDataType _OneTrans = new AccountTransactionType.AccountTransactionDataType(); string TransRefDr = ""; string AccRef = GetAccReference(_OneData.AccID, CurCon); Counter += 1; if (Counter < 5) DrAccRef = DrAccRef + "," + AccRef; _OneTrans.AccountID = _OneData.AccID; _OneTrans.AccountYear = _SaveData.AccPeriod; _OneTrans.ActualDate = _SaveData.BillDate; _OneTrans.CompanyID = _SaveData.CompanyID; _OneTrans.Cr = 0; _OneTrans.CurRate = _SaveData.CurRate; _OneTrans.Description = _OneData.Description; _OneTrans.Dr = _OneData.Dr; _OneTrans.FCr = 0; _OneTrans.FDr = _OneData.Fdr ; _OneTrans.MainRef = AccRef; _OneTrans.PayMethod = 5; _OneTrans.RelRef = MainAccountRef; _OneTrans.TransType = 2; _OneTrans.TrMachine = macAdd; _OneTrans.TrUser = _SaveData.TrUser; _OneTrans.VoucherID = _SaveData.BillNo; FullPayment = FullPayment + _OneData.Dr; respond = SaveAccountTransaction(_OneTrans, CurCon, out TransRefDr); if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } else { respond = UpdateTranseRefinReleventTable(2, true, TransRefDr, _SaveData.BillNo, _OneData.ItemNo.ToString(), CurCon); if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } else { respond = UpdateLastRefonAccount(_OneTrans.AccountID, AccRef, CurCon); if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } } } } if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } else { AccountTransactionType.AccountTransactionDataType _SaveTranData = new AccountTransactionType.AccountTransactionDataType(); _SaveTranData.AccountID = _SaveData.AccountID; //1 _SaveTranData.AccountYear = _SaveData.AccPeriod; //2 _SaveTranData.Description = _SaveData.Description; //3 _SaveTranData.CompanyID = _SaveData.CompanyID; //4 _SaveTranData.Cr = _SaveData.Cr; //5 _SaveTranData.CurRate = _SaveData.CurRate; //6 _SaveTranData.Dr = 0; //7 _SaveTranData.FCr = _SaveData.FCr ; //8 _SaveTranData.FDr = 0; //9 _SaveTranData.MainRef = MainAccountRef; //10 _SaveTranData.PayMethod = 5; //11 _SaveTranData.TrID = TrReference; //12 _SaveTranData.TransType = 2; //13 _SaveTranData.RelRef = DrAccRef; //14 _SaveTranData.TrMachine = macAdd; //14 _SaveTranData.VoucherID = _SaveData.BillNo; //15 _SaveTranData.TrUser = _SaveData.TrUser; //16 _SaveTranData.ActualDate = _SaveData.BillDate; respond = SaveAccountTransaction(_SaveTranData, CurCon, out TrReference); if ( FullPayment != _SaveData.Cr) { Mytrans.Rollback(); CurCon.Close(); return "Amount Not balance"; } if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } else { respond = UpdateTranseRefinReleventTable(2, false, TrReference, _SaveData.BillNo, "", CurCon); if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } else { respond = UpdateLastRefonAccount(_SaveData.AccountID, MainAccountRef, CurCon); if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } else { BillingDataTypes.PendingPaymentDataType _SavependingData = new BillingDataTypes.PendingPaymentDataType(); _SavependingData.AccountID = _SaveData.AccountID; _SavependingData.AccPeriod = _SaveData.AccPeriod; _SavependingData.BillDate = _SaveData.BillDate; _SavependingData.BillNo = _SaveData.BillNo; _SavependingData.BillStatus = 0; _SavependingData.CompanyID = _SaveData.CompanyID; _SavependingData.Cr = _SaveData.Cr; _SavependingData.CurRate = _SaveData.CurRate; _SavependingData.Description = _SaveData.Description; _SavependingData.FCr = _SaveData.FCr; _SavependingData.PayedAmount = 0; _SavependingData.Supplier = _SaveData.PayToID; _SavependingData.TobePayDate = _SaveData.TobePayDate; _SavependingData.TotalAmount = _SaveData.Cr; respond = MyBill.SavePP(_SavependingData, CurCon); if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } else { //respond = SetBillGetToLog(_SaveData.BillNo, _SaveData.PayToID); Mytrans.Commit(); CurCon.Close(); return "True"; } } } } } } catch (Exception ex) { return ex.Message; } }
public string Update(BillingDataTypes.BillingDataType _SaveData) { MySql.Data.MySqlClient.MySqlTransaction Mytrans; MySqlConnection CurCon = new MySqlConnection(); CurCon = Mycommon.AccountConnection; string respond = ""; if (CurCon.State == ConnectionState.Closed) CurCon.Open(); Mytrans = Mycommon.AccountConnection.BeginTransaction(); MySqlCommand oSqlCommand = new MySqlCommand(); respond = UpdateBilling(_SaveData, CurCon); if (respond != "True") { Mytrans.Rollback(); return respond; } else { BillingDataTypes.PendingPaymentDataType _BillLog = new BillingDataTypes.PendingPaymentDataType(); _BillLog = TransformBillToPending(_SaveData); if (!ExistPendingPaymentInTrans(_SaveData.CompanyID, _SaveData.BillNo, CurCon)) respond = SavePendingPaymentInTrans(_BillLog, CurCon); else respond = UpdatePendingPayment(_BillLog, CurCon); if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } else { foreach (BillingDataTypes.BillingDetailsDataType _OneItem in _SaveData.BillingDetails) { if (!ExistBillingDetails(_OneItem.ItemNo, _OneItem.BillNo, CurCon)) { respond = SaveBillingDetailsinTrance(_OneItem, CurCon); if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } } else { respond = UpdateBillingDetails(_OneItem, CurCon); if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } } } if (respond != "True") { Mytrans.Rollback(); CurCon.Close(); return respond; } else { Mytrans.Commit(); CurCon.Close(); return "True"; } } } }
public string GetExistPendingPayment(int CompanyID, string BillNo, out BillingDataTypes.PendingPaymentDataType _ExistData) { _ExistData = new BillingDataTypes.PendingPaymentDataType(); MySqlCommand oSqlCommand = new MySqlCommand(); string sqlQuery = "Select " + "CompanyID," + "BillNo," + "Description," + "AccountID," + "CurRate," + "Cr," + "FCr," + "BillStatus," + "AccPeriod," + "Supplier," + "TotalAmount," + "PayedAmount," + "TobePayDate" + " from tblpendingpayablebill" + " Where 1=1 " + " and CompanyID=@CompanyID" + " and BillNo=@BillNo"; oSqlCommand.Parameters.AddWithValue("@CompanyID", CompanyID); oSqlCommand.Parameters.AddWithValue("@BillNo", BillNo); DataRow r = Mycommon.GetDataRowAccount(sqlQuery, oSqlCommand, "Get Exist data PendingPayment"); if (r != null) { try { bool resp = false; int inCompanyID = 0; resp = int.TryParse(r["CompanyID"].ToString(), out inCompanyID); _ExistData.CompanyID = inCompanyID; _ExistData.BillNo = r["BillNo"].ToString(); _ExistData.Description = r["Description"].ToString(); _ExistData.AccountID = r["AccountID"].ToString(); decimal deCurRate = 0; resp = decimal.TryParse(r["CurRate"].ToString(), out deCurRate); _ExistData.CurRate = deCurRate; decimal deCr = 0; resp = decimal.TryParse(r["Cr"].ToString(), out deCr); _ExistData.Cr = deCr; decimal deFCr = 0; resp = decimal.TryParse(r["FCr"].ToString(), out deFCr); _ExistData.FCr = deFCr; int inBillStatus = 0; resp = int.TryParse(r["BillStatus"].ToString(), out inBillStatus); _ExistData.BillStatus = inBillStatus; int inAccPeriod = 0; resp = int.TryParse(r["AccPeriod"].ToString(), out inAccPeriod); _ExistData.AccPeriod = inAccPeriod; int inSupplier = 0; resp = int.TryParse(r["Supplier"].ToString(), out inSupplier); _ExistData.Supplier = inSupplier; decimal deTotalAmount = 0; resp = decimal.TryParse(r["TotalAmount"].ToString(), out deTotalAmount); _ExistData.TotalAmount = deTotalAmount; decimal dePayedAmount = 0; resp = decimal.TryParse(r["PayedAmount"].ToString(), out dePayedAmount); _ExistData.PayedAmount = dePayedAmount; DateTime dtTobePayDate = new DateTime(1900, 1, 1); resp = DateTime.TryParse(r["TobePayDate"].ToString(), out dtTobePayDate); if (resp) _ExistData.TobePayDate = dtTobePayDate; else _ExistData.TobePayDate = new DateTime(1900, 1, 1); DateTime dtBillDate = new DateTime(1900, 1, 1); resp = DateTime.TryParse(r["BillDate"].ToString(), out dtBillDate); if (resp) _ExistData.BillDate = dtBillDate; else _ExistData.BillDate = new DateTime(1900, 1, 1); return "True"; } catch (Exception ex) { return ex.Message; } } else return "data not found "; }