public void PaymentBooking(TransactionGroup transactionGroup, Booking bookingPay, double usd, double vnd, double rate)
        {
            double totalPaidUSD = 0;
            double totalPaidVND = 0;

            foreach (var t in bookingPay.Transactions)
            {
                if (t.TransactionType == Transaction.BOOKING)
                {
                    totalPaidUSD += t.USDAmount;
                    totalPaidVND += t.VNDAmount;
                }
            }

            var transaction = new Transaction()
            {
                Agency           = bookingPay.Agency,
                Booking          = bookingPay,
                CreatedBy        = CurrentUser,
                CreatedDate      = DateTime.Now,
                IsExpense        = false,
                TransactionType  = Transaction.BOOKING,
                USDAmount        = usd,
                VNDAmount        = vnd,
                TransactionGroup = transactionGroup
            };

            if (bookingPay.IsTotalUsd || usd > 0)
            {
                transaction.AppliedRate = rate;
            }
            BookingPaymentBLL.TransactionSaveOrUpdate(transaction);

            totalPaidUSD += transaction.USDAmount;
            totalPaidVND += transaction.VNDAmount;

            bookingPay.Paid     = totalPaidUSD;
            bookingPay.PaidBase = totalPaidVND;
            if (bookingPay.IsTotalUsd || usd > 0)
            {
                bookingPay.CurrencyRate = rate;
            }
            if (bookingPay.MoneyLeft <= 0)
            {
                bookingPay.IsPaid = true;
            }

            bookingPay.PaidDate = DateTime.Now;

            bookingPay.AgencyConfirmed = false;
            BookingPaymentBLL.BookingSaveOrUpdate(bookingPay);
        }
예제 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            double appliedRate;
            double currentRate = BookingPaymentBLL.USDRateGetByDate(DateTime.Now).Rate;

            if (txtAppliedRate.Text != string.Empty)
            {
                appliedRate = Convert.ToDouble(txtAppliedRate.Text);
            }
            else
            {
                appliedRate = 0;
            }


            double usdPaid = Convert.ToDouble(txtPaid.Text);
            double vndPaid = Convert.ToDouble(txtPaidBase.Text);

            usdPaid += Booking.Paid;
            vndPaid += Booking.PaidBase;
            try
            {
                if (Booking.IsTotalUsd && Convert.ToDouble(txtAppliedRate.Text) > 1)
                {
                    Booking.CurrencyRate = Convert.ToDouble(txtAppliedRate.Text);
                }
            }
            catch (Exception) { }

            double paidUSD = 0.0;

            try
            {
                paidUSD = Convert.ToDouble(txtPaid.Text);
            }
            catch (Exception) { }

            double paidVND = 0.0;

            try
            {
                paidVND = Convert.ToDouble(txtPaidBase.Text);
            }
            catch (Exception) { }

            double totalPaidUSD = 0;
            double totalPaidVND = 0;

            foreach (var t in Booking.Transactions)
            {
                if (t.TransactionType == Transaction.BOOKING)
                {
                    totalPaidUSD += t.USDAmount;
                    totalPaidVND += t.VNDAmount;
                }
            }

            var transaction = new Transaction()
            {
                Agency          = Booking.Agency,
                Booking         = Booking,
                CreatedBy       = CurrentUser,
                CreatedDate     = DateTime.Now,
                IsExpense       = false,
                TransactionType = Transaction.BOOKING,
                USDAmount       = paidUSD,
                VNDAmount       = paidVND,
                Note            = txtNote.Text,
            };

            if (Convert.ToDouble(txtAppliedRate.Text) > 1)
            {
                transaction.AppliedRate = Convert.ToDouble(txtAppliedRate.Text);
            }
            BookingPaymentBLL.TransactionSaveOrUpdate(transaction);

            totalPaidUSD += transaction.USDAmount;
            totalPaidVND += transaction.VNDAmount;

            Booking.Paid     = totalPaidUSD;
            Booking.PaidBase = totalPaidVND;

            bool temp;

            temp           = Booking.IsPaid;
            Booking.IsPaid = false;
            if (Booking.AgencyReceivable == 0)
            {
                chkPaid.Checked = true;
            }
            Booking.IsPaid = temp;

            if (Booking.IsPaid != chkPaid.Checked)
            {
                Booking.IsPaid = chkPaid.Checked;
                if (Booking.IsPaid)
                {
                    Booking.PaidDate = DateTime.Now;
                }
            }
            Booking.AgencyConfirmed = false;
            BookingPaymentBLL.BookingSaveOrUpdate(Booking);
            ClientScript.RegisterStartupScript(this.GetType(), "RefreshParentPage", "<script>window.parent.location.href = window.parent.location.href;</script>");
        }