INSERT INTO tenant_rental_rate (tenant_id, rental_rate, start_date, end_date, status, created_at)
SELECT id, rental_rate, start_date,end_date,status, created_at  FROM tenants

--RUN CODE UNTUK TABLE LOCATIONS DAN RECEIPT NUMBER
--TABLE LOCATIONS START
ALTER TABLE `locations` 
MODIFY created_at TIMESTAMP,
MODIFY updated_at TIMESTAMP
DEFAULT CURRENT_TIMESTAMP 
NOT NULL

--pastikan column created_at DAN updated_at NOT NULL = NO, KLU YES RUN CODE BAWAH NI:
--next
ALTER TABLE `locations` 
MODIFY created_at TIMESTAMP
DEFAULT CURRENT_TIMESTAMP 
NOT NULL;
--next 
ALTER TABLE `locations` 
MODIFY updated_at TIMESTAMP
DEFAULT CURRENT_TIMESTAMP 
NOT NULL;

--next ini
ALTER TABLE `locations` CHANGE `location_code` `location_code` VARCHAR(10) NOT NULL;
--TABLE LOCATIONS END

--run code ni dulu
ALTER TABLE `receipt_number` 
MODIFY created_at TIMESTAMP,
MODIFY updated_at TIMESTAMP
DEFAULT CURRENT_TIMESTAMP 
NOT NULL
--next ini
ALTER TABLE `receipt_number` CHANGE `location_code` `location_code` VARCHAR(10) NOT NULL;

--pastikan column created_at DAN updated_at NOT NULL = NO, KLU YES RUN CODE BAWAH NI:
--next
ALTER TABLE `receipt_number` 
MODIFY created_at TIMESTAMP
DEFAULT CURRENT_TIMESTAMP 
NOT NULL;
--next 
ALTER TABLE `receipt_number` 
MODIFY updated_at TIMESTAMP
DEFAULT CURRENT_TIMESTAMP 
NOT NULL;



--query search tunggakan manual by ROW
select   bills.bill_amount as total_bills, bills.issue_date from bills 
								where bills.tenant_id = 2227 and bills.issue_date <= '2024-12-03' and bills.bill_type_id = 1 order by bills.issue_date ASC;


select    payments.amount_paid as total_payments, bills.issue_date from payments 
								inner join bills on payments.bill_id = bills.id
								where bills.tenant_id = 2227 and bills.issue_date <= '2024-12-03' and bills.bill_type_id = 1 order by bills.issue_date ASC