UNLOCK TABLES;
TRUNCATE `autodebet_student`;
TRUNCATE `jobs`;
TRUNCATE `journal_pendings`;
TRUNCATE `library_visitors`;
TRUNCATE `logs`;
TRUNCATE `monthly_tahfidz`;
TRUNCATE `patients`;
TRUNCATE `psb_exam_participants`;
TRUNCATE `school_cases`;
TRUNCATE `scores`;
TRUNCATE `student_bill_types`;
TRUNCATE `student_psb_flow`;
TRUNCATE `student_reward`;
TRUNCATE `transaction_pendings`;
TRUNCATE `new_students`;
TRUNCATE `bills`;
TRUNCATE `donations`;
TRUNCATE `new_parents`;
TRUNCATE `student_mutations`;
TRUNCATE `transactions`;
TRUNCATE `attendances`;
TRUNCATE `agendas`;
TRUNCATE `approvals`;
TRUNCATE `bill_payment`;
TRUNCATE `bill_transaction`;
TRUNCATE `book_borrow`;
TRUNCATE `card_queues`;
TRUNCATE `employee_mutations`;
TRUNCATE `inventory_handover`;
TRUNCATE `journals`;
TRUNCATE `news`;
TRUNCATE `news_readers`;
TRUNCATE `notifications`;
TRUNCATE `notification_user`;
TRUNCATE `payment_bank_settlement`;
TRUNCATE `payments`;
TRUNCATE `permission_date`;
TRUNCATE `permission_jam`;
TRUNCATE `permissions`;
TRUNCATE `permission_schedule`;
TRUNCATE `progress_mengaji`;
TRUNCATE `progress_tahfidz`;
TRUNCATE `psb_documents`;
TRUNCATE `school_cases`;
TRUNCATE `store_withdrawals`;
TRUNCATE `student_mutations`;
TRUNCATE `teaching_notes`;
TRUNCATE `transaction_product`;


delete transactions FROM transactions 
left join bill_transaction on bill_transaction.transaction_id = transactions.id
left join bills on bill_transaction.bill_id = bills.id
WHERE bill_transaction.transaction_id is null
and transactions.transactionDate < '2022-10-09'
and transaction_type_value=0;

delete transactions FROM transactions 
left join bill_transaction on bill_transaction.transaction_id = transactions.id
left join bills on bill_transaction.bill_id = bills.id
WHERE 1=1
and bill_transaction.transaction_id is null
and transactions.transactionDate < '2022-10-10'
and transaction_type_value=0
and transactions.admin_employee_id=5;

delete journals FROM `journals` 
left join transactions on transactions.id = journals.transaction_id 
where transactions.id is null and journals.transactionDate < '2022-10-10';