CentralAZ / Rock-CentralAZ

An open source CMS, Relationship Management System (RMS), Church Management System (ChMS), and composable application framework.
http://www.rockrms.com
17 stars 3 forks source link

Approving/Denying Locations/Resources on Copied reservation actually updates original reservation. #170

Open azturner opened 4 years ago

azturner commented 4 years ago

Prerequisites

Description

If you copy a reservation that has a location and/or resource. You are not able to approve or deny that location or resource on the copied reservation. When you attempt to, nothing changes on the existing reservation, but the original reservation is updated with the approval/denial that you are attempting to make on the copy.

This appears to be due to the fact that when copying a reservation, the copied ReservationLocation and ReservationResource record have the same guid as the original records. So when attempting to approve or deny the copy, the code is updating those records based on first matching guid which is actually the records from first reservation.

Steps to Reproduce

  1. Copy a reservation that has one or more locations and/or resources
  2. Try to approve the location or resource on the copied reservation

Expected behavior:

The location/resource is actually updated to reflect that it was approved or denied

Actual behavior:

Nothing visibly changes, but if you view the original reservation that current reservation was copied from, it's location and resource is updated.

Versions

azturner commented 4 years ago

FYI, we ran this query to update the existing copied ReservationLocation and ReservationResource records so that they had their own unique guid and was then able to approve the locations/resources:

update r2 set guid = newid()
from _com_centralaz_RoomManagement_ReservationLocation r1
inner join _com_centralaz_RoomManagement_ReservationLocation r2 on r2.guid = r1.Guid and r2.ReservationId > r1.ReservationId
cross apply (
    select min(reservationid) as firstid
    from _com_centralaz_RoomManagement_ReservationLocation
    where guid = r1.Guid
) f
where r1.ReservationId = f.firstid

update r2 set guid = newid()
from _com_centralaz_RoomManagement_ReservationResource r1
inner join _com_centralaz_RoomManagement_ReservationResource r2 on r2.guid = r1.Guid and r2.ReservationId > r1.ReservationId
cross apply (
    select min(reservationid) as firstid
    from _com_centralaz_RoomManagement_ReservationResource
    where guid = r1.Guid
) f
where r1.ReservationId = f.firstid