コード例 #1
0
        BookingFinancialPaymentContract BookingFinancialPaymentsNew(
            Guid bookingId,
            string financialPaymentTypeRcd,
            Guid?financialPaymentId,
            Guid?financialCurrencyId,
            Guid?financialVoucherId
            )
        {
            // fix null's
            if (financialPaymentId == null)
            {
                financialPaymentId = Guid.Empty;
            }
            if (financialCurrencyId == null)
            {
                financialCurrencyId = Guid.Empty;
            }
            if (financialVoucherId == null)
            {
                financialVoucherId = Guid.Empty;
            }

            // fetch booking data
            var bookingFinancialPayment =
                new BookingFinancialPaymentContract(
                    bookingId,
                    Logging.UserId(User.Identity, ViewBag)
                    );

            // booking
            bookingFinancialPayment.BookingId = bookingId;

            bookingFinancialPayment.BookingBalanceFinancialCurrencyId =
                bookingFinancialPayment.BookingContract.Booking.FinancialCurrencyId;

            ViewBag.BookingBalanceFinancialCurrencyName =
                new CrudeFinancialCurrencyServiceClient().FetchByFinancialCurrencyId(
                    bookingFinancialPayment.BookingBalanceFinancialCurrencyId
                    ).FinancialCurrencyTypeName;

            // new payment
            if (financialPaymentId == Guid.Empty)
            {
                // get booking balance
                bookingFinancialPayment.BookingBalanceAmount =
                    new BookingServiceClient().BookingFinancialBalance(
                        bookingId);

                if (financialCurrencyId != Guid.Empty)
                {
                    // payment in new(selected) currency
                    bookingFinancialPayment.PaymentFinancialCurrencyId =
                        ( Guid )financialCurrencyId;

                    CrudeFinancialCurrencyContract currency =
                        new CrudeFinancialCurrencyServiceClient().FetchByFinancialCurrencyId(
                            bookingFinancialPayment.PaymentFinancialCurrencyId);

                    CrudeFinancialCurrencyTypeRefContract paymentCurrency =
                        new CrudeFinancialCurrencyTypeRefServiceClient().FetchByFinancialCurrencyTypeRcd(
                            currency.FinancialCurrencyAgainstFinancialCurrencyTypeRcd);

                    ViewBag.PaymentFinancialCurrencyName = paymentCurrency.FinancialCurrencyTypeName;

                    bookingFinancialPayment.PaymentAmount =
                        bookingFinancialPayment.BookingBalanceAmount * currency.EqualsAmount;

                    bookingFinancialPayment.PaymentBookingCurrencyAmount =
                        bookingFinancialPayment.BookingBalanceAmount;
                }
                else
                {
                    // payment in booking currency
                    bookingFinancialPayment.PaymentFinancialCurrencyId =
                        bookingFinancialPayment.BookingContract.Booking.FinancialCurrencyId;

                    bookingFinancialPayment.PaymentAmount =
                        bookingFinancialPayment.BookingBalanceAmount;

                    bookingFinancialPayment.PaymentBookingCurrencyAmount =
                        bookingFinancialPayment.BookingBalanceAmount;

                    ViewBag.PaymentFinancialCurrencyName =
                        new CrudeFinancialCurrencyServiceClient().FetchByFinancialCurrencyId(
                            bookingFinancialPayment.PaymentFinancialCurrencyId
                            ).FinancialCurrencyTypeName;
                }

                bookingFinancialPayment.PaymentFinancialCostcentreId =
                    bookingFinancialPayment.BookingContract.Booking.FinancialCostcentreId;
            }

            // payments
            bookingFinancialPayment.Payments =
                new BookingSearchService().BookingFinancialPayments(bookingId);

            bookingFinancialPayment.PaymentFinancialPaymentTypeRcd = financialPaymentTypeRcd;

            // get previous payment ( for viewing )
            if (financialPaymentId != Guid.Empty)
            {
                bookingFinancialPayment.PaymentContract =
                    new CrudeFinancialPaymentServiceClient().FetchByFinancialPaymentId(
                        ( Guid )financialPaymentId);
            }
            else
            {
                // get available currencies
                bookingFinancialPayment.PaymentSelectedFinancialCurrencyId =
                    bookingFinancialPayment.PaymentFinancialCurrencyId;

                ViewBag.PaymentSelectedFinancialCurrencyId =
                    new SelectList(new FinancialSearchService().
                                   GetAvailableCurrencies(
                                       bookingFinancialPayment.BookingBalanceFinancialCurrencyId,
                                       DateTime.UtcNow
                                       ),
                                   "FinancialCurrencyId",
                                   "FinancialCurrencyTypeName",
                                   bookingFinancialPayment.PaymentSelectedFinancialCurrencyId
                                   );
            }

            // payment type specific
            if (financialPaymentTypeRcd.Contains(FinancialPaymentTypeRef.Card))
            {
                // card
                if (financialPaymentId != Guid.Empty)
                {
                    bookingFinancialPayment.CardContract =
                        new CrudeFinancialPaymentCardServiceClient().FetchByFinancialPaymentCardId(
                            bookingFinancialPayment.PaymentContract.FinancialPaymentCardId);
                }

                ViewBag.FinancialCardTypeRcd =
                    new SelectList(new CrudeFinancialCardTypeRefServiceClient().FetchAll(),
                                   "FinancialCardTypeRcd",
                                   "FinancialCardTypeName",
                                   bookingFinancialPayment.FinancialCardTypeRcd);
            }
            else if (financialPaymentTypeRcd.Contains(FinancialPaymentTypeRef.Cash))
            {
                // cash
                if (financialPaymentId != Guid.Empty)
                {
                    bookingFinancialPayment.CashContract =
                        new CrudeFinancialPaymentCashServiceClient().FetchByFinancialPaymentCashId(
                            bookingFinancialPayment.PaymentContract.FinancialPaymentCashId);
                }
            }
            else if (financialPaymentTypeRcd.Contains(FinancialPaymentTypeRef.Bank))
            {
                // bank
                if (financialPaymentId != Guid.Empty)
                {
                    bookingFinancialPayment.BankContract =
                        new CrudeFinancialPaymentBankServiceClient().FetchByFinancialPaymentBankId(
                            bookingFinancialPayment.PaymentContract.FinancialPaymentBankId);
                }

                ViewBag.FinancialBankAccountNumberTypeRcd =
                    new SelectList(new CrudeFinancialBankAccountNumberTypeRefServiceClient().FetchAll(),
                                   "FinancialBankAccountNumberTypeRcd",
                                   "FinancialBankAccountNumberTypeName",
                                   bookingFinancialPayment.FinancialBankAccountNumberTypeRcd);
            }
            else if (financialPaymentTypeRcd.Contains(FinancialPaymentTypeRef.Voucher))
            {
                // voucher
                if (financialPaymentId == Guid.Empty)
                {
                    bookingFinancialPayment.Vouchers =
                        new FinancialSearchService().VoucherSearchWithRemainingAmount(DateTime.UtcNow);
                }
            }

            return(bookingFinancialPayment);
        }
コード例 #2
0
        public ActionResult BookingFinancialPayments(
            [Bind()] BookingFinancialPaymentContract bookingFinancialPayment,
            Guid?financialPaymentId,
            Guid?financialCurrencyId,
            Guid?financialVoucherId
            )
        {
            if (ModelState.IsValid)
            {
                // reload if no currency is selected
                if (financialCurrencyId != null && financialCurrencyId != bookingFinancialPayment.PaymentSelectedFinancialCurrencyId)
                {
                    return(RedirectToAction(
                               "BookingFinancialPayments",
                               new {
                        bookingId = bookingFinancialPayment.BookingId,
                        financialPaymentTypeRcd = bookingFinancialPayment.PaymentFinancialPaymentTypeRcd,
                        financialPaymentId = Guid.Empty,
                        financialCurrencyId = bookingFinancialPayment.PaymentSelectedFinancialCurrencyId
                    }
                               ));
                }

                // currency selected, make payment
                bookingFinancialPayment.PaymentFinancialCurrencyId = bookingFinancialPayment.PaymentSelectedFinancialCurrencyId;

                if (bookingFinancialPayment.PaymentFinancialPaymentTypeRcd.Contains(FinancialPaymentTypeRef.Card))
                {
                    // card
                    bookingFinancialPayment.CardContract.Amount = bookingFinancialPayment.PaymentAmount;
                    bookingFinancialPayment.CardContract.FinancialCurrencyId = bookingFinancialPayment.PaymentFinancialCurrencyId;

                    new BookingServiceClient()
                    .PaymentCardAdd(
                        bookingFinancialPayment.BookingId,
                        bookingFinancialPayment.PaymentBookingCurrencyAmount,
                        0,
                        bookingFinancialPayment.BookingBalanceFinancialCurrencyId,
                        bookingFinancialPayment.CardContract,
                        bookingFinancialPayment.PaymentFinancialCostcentreId,
                        Logging.UserId(User.Identity, ViewBag)
                        );
                }
                else if (bookingFinancialPayment.PaymentFinancialPaymentTypeRcd.Contains(FinancialPaymentTypeRef.Cash))
                {
                    // cash
                    new BookingServiceClient()
                    .PaymentCashAdd(
                        bookingFinancialPayment.BookingId,
                        bookingFinancialPayment.PaymentAmount,
                        0,
                        bookingFinancialPayment.PaymentFinancialCurrencyId,
                        bookingFinancialPayment.PaymentBookingCurrencyAmount,
                        0,
                        bookingFinancialPayment.BookingBalanceFinancialCurrencyId,
                        bookingFinancialPayment.PaymentFinancialCostcentreId,
                        Logging.UserId(User.Identity, ViewBag)
                        );
                }
                else if (bookingFinancialPayment.PaymentFinancialPaymentTypeRcd.Contains(FinancialPaymentTypeRef.Bank))
                {
                    // bank
                    new BookingServiceClient()
                    .PaymentBankAdd(
                        bookingFinancialPayment.BookingId,
                        bookingFinancialPayment.PaymentAmount,
                        0,
                        bookingFinancialPayment.PaymentFinancialCurrencyId,
                        bookingFinancialPayment.PaymentBookingCurrencyAmount,
                        0,
                        bookingFinancialPayment.BookingBalanceFinancialCurrencyId,
                        bookingFinancialPayment.BankContract.FinancialBankAccountNumberTypeRcd,
                        bookingFinancialPayment.BankContract.BankName,
                        bookingFinancialPayment.BankContract.BankAccount,
                        bookingFinancialPayment.BankContract.BankNumber,
                        bookingFinancialPayment.PaymentFinancialCostcentreId,
                        Logging.UserId(User.Identity, ViewBag)
                        );
                }
                else if (bookingFinancialPayment.PaymentFinancialPaymentTypeRcd.Contains(FinancialPaymentTypeRef.Voucher))
                {
                    // voucher
                    new BookingServiceClient()
                    .PaymentVoucherAdd(
                        bookingFinancialPayment.BookingId,
                        ( Guid )financialVoucherId,
                        bookingFinancialPayment.PaymentAmount,
                        0,
                        bookingFinancialPayment.PaymentFinancialCurrencyId,
                        bookingFinancialPayment.PaymentBookingCurrencyAmount,
                        0,
                        bookingFinancialPayment.BookingBalanceFinancialCurrencyId,
                        bookingFinancialPayment.PaymentFinancialCostcentreId,
                        Logging.UserId(User.Identity, ViewBag)
                        );
                }

                return(RedirectToAction(
                           "BookingFinancialPayments",
                           new {
                    bookingId = bookingFinancialPayment.BookingId,
                    financialPaymentTypeRcd = bookingFinancialPayment.PaymentFinancialPaymentTypeRcd,
                    financialPaymentId = Guid.Empty,
                    financialCurrencyId = Guid.Empty
                }
                           ));
            }

            return(View(
                       MVCHelper.Resolve(Request, "", "Booking", "BookingFinancialPayments"),
                       BookingFinancialPaymentsNew(
                           bookingFinancialPayment.BookingId,
                           bookingFinancialPayment.PaymentFinancialPaymentTypeRcd,
                           Guid.Empty,
                           Guid.Empty,
                           Guid.Empty
                           )
                       ));
        }