<?php
include $_SERVER['DOCUMENT_ROOT'] . '/classes/autoload.php';

$note = str_replace('"', '', $_POST['note']);
$note = str_replace("'", '', $note);

$credit_note_id = $db->query("credit_notes", "INSERT INTO credit_notes (`invoice_id`,`client_banking_details`) VALUES ('{$_POST['invoice_id']}','$note')");

$stokc_items_arr = $_POST['descriptions'];
$index = 0;
foreach ($stokc_items_arr as $item_name) {
    $db->query("credit_notes_list", "INSERT INTO credit_notes_list (`credit_note_id`,`name`,`amount`) VALUES ('$credit_note_id','$item_name','{$_POST['amounts'][$index]}')");
    $index++;
}
header("location:home.php");