Exemplo n.º 1
0
        public async Task <IActionResult> Putreserved_rooms([FromRoute] int id, [FromBody] reserved_rooms reserved_rooms)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != reserved_rooms.id)
            {
                return(BadRequest());
            }

            _context.Entry(reserved_rooms).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!reserved_roomsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Postreserved_rooms([FromBody] reserved_rooms reserved_rooms)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.reserved_rooms.Add(reserved_rooms);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Getreserved_rooms", new { id = reserved_rooms.id }, reserved_rooms));
        }
Exemplo n.º 3
0
        public IActionResult post_reservations([FromBody] Posted_Data data)
        {
            var bookingForm  = data.bookingForm;
            var userForm     = data.userForm;
            var businessForm = data.businessForm;
            var rooms        = data.rms;
            var paymentForm  = data.paymentForm;


            var userId = int.Parse(userForm.id);

            accounts ac = null;

            if (userId > 0)
            {
                ac             = _context.accounts.Where(a => a.id == userId).FirstOrDefault();
                ac.address1    = userForm.address1;
                ac.address2    = userForm.address2;
                ac.city        = userForm.city;
                ac.country     = userForm.country;
                ac.email       = userForm.email;
                ac.fax         = userForm.fax;
                ac.first_name  = userForm.first_name;
                ac.last_name   = userForm.last_name;
                ac.phone       = userForm.phone;
                ac.postal_code = userForm.postal_code;
                ac.state       = userForm.state;
                _context.SaveChanges();
            }
            else
            {
                ac = new accounts();
                ac.account_number = CHIS.Core.Infrastructure.AccountGenerator.Generate(10);
                var account_type = _context.account_types.Select(a => a).OrderBy(a => a.id).FirstOrDefault();
                if (account_type != null)
                {
                    ac.account_type_id = account_type.id;
                }
                ac.address1         = userForm.address1;
                ac.address2         = userForm.address2;
                ac.alias            = "AC";
                ac.card_holder      = "";
                ac.city             = userForm.city;
                ac.country          = userForm.country;
                ac.created          = DateTime.Now;
                ac.created_by       = "1";
                ac.created_on       = DateTime.Now;
                ac.credit_card_type = "";
                ac.credit_limit     = 500M;
                ac.email            = userForm.email;
                ac.exp_date         = DateTime.Now;
                ac.fax             = userForm.fax;
                ac.first_name      = userForm.first_name;
                ac.last_name       = userForm.last_name;
                ac.modified        = DateTime.Now;
                ac.opening_balance = 0M;
                ac.payment_term    = 0M;
                ac.phone           = userForm.phone;
                ac.postal_code     = userForm.postal_code;
                ac.reg_number      = "";
                ac.reg_number1     = "";
                ac.reg_number2     = "";
                ac.remark          = "";
                ac.state           = userForm.state;
                _context.accounts.Add(ac);
                _context.SaveChanges();
            }



            var rs = new reservations();

            rs.account_id = ac.id;
            var arrival_string   = bookingForm.arrival.Split("/");
            var new_arrival_date = String.Format("{0}-{1}-{2}", arrival_string[2], arrival_string[0], arrival_string[1]);

            rs.arrival            = DateTime.Parse(new_arrival_date);
            rs.book_by            = bookingForm.book_by;
            rs.book_on            = DateTime.Now;
            rs.business_source_id = int.Parse(businessForm.business_source_id);
            rs.code               = Guid.NewGuid().ToString();
            rs.created            = DateTime.Now;
            rs.departure          = rs.arrival.Value.AddDays(int.Parse(bookingForm.num_of_night));
            rs.modified           = DateTime.Now;
            rs.num_of_night       = int.Parse(bookingForm.num_of_night);
            rs.reservation_number = CHIS.Core.Infrastructure.AccountGenerator.Generate(8);
            rs.reservation_status = "Reserved";
            rs.account_number     = paymentForm.account_number;
            var onDiscounts = Boolean.Parse(paymentForm.apply_discount);

            if (onDiscounts)
            {
                rs.apply_discount = 1;
                rs.discount_code  = paymentForm.discount_code;
                rs.discount_plan  = int.Parse(paymentForm.discount_plan);
                rs.discount_value = Decimal.Parse(paymentForm.discount_value);
            }
            else
            {
                rs.apply_discount = 0;
                rs.discount_code  = "";
                //rs.discount_plan = 0;
                rs.discount_value = 0M;
            }

            rs.bank_name   = paymentForm.bank_name;
            rs.branch_name = paymentForm.branch_name;
            rs.cheque      = paymentForm.cheque;


            rs.amount_paid     = Decimal.Parse(paymentForm.amount);
            rs.balance         = Decimal.Parse(paymentForm.balance);
            rs.total_booking   = Decimal.Parse(paymentForm.total_amount);
            rs.payment_status  = "incomplete";
            rs.last_payment_id = 0;



            _context.reservations.Add(rs);
            _context.SaveChanges();



            foreach (var room in rooms)
            {
                var dd = new reserved_rooms();
                dd.arrival         = rs.arrival;
                dd.balance         = Decimal.Parse(paymentForm.balance);
                dd.created         = rs.created;
                dd.departure       = DateTime.Now;
                dd.modified        = DateTime.Now;
                dd.num_of_night    = rs.num_of_night;
                dd.original_owner  = ac.first_name + " " + ac.last_name;
                dd.paid            = Decimal.Parse(paymentForm.amount);
                dd.reservation_id  = rs.id;
                dd.modified        = DateTime.Now;
                dd.reserved_status = "Reserved";
                dd.room_id         = int.Parse(room.id);
                dd.room_type_id    = int.Parse(room.room_type_id);
                dd.serial_number   = CHIS.Core.Infrastructure.AccountGenerator.Generate(8);
                dd.status          = "Open";
                dd.total           = Decimal.Parse(paymentForm.total_amount);
                dd.transfer_owner  = "";
                dd.num_of_night    = rs.num_of_night;
                dd.num_of_adult    = int.Parse(room.extra_adult);
                dd.num_of_children = int.Parse(room.extra_children);
                dd.room_name       = room.room_name;
                dd.room_type_name  = room.room_type_name;

                _context.reserved_rooms.Add(dd);
                _context.SaveChanges();



                rs.reserved_rooms.Add(dd);
            }

            foreach (var rr in rs.reserved_rooms)
            {
                for (int i = 0; i < rs.num_of_night; i++)
                {
                    var tran = new reservation_transaction();
                    var rate = getRoomRate(rs.arrival.Value.AddDays(i), rr.room_type_id);
                    tran.total_reservation = rate.amount.Value;
                    tran.total_children    = rr.num_of_children * rate.extra_child;
                    tran.total_adult       = rr.num_of_adult * rate.extra_adult;
                    tran.total             = tran.total_adult + tran.total_children + tran.total_reservation;
                    tran.balance           = tran.total;
                    tran.created           = DateTime.Now;
                    tran.modified          = DateTime.Now;
                    tran.paid             = Decimal.Parse(paymentForm.amount);
                    tran.rate             = rate.amount;
                    tran.reservation_id   = rs.id;
                    tran.reserved_room_id = rr.id;
                    tran.status           = "Reserved";
                    tran.transaction_date = rs.arrival.Value.AddDays(i);
                    tran.rate_type        = _context.rate_types.Where(a => a.id == rate.rate_type_id).FirstOrDefault().rate_type_name;
                    tran.rate_name        = rate.rate_name;

                    tran.payment_method = paymentForm.payment_method;
                    tran.room_name      = rr.room_name;
                    tran.room_Type      = rr.room_type_name;
                    _context.reservation_transaction.Add(tran);
                    _context.SaveChanges();
                    rs.reservation_transaction.Add(tran);
                }
            }

            reservation_payments payment = new reservation_payments();

            payment.created          = DateTime.Now;
            payment.modified         = DateTime.Now;
            payment.paid             = Decimal.Parse(paymentForm.amount);
            payment.payment_method   = paymentForm.payment_method;
            payment.reservation_id   = rs.id;
            payment.status           = "";
            payment.total_amount     = Decimal.Parse(paymentForm.total_amount);
            payment.transaction_date = DateTime.Now;
            payment.transaction_type = "Reservation Payment";
            payment.balance          = Decimal.Parse(paymentForm.balance);

            var apply_discount = Boolean.Parse(paymentForm.apply_discount);

            if (apply_discount)
            {
                payment.on_discount = 1;
                var discount = 0M;
                decimal.TryParse(paymentForm.discount_value, out discount);
                payment.discount_value = discount;
                var discount_id  = int.Parse(paymentForm.discount_plan);
                var MainDiscount = _context.discount_plans.Where(a => a.id == discount_id).FirstOrDefault();
                payment.discount_name = MainDiscount.plan_name;
                if (MainDiscount.plan_category.Trim() == "c100")
                {
                    var discount2 = (payment.discount_value / 100M) * payment.total_amount;
                    payment.total_amount_with_discount = payment.total_amount.Value - discount2.Value;
                    payment.balance    = payment.total_amount_with_discount - payment.paid;
                    rs.discount_amount = discount2.Value;
                }
                else
                {
                    var amount = payment.total_amount - payment.discount_value;
                    payment.total_amount_with_discount = amount.Value;
                    payment.balance    = payment.total_amount_with_discount - payment.paid;
                    rs.discount_amount = payment.discount_value;
                }
            }
            else
            {
                payment.on_discount                = 0;
                payment.discount_name              = "";
                payment.discount_type              = 0;
                payment.discount_value             = 0;
                payment.total_amount_with_discount = 0M;
            }
            _context.reservation_payments.Add(payment);
            _context.SaveChanges();

            rs.total_amount_with_discount = payment.total_amount_with_discount;
            rs.balance         = payment.balance;
            rs.last_payment_id = payment.id;
            if (rs.balance <= 0)
            {
                rs.payment_status = "Completed";
            }
            else
            {
                rs.payment_status = "Incomplete";
            }

            _context.SaveChanges();

            rs = _context.reservations.Where(a => a.id == rs.id).Include(a => a.account_).Include(a => a.reservation_payments).Include(a => a.reserved_rooms).FirstOrDefault();


            return(Ok(rs));
        }
Exemplo n.º 4
0
        public IActionResult get_total_reservation_rate([FromBody] Posted_Data data)
        {
            var bookingForm  = data.bookingForm;
            var userForm     = data.userForm;
            var businessForm = data.businessForm;
            var rooms        = data.rms;



            var rs               = new reservations();
            var arrival_string   = bookingForm.arrival.Split("/");
            var new_arrival_date = String.Format("{0}-{1}-{2}", arrival_string[2], arrival_string[0], arrival_string[1]);

            rs.arrival      = DateTime.Parse(new_arrival_date);
            rs.arrival_time = bookingForm.arrival_time;


            rs.departure    = rs.arrival.Value.AddDays(int.Parse(bookingForm.num_of_night));
            rs.num_of_night = int.Parse(bookingForm.num_of_night);



            foreach (var room in rooms)
            {
                var dd = new reserved_rooms();
                dd.arrival         = rs.arrival;
                dd.arrival_time    = rs.arrival_time;
                dd.balance         = 0M;
                dd.created         = rs.created;
                dd.departure       = DateTime.Now;
                dd.departure_time  = "";
                dd.modified        = DateTime.Now;
                dd.num_of_night    = rs.num_of_night;
                dd.paid            = 0M;
                dd.modified        = DateTime.Now;
                dd.reserved_status = "Open";
                dd.room_id         = int.Parse(room.id);
                dd.room_type_id    = int.Parse(room.room_type_id);
                dd.num_of_night    = rs.num_of_night;
                dd.num_of_adult    = int.Parse(room.extra_adult);
                dd.num_of_children = int.Parse(room.extra_children);
                dd.room_name       = room.room_name;
                dd.room_type_name  = room.room_type_name;
                rs.reserved_rooms.Add(dd);
            }

            foreach (var rr in rs.reserved_rooms)
            {
                for (int i = 0; i < rs.num_of_night; i++)
                {
                    var tran = new reservation_transaction();
                    var rate = getRoomRate(rs.arrival.Value.AddDays(i), rr.room_type_id);
                    tran.total_reservation = rate.amount.Value;
                    tran.total_children    = rr.num_of_children * rate.extra_child;
                    tran.total_adult       = rr.num_of_adult * rate.extra_adult;
                    tran.total             = tran.total_adult + tran.total_children + tran.total_reservation;
                    tran.balance           = tran.total;
                    tran.created           = DateTime.Now;
                    tran.modified          = DateTime.Now;
                    tran.paid             = 0M;
                    tran.rate             = rate.amount;
                    tran.reservation_id   = rs.id;
                    tran.reserved_room_id = rr.id;
                    tran.status           = "Open";
                    tran.transaction_date = rs.arrival.Value.AddDays(i);
                    tran.rate_type        = _context.rate_types.Where(a => a.id == rate.rate_type_id).FirstOrDefault().rate_type_name;
                    tran.rate_name        = rate.rate_name;
                    tran.reserved_room_   = rr;

                    rs.reservation_transaction.Add(tran);
                }
            }



            return(Ok(rs));
        }