// DESCRIPTION: Creates a payment record and updates the balance of the reservation
    public bool makePayment(int userID, int confirmationID, double amountPaid, string paymentMethod, bool usedRewards, DateTime currentDate, string ccNumber)
    {
        // create payment record
        DBConnect    makePaymentConn = new DBConnect();
        MySqlCommand makePayment     = new MySqlCommand(@"INSERT INTO dbo.payment(customerID, confirmationID, amountPaid, paymentMethod, usedRewards,created, ccNum)
                                                    VALUES(@userID, @confID, @amountPaid, @paymentMethod, @usedRewards, @created, @ccNum)");

        makePayment.Parameters.Add("@userID", MySqlDbType.Int32).Value              = userID;
        makePayment.Parameters.Add("@confID", MySqlDbType.Int32).Value              = confirmationID;
        makePayment.Parameters.Add("@amountPaid", MySqlDbType.Decimal).Value        = amountPaid;
        makePayment.Parameters.Add("@paymentMethod", MySqlDbType.VarChar, 45).Value = paymentMethod;
        makePayment.Parameters.Add("@usedRewards", MySqlDbType.Bit).Value           = usedRewards;
        makePayment.Parameters.Add("@created", MySqlDbType.Date).Value              = currentDate;
        makePayment.Parameters.Add("@ccNum", MySqlDbType.VarChar, 45).Value         = ccNumber;

        if (makePaymentConn.NonQuery(makePayment) > 0)
        {// update balance and amount paid on reservation
            if (usedRewards)
            {
                Reward updateRewards = new Reward();
                updateRewards.setRewardsPoints(userID, -50, userID, currentDate);
            }

            // get payment ID
            makePayment.CommandText = "SELECT paymentID from dbo.payment where customerID = @userID and confirmationID = @confID and amountPaid = @amountPAid and paymentMethod = @paymentMethod and usedRewards = @usedRewards and created = @created and ccNum = @ccNum";

            int payID = makePaymentConn.intScalar(makePayment);

            // log payment
            LoggedActivity logPayment = new LoggedActivity();
            logPayment.logActivity(userID, 8, payID, currentDate, userID);

            // update reservation amount
            Reservation payReservation = new Reservation(confirmationID);
            payReservation.amountDue  = payReservation.totalPrice - amountPaid;
            payReservation.amountPaid = payReservation.amountPaid + amountPaid;

            MySqlCommand updateRes = new MySqlCommand(@"UPDATE reservation
                                                        SET
                                                        amountDue = @amountDue,
                                                        amountPaid = @amountPaid
                                                        WHERE confirmationID = @confirmationID");
            updateRes.Parameters.Add("@amountDue", MySqlDbType.Decimal).Value    = payReservation.amountDue;
            updateRes.Parameters.Add("@amountPaid", MySqlDbType.Decimal).Value   = payReservation.amountPaid;
            updateRes.Parameters.Add("@confirmationID", MySqlDbType.Int32).Value = payReservation.confirmatonID;
            if (makePaymentConn.NonQuery(updateRes) > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }
    // DESCRIPTION: Adds cancellation to activity log
    public bool logCancellation(int cancelledBy, int userID, DateTime currentDate)
    {
        LoggedActivity logCancellation = new LoggedActivity();

        if (logCancellation.logActivity(userID, 3, this.confirmatonID, currentDate, cancelledBy))
        {
            return(true);
        }
        return(false);
    }
    public bool checkOutReservation(DateTime currentDate)
    {
        //update status
        status = "checked-out";
        //add checkout activity log
        LoggedActivity logCheckout = new LoggedActivity();

        logCheckout.logActivity(userID, 5, this.confirmatonID, currentDate, 17);
        //update customer rewards point balance
        Reward checkoutReward = new Reward();

        checkoutReward.setRewardsPoints(userID, points, 17, currentDate);
        //update reservation price
        if (endDate != currentDate)
        {
            endDate = currentDate;
            Utilities recalc      = new Utilities();
            Room      roomDetails = new Room(roomNumList[0], locationID);
            totalPrice = recalc.calculatePrice(((endDate - startDate).TotalDays), roomDetails.price);
            if ((endDate - startDate).TotalDays == 0)
            {
                //cancelation fee
                totalPrice = recalc.getMinCharge();
                status     = "cancelled";
            }

            points    = Convert.ToInt32(recalc.calculatePoints(((endDate - startDate).TotalDays)));
            amountDue = totalPrice - amountPaid;
        }
        //charge customer remaining balance on reservation
        try
        {
            PaymentRecord checkoutPayment = new PaymentRecord();
            DBConnect     checkinConn     = new DBConnect();
            MySqlCommand  cmd             = new MySqlCommand("SELECT ccNum from dbo.payment where confirmationID = @confirm");
            cmd.Parameters.Add("@confirm", MySqlDbType.Int32).Value = confirmatonID;
            DBConnect ccNumConn = new DBConnect();
            string    ccNum     = ccNumConn.stringScalar(cmd);
            ccNumConn.CloseConnection();
            checkoutPayment.makePayment(userID, confirmatonID, amountDue, "Credit Card", false, currentDate, ccNum);
            amountPaid += amountDue;
            amountDue   = 0;
        }
        catch (Exception ex)
        {
            MessageBox.Show("Unable to retrieve previous credit card number." + ex);
        }
        if (updateReservation(this))
        {
            MessageBox.Show("Reservation with confirmation id " + confirmatonID + " was checked out.");
            return(true);
        }
        return(false);
    }
    public bool checkInReservation(DateTime currentDate)
    {
        if (startDate != currentDate)
        {
            startDate = currentDate;
            Utilities recalc      = new Utilities();
            Room      roomDetails = new Room(roomNumList[0], locationID);
            totalPrice = recalc.calculatePrice(((endDate - startDate).TotalDays), roomDetails.price);
            points     = Convert.ToInt32(recalc.calculatePoints(((endDate - startDate).TotalDays)));
            amountDue  = totalPrice - amountPaid;
        }
        LoggedActivity logCheckin = new LoggedActivity();

        logCheckin.logActivity(userID, 4, this.confirmatonID, currentDate, 17);
        status = "checked-in";
        if (updateReservation(this))
        {
            MessageBox.Show("Reservation with confirmation id " + confirmatonID + " was checked in.");
            return(true);
        }
        return(false);
    }
Esempio n. 5
0
 private void btnModify_Click(object sender, EventArgs e)
 {
     // log customer-requested upgrade
     if ((checkFreeUpgrade.Checked == false))
     {
         modResInfo.totalPrice = price;
         LoggedActivity customerUpdate = new LoggedActivity();
         customerUpdate.logActivity(modResInfo.userID, 2, modResInfo.confirmatonID, currentDate, modResInfo.userID);
     }
     else
     {
         // log employee-initiated upgrade
         LoggedActivity employeeUpdate = new LoggedActivity();
         employeeUpdate.logActivity(modResInfo.userID, 2, modResInfo.confirmatonID, currentDate, resUserID);
     }
     // update reservation
     modResInfo.locationID  = Convert.ToInt32(cboxHotel.SelectedValue);
     modResInfo.numGuests   = Convert.ToInt32(cboxNumGuests.SelectedItem);
     modResInfo.startDate   = startDate.Value;
     modResInfo.endDate     = endDate.Value;
     modResInfo.roomNumList = roomNumList;
     modResInfo.amountDue   = price - modResInfo.amountPaid;
     modResInfo.points      = points;
     if (modResInfo.updateReservation(modResInfo) == true)
     {
         lblError.ForeColor = System.Drawing.Color.Green;
         lblError.Visible   = true;
         lblError.Text      = "Reservation has been modified";
     }
     else
     {
         displayError("Unable to modify reservation");
     }
     if (endDate.Value == currentDate)
     {
         modResInfo.checkOutReservation(currentDate);
     }
 }
    // DESCRIPTION: Adds reservation to dbo.reservation and activity log
    public int makeReservation(int locationID, int newResUserID, int resUserID, DateTime startDate, DateTime endDate, double newResPrice, int newResPoints, List <int> newResRoomList, int numGuests, DateTime currentDate)
    {
        int          confirmationID = -1;
        DBConnect    createResConn  = new DBConnect();
        MySqlCommand createResCmd   = new MySqlCommand("INSERT INTO `dbo`.`reservation`(`confirmationID`,`userID`,`locationID`,`roomNum`,`startDate`,`endDate`,`pointsAccumulated`,`price`,`amountDue`,`amountPaid`,`reservationStatus`,`created`,`numGuests`) VALUES(@confirmationID,@userID,@locationID,@roomNum,@startDate,@endDate,@points,@price,@price,0,@status,@created,@numGuests)");

        DBConnect    getNextConfConn = new DBConnect();
        MySqlCommand cmd             = new MySqlCommand("select confirmationID from dbo.reservation order by confirmationID desc limit 1");

        confirmationID = getNextConfConn.intScalar(cmd) + 1;

        createResCmd.Parameters.Add("@roomNum", MySqlDbType.Int32);
        createResCmd.Parameters.Add("@locationID", MySqlDbType.Int32).Value     = locationID;
        createResCmd.Parameters.Add("@userID", MySqlDbType.Int32).Value         = resUserID;
        createResCmd.Parameters.Add("@startDate", MySqlDbType.Date).Value       = startDate;
        createResCmd.Parameters.Add("@endDate", MySqlDbType.Date).Value         = endDate;
        createResCmd.Parameters.Add("@confirmationID", MySqlDbType.Int32).Value = confirmationID;
        createResCmd.Parameters.Add("@points", MySqlDbType.Int32).Value         = newResPoints;
        createResCmd.Parameters.Add("@price", MySqlDbType.Decimal).Value        = newResPrice;
        createResCmd.Parameters.Add("@status", MySqlDbType.VarChar, 45).Value   = "upcoming";
        createResCmd.Parameters.Add("@created", MySqlDbType.Date).Value         = currentDate;
        createResCmd.Parameters.Add("@numGuests", MySqlDbType.Int32).Value      = numGuests;

        // insert one row for each room
        foreach (int newResRoomNum in newResRoomList)
        {
            createResCmd.Parameters["@roomNum"].Value = newResRoomNum;
            createResConn.NonQuery(createResCmd);
        }
        if (confirmationID != -1)
        {
            LoggedActivity logNewRes = new LoggedActivity();
            logNewRes.logActivity(resUserID, 1, confirmationID, currentDate, newResUserID);
        }
        return(confirmationID);
    }