public bool SaveRdReceipt(RdReceiptDTO ObjRdReceiptDTO, string ConnectionString, out string OUTReceiptid)
        {
            bool          Issaved        = false;
            StringBuilder sbInsert       = new StringBuilder();
            bool          IsAccountSaved = false;
            string        Referenceno    = string.Empty;

            try
            {
                con = new NpgsqlConnection(ConnectionString);
                if (con.State != ConnectionState.Open)
                {
                    con.Open();
                }
                trans = con.BeginTransaction();
                if (ObjRdReceiptDTO.pModeofreceipt != "ADJUSTMENT")
                {
                    if (Savegenaralreceipt(ObjRdReceiptDTO, trans, out OUTReceiptid))
                    {
                        IsAccountSaved = true;
                        Referenceno    = OUTReceiptid;
                    }
                }
                else
                {
                    string adjustrefno = string.Empty;
                    JournalVoucherNewDTO  objJournalVoucherDTO = new JournalVoucherNewDTO();
                    List <PaymentsNewDTO> _Paymentslist        = new List <PaymentsNewDTO>();
                    objJournalVoucherDTO.pjvdate           = ObjRdReceiptDTO.pReceiptdate;
                    objJournalVoucherDTO.pCreatedby        = ObjRdReceiptDTO.pCreatedby;
                    objJournalVoucherDTO.pnarration        = ObjRdReceiptDTO.pNarration;
                    objJournalVoucherDTO.pmodoftransaction = "MANUAL";
                    PaymentsNewDTO objPaymentsDTO = new PaymentsNewDTO
                    {
                        ppartyid     = null,
                        ptranstype   = "C",
                        psubledgerid = ObjRdReceiptDTO.pSubledgerid,
                        pamount      = Convert.ToDecimal(ObjRdReceiptDTO.pReceivedamount)
                    };
                    _Paymentslist.Add(objPaymentsDTO);
                    objPaymentsDTO = new PaymentsNewDTO
                    {
                        ptranstype        = "D",
                        ppartyid          = null,
                        ppartyname        = "",
                        ppartyreferenceid = "",
                        ppartyreftype     = ""
                    };
                    //  long creditaccountid = memberaccountid;
                    objPaymentsDTO.psubledgerid = ObjRdReceiptDTO.pSavingsMemberAccountid;
                    objPaymentsDTO.pamount      = Convert.ToDecimal(ObjRdReceiptDTO.pReceivedamount);
                    _Paymentslist.Add(objPaymentsDTO);
                    objJournalVoucherDTO.pJournalVoucherlist = _Paymentslist;
                    AccountingTransactionsDAL Accontstrans = new AccountingTransactionsDAL();
                    if (Accontstrans.SaveJournalVoucherNew(objJournalVoucherDTO, trans, out adjustrefno))
                    {
                        Referenceno = adjustrefno;
                    }
                }
                if (string.IsNullOrEmpty(ObjRdReceiptDTO.pRecordid.ToString()) || ObjRdReceiptDTO.pRecordid == 0)
                {
                    sbInsert.Append("INSERT INTO Rd_receipt(rd_receipt_date,member_id,rd_account_id,deposit_type, instalment_amount,penalty_amount, received_amount, mode_of_receipt,receipt_no)VALUES('" + FormatDate(ObjRdReceiptDTO.pReceiptdate) + "'," + ObjRdReceiptDTO.pMemberid + "," + ObjRdReceiptDTO.pAccountid + ",'" + ObjRdReceiptDTO.pDeposittype + "'," + ObjRdReceiptDTO.pInstalmentamount + ", " + ObjRdReceiptDTO.pPenaltyamount + "," + ObjRdReceiptDTO.pReceivedamount + ",'" + ObjRdReceiptDTO.pModeofreceipt + "','" + Referenceno + "');");
                }
                if (!string.IsNullOrEmpty(sbInsert.ToString()))
                {
                    NPGSqlHelper.ExecuteNonQuery(trans, CommandType.Text, sbInsert.ToString());
                }
                if (ObjRdReceiptDTO.pModeofreceipt == "CASH" || ObjRdReceiptDTO.pModeofreceipt == "ADJUSTMENT")
                {
                    NPGSqlHelper.ExecuteNonQuery(trans, CommandType.Text, "select fn_rd_instalments_update('" + ObjRdReceiptDTO.pAccountno + "','" + Referenceno + "')");
                }
                trans.Commit();
                Issaved      = true;
                OUTReceiptid = Referenceno;
            }
            catch (Exception ex)
            {
                trans.Rollback();
                throw ex;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Dispose();
                    con.Close();
                    con.ClearPool();
                    trans.Dispose();
                }
            }
            return(Issaved);
        }
        public bool SaveJournalVoucherNew(JournalVoucherNewDTO _JournalVoucherDTO, NpgsqlTransaction trans, out string ptdsrefjvnumber)

        {
            bool          IsSaved = false;
            StringBuilder sbQuery = new StringBuilder();

            try
            {
                if (string.IsNullOrEmpty(_JournalVoucherDTO.pjvnumber))
                {
                    _JournalVoucherDTO.pjvnumber = Convert.ToString(Convert.ToString(NPGSqlHelper.ExecuteScalar(trans, CommandType.Text, "SELECT FN_GENERATENEXTID('JOURNAL VOUCHER','AUTO','" + FormatDate(_JournalVoucherDTO.pjvdate) + "')")));
                }

                ptdsrefjvnumber = _JournalVoucherDTO.pjvnumber;
                string query     = "";
                long   detailsid = 0;
                if (string.IsNullOrEmpty(_JournalVoucherDTO.ptypeofoperation))
                {
                    _JournalVoucherDTO.ptypeofoperation = "CREATE";
                }
                if (_JournalVoucherDTO.ptypeofoperation.ToUpper() == "CREATE")
                {
                    query     = "insert into tbltransjournalvoucher( jvnumber, jvdate, narration, statusid, createdby, createddate,filename,filepath,fileformat,modeoftransaction)values('" + _JournalVoucherDTO.pjvnumber + "', '" + FormatDate(_JournalVoucherDTO.pjvdate) + "', '" + ManageQuote(_JournalVoucherDTO.pnarration) + "',  " + Convert.ToInt32(Status.Active) + ", " + _JournalVoucherDTO.pCreatedby + ", current_timestamp,'" + ManageQuote(_JournalVoucherDTO.pFilename) + "','" + ManageQuote(_JournalVoucherDTO.pFilepath) + "','" + ManageQuote(_JournalVoucherDTO.pFileformat) + "','" + ManageQuote(_JournalVoucherDTO.pmodoftransaction) + "') returning recordid";
                    detailsid = Convert.ToInt64(NPGSqlHelper.ExecuteScalar(trans, CommandType.Text, query));
                }
                else if (_JournalVoucherDTO.ptypeofoperation.ToUpper() == "UPDATE")
                {
                    query     = "select recordid from tbltransjournalvoucher where jvnumber='" + _JournalVoucherDTO.pjvnumber + "';";
                    detailsid = Convert.ToInt64(NPGSqlHelper.ExecuteScalar(trans, CommandType.Text, query));
                    sbQuery.Append("update tbltransjournalvoucher set  modifiedby=" + _JournalVoucherDTO.pCreatedby + ", modifieddate=current_timestamp where jvnumber='" + _JournalVoucherDTO.pjvnumber + "'; ");
                    sbQuery.Append("delete from tbltransjournalvoucherdetails where jvnumber='" + _JournalVoucherDTO.pjvnumber + "'; ");
                    sbQuery.Append("delete from tbltranstotaltransactions where transactionno='" + _JournalVoucherDTO.pjvnumber + "' ;");
                }
                if (_JournalVoucherDTO.pJournalVoucherlist != null)
                {
                    for (int i = 0; i < _JournalVoucherDTO.pJournalVoucherlist.Count; i++)
                    {
                        if (string.IsNullOrEmpty(_JournalVoucherDTO.pJournalVoucherlist[i].ptypeofoperation))
                        {
                            _JournalVoucherDTO.pJournalVoucherlist[i].ptypeofoperation = "CREATE";
                        }
                        if (_JournalVoucherDTO.pJournalVoucherlist[i].ptypeofoperation.ToUpper() == "CREATE")
                        {
                            if (string.IsNullOrEmpty(_JournalVoucherDTO.pJournalVoucherlist[i].ppartyid))
                            {
                                _JournalVoucherDTO.pJournalVoucherlist[i].ppartyid = "0";
                            }
                            sbQuery.Append("insert into tbltransjournalvoucherdetails( detailsid, jvnumber, contactid,contactname,contactrefid,contactreftype, jvaccountid, ledgeramount,accounttranstype, gsttype, gstcalculationtype, tdssection, pannumber, tdscalculationtype, tdspercentage, tdsamount, gstpercentage, igstamount, cgstamount, sgstamount, utgstamount, istdsapplicable,gstnumber,tdsaccountid,stateid,statename)values (" + detailsid + ", '" + ManageQuote(_JournalVoucherDTO.pjvnumber) + "'," + _JournalVoucherDTO.pJournalVoucherlist[i].ppartyid + ",'" + _JournalVoucherDTO.pJournalVoucherlist[i].ppartyname + "','" + ManageQuote(_JournalVoucherDTO.pJournalVoucherlist[i].ppartyreferenceid) + "','" + ManageQuote(_JournalVoucherDTO.pJournalVoucherlist[i].ppartyreftype) + "', " + _JournalVoucherDTO.pJournalVoucherlist[i].psubledgerid + ", " + _JournalVoucherDTO.pJournalVoucherlist[i].pamount + ",'" + _JournalVoucherDTO.pJournalVoucherlist[i].ptranstype + "', '" + _JournalVoucherDTO.pJournalVoucherlist[i].pgsttype + "', '" + _JournalVoucherDTO.pJournalVoucherlist[i].pgstcalculationtype + "', '" + _JournalVoucherDTO.pJournalVoucherlist[i].ptdssection + "', '" + _JournalVoucherDTO.pJournalVoucherlist[i].ppartypannumber + "', '" + _JournalVoucherDTO.pJournalVoucherlist[i].ptdscalculationtype + "', " + _JournalVoucherDTO.pJournalVoucherlist[i].ptdspercentage + ", " + _JournalVoucherDTO.pJournalVoucherlist[i].ptdsamount + ", '" + _JournalVoucherDTO.pJournalVoucherlist[i].pgstpercentage + "', '" + _JournalVoucherDTO.pJournalVoucherlist[i].pigstamount + "', '" + _JournalVoucherDTO.pJournalVoucherlist[i].pcgstamount + "', " + _JournalVoucherDTO.pJournalVoucherlist[i].psgstamount + ", " + _JournalVoucherDTO.pJournalVoucherlist[i].putgstamount + ", " + _JournalVoucherDTO.pJournalVoucherlist[i].pistdsapplicable + ",'" + _JournalVoucherDTO.pJournalVoucherlist[i].pgstno + "'," + _JournalVoucherDTO.pJournalVoucherlist[i].ptdsaccountId + "," + _JournalVoucherDTO.pJournalVoucherlist[i].pStateId + ",'" + _JournalVoucherDTO.pJournalVoucherlist[i].pState + "');");
                        }
                    }
                }

                if (!string.IsNullOrEmpty(_JournalVoucherDTO.pjvnumber))
                {
                    //sbQuery.AppendLine("SELECT fntotaltransactions('" + _JournalVoucherDTO.pjvnumber + "','JOURNALVOUCHER');select accountsupdate();");
                    sbQuery.AppendLine("SELECT fntotaltransactions('" + _JournalVoucherDTO.pjvnumber + "','JOURNALVOUCHER');");
                }

                if (!string.IsNullOrEmpty(sbQuery.ToString()))
                {
                    NPGSqlHelper.ExecuteNonQuery(trans, CommandType.Text, sbQuery.ToString());
                }

                IsSaved = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(IsSaved);
        }