<?php
include "../koneksi.php";

$id = $_POST['del_id'];
$date_kirim = $_POST['date_kirim'];
$detail_ekspedisi = $_POST['detail_ekspedisi'];
$dn = $_POST['dn'];
		if ($date_kirim == '') {
			$data['error']['edit_date_kirim'] = 'Tanggal kirim  tidak boleh kosong';
		}

		function weekOfYear($date) {
			$weekOfYear = intval(date("W", $date));
			if (date('n', $date) == "1" && $weekOfYear > 51) {
				// It's the last week of the previos year.
				return 0;
			}
			else if (date('n', $date) == "12" && $weekOfYear == 1) {
				// It's the first week of the next year.
				return 53;
			}
			else {
				// It's a "normal" week.
				return $weekOfYear;
			}
		}
		
		$week = weekOfYear(strtotime($date_kirim));

		if (empty($data['error'])) {
			$query = "UPDATE deliverytbl SET
											DateKirim = '$date_kirim',
											Week = '$week',
											DetailEkspedisi_ID = '$detail_ekspedisi',
											NoDN = '$dn'
											WHERE Del_ID = '$id'
											";

			mysqli_query($koneksi, $query)
			or die ("Gagal Perintah SQL".mysql_error());
			$data['hasil'] = 'sukses';
		} else {
			$data['hasil'] = 'gagal';
		}
		echo json_encode($data);

?>

