public bool Remove(PaymentVendorDetail data, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(false);
            };

            bool result;

            try
            {
                result = Remove(data, oConn);
            }
            catch (Exception ex)
            {
                ConnManager.CloseConn(oConn);
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                return(false);
            }

            ConnManager.CloseConn(oConn);

            return(result);
        }
        private bool Remove(PaymentVendorDetail data, SqlConnection oConn)
        {
            string sql = "DELETE FROM PaymentVendorDetails " +
                         " WHERE (PayVendorDetailId = @id)";

            SqlCommand cmd = new SqlCommand(sql, oConn);

            cmd.Parameters.Add("@id", SqlDbType.Int).Value = data.PayVendorDetailId;

            int number = Convert.ToInt32(cmd.ExecuteNonQuery());

            if (number > 0)
            {
                return(true);
            }

            return(false);
        }
        public PaymentVendorDetail Add(PaymentVendorDetail data, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                throw;
            };

            string sql = "INSERT INTO PaymentVendorDetails ({0}) VALUES ({1}) " +
                         "SELECT SCOPE_IDENTITY()";

            EnumExtension.setListValues(data, "PayVendorDetailId", ref sql);

            SqlCommand cmd = new SqlCommand(sql, oConn);

            int keyGenerated = 0;

            try
            {
                keyGenerated = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                ConnManager.CloseConn(oConn);
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(null);
            }

            PaymentVendorDetail returnData = Get(keyGenerated, oConn);

            ConnManager.CloseConn(oConn);

            return(returnData);
        }
        public PaymentVendorDetail Get(int id, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(null);
            };

            PaymentVendorDetail data = Get(id, oConn);

            ConnManager.CloseConn(oConn);

            return(data);
        }
        public PaymentVendorDetail Update(PaymentVendorDetail data, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                throw;
            };

            string sql = "UPDATE PaymentVendorDetails SET {0} WHERE PayVendorDetailId = @id";

            EnumExtension.setUpdateValues(data, "PayVendorDetailId", ref sql);

            SqlCommand cmd = new SqlCommand(sql, oConn);

            cmd.Parameters.Add("@id", SqlDbType.Int).Value = data.PayVendorDetailId;

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ConnManager.CloseConn(oConn);
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(null);
            }

            PaymentVendorDetail returnData = Get(data.PayVendorDetailId, oConn);

            ConnManager.CloseConn(oConn);

            return(returnData);
        }
Exemple #6
0
        public bool Pay(int VendorId, string UserId, Payment Paid, ref string msg)
        {
            decimal       amount = 0, amountNB = 0, currencyRate = 0;
            string        reference = "";
            PaymentVendor payHeader = new PaymentVendor();

            payHeader.PayVendorCreatedBy   = UserId;
            payHeader.PayVendorCreatedDate = DateTime.Now;

            // Add into database pay Header
            payHeader = repPayHead.Add(payHeader, ref msg);

            //Insert into database details
            foreach (var pov in Paid.PaidDetail)
            {
                PaymentVendorDetail payDetail = new PaymentVendorDetail();
                payDetail.PayModeID                   = pov.PayModeID;
                payDetail.PayVendorId                 = payHeader.PayVendorId;
                payDetail.PayVendorDetailAmount       = pov.PayVendorDetailAmount;
                payDetail.PayVendorDetailAmountNB     = pov.PayVendorDetailAmountNB;
                payDetail.PayVendorDetailCurrencyRate = pov.PayVendorDetailCurrencyRate;
                payDetail.PayVendorDetailReference    = pov.PayVendorDetailReference;
                payDetail.AccountID                   = pov.AccountID;
                payDetail.PayVendorDetailDate         = pov.PayVendorDetailDate;
                payDetail.PayVendorDetailComments     = pov.PayVendorDetailComments;

                amount      += pov.PayVendorDetailAmount;
                amountNB    += pov.PayVendorDetailAmountNB;
                currencyRate = pov.PayVendorDetailCurrencyRate;
                reference   += "/" + pov.PayVendorDetailReference;

                payDetail = repPayDetail.Add(payDetail, ref msg);
            }

            // insert details to pay
            decimal thisPaid = 0, thisPaidNB = 0;

            foreach (var pov in Paid.POVList)
            {
                thisPaid   = pov.x_InvoiceVendorBalance.GetValueOrDefault();
                thisPaidNB = pov.x_InvoiceVendorBalanceNB.GetValueOrDefault();

                POVendorsDetail povDetail = new POVendorsDetail();
                povDetail.POVDetailAmount        = -thisPaid;
                povDetail.POVDetailAmountNB      = -thisPaidNB;
                povDetail.POVDetailCreatedBy     = UserId;
                povDetail.POVDetailCreatedDate   = DateTime.Now;
                povDetail.POVDetailCurrencyRate  = currencyRate;
                povDetail.POVDetailDate          = DateTime.Now;
                povDetail.POVDetailPaymentNumber = !string.IsNullOrEmpty(reference) ? reference.Substring(1) : reference;
                povDetail.POVId         = pov.POVId;
                povDetail.POVDetailType = "PB";
                povDetail.PayVendorId   = payHeader.PayVendorId;

                povDetail = repPOV.AddDetail(povDetail, ref msg);
            }

            foreach (var file in Paid.Files)
            {
                IDictionary <string, object> data = new Dictionary <string, object>();
                data["AttachId"]    = file.AttachId;
                data["AttachDirty"] = false;
                data["PayVendorId"] = payHeader.PayVendorId;
                repAtt.Update(data, UserId, ref msg);
            }
            //msg = String.Format("{0:#,###.00} and {1:#,###.00}", amount, amountNB);
            return(true);
        }