<?php
require_once('includes/load.php');
$order = isset($_POST['order']) ? $_POST['order'] : '';
$zipcode = isset($_POST['zipcode']) ? $_POST['zipcode'] : '';
$code = generateCode("PL");
$genPacking = generatePackingListPDFByOrderSN($order, $code, "$code.pdf");
$barcodeFileName = 'storage/barcode_' . $code . '.png';
deleteBarcode($barcodeFileName);
$packingListData = [
    'code' =>  $code,
    'zipcode' => $zipcode,
    'file_url' => $genPacking['file_url'],
];
$idPacking = insertPackingListAndUpdateOrders($packingListData, $genPacking['order_ids']);
$orderSNArray = explode(",", $order);
updateOrderQueueProcessedByOrderSN($orderSNArray);
$warehouse = getWarehouseByZipcode($zipcode);
$namaFile = $code . '-' . $warehouse . '-' . time() . '.pdf';
mergePDFFilePacking($idPacking, $namaFile);
echo '<script language="javascript">window.location.assign("list_antrian_packing.php")</script>';
die();