diff --git a/print_label_dates.php b/print_label_dates.php new file mode 100644 index 0000000..d5eaf45 --- /dev/null +++ b/print_label_dates.php @@ -0,0 +1,386 @@ +prepare("SELECT * FROM items WHERE sku IN ($placeholders)"); + $stmt->execute($skus); + $results = $stmt->fetchAll(); + // Index by SKU + foreach ($results as $row) { + $items[$row['sku']] = $row; + } +} + +$customWidth = $_REQUEST['custom_width'] ?? '40'; +$customHeight = $_REQUEST['custom_height'] ?? '25'; + +// Templates configuration +$templates = [ + 'custom_roll' => [ + 'name' => 'Custom Size / مقاس مخصص (أدخل المقاس أدناه)', + 'cols' => 1, + 'rows' => 1, + 'width' => $customWidth . 'mm', + 'height' => $customHeight . 'mm', + 'margin_top' => '0mm', + 'margin_left' => '0mm', + 'gap_x' => '0mm', + 'gap_y' => '0mm', + 'page_width' => $customWidth . 'mm', + 'page_height' => $customHeight . 'mm', + ], + 'roll_40x25' => [ + 'name' => 'Roll / Zebra (40 x 25 mm)', + 'cols' => 1, + 'rows' => 1, + 'width' => '40mm', + 'height' => '25mm', + 'margin_top' => '0mm', + 'margin_left' => '0mm', + 'gap_x' => '0mm', + 'gap_y' => '0mm', + 'page_width' => '40mm', + 'page_height' => '25mm', + ], + 'roll_25x40' => [ + 'name' => 'Roll / Zebra (25 x 40 mm)', + 'cols' => 1, + 'rows' => 1, + 'width' => '25mm', + 'height' => '40mm', + 'margin_top' => '0mm', + 'margin_left' => '0mm', + 'gap_x' => '0mm', + 'gap_y' => '0mm', + 'page_width' => '25mm', + 'page_height' => '40mm', + ], + 'roll_38x25' => [ + 'name' => 'Roll / Zebra (38 x 25 mm)', + 'cols' => 1, + 'rows' => 1, + 'width' => '38mm', + 'height' => '25mm', + 'margin_top' => '0mm', + 'margin_left' => '0mm', + 'gap_x' => '0mm', + 'gap_y' => '0mm', + 'page_width' => '38mm', + 'page_height' => '25mm', + ], + 'avery_65' => [ + 'name' => 'Avery L7651 - 65 Labels (38.1 x 21.2 mm)', + 'cols' => 5, + 'rows' => 13, + 'width' => '38.1mm', + 'height' => '21.2mm', + 'margin_top' => '10.5mm', + 'margin_left' => '4.7mm', + 'gap_x' => '2.5mm', + 'gap_y' => '0mm', + 'page_width' => '210mm', + 'page_height' => '297mm', + ], + 'avery_54' => [ + 'name' => 'Avery 54 Labels (32 x 25.4 mm)', + 'cols' => 6, + 'rows' => 9, + 'width' => '32mm', + 'height' => '25.4mm', + 'margin_top' => '10mm', + 'margin_left' => '5mm', + 'gap_x' => '2mm', + 'gap_y' => '0mm', + 'page_width' => '210mm', + 'page_height' => '297mm', + ], + 'avery_45' => [ + 'name' => 'Avery 45 Labels (38.1 x 29.6 mm)', + 'cols' => 5, + 'rows' => 9, + 'width' => '38.1mm', + 'height' => '29.6mm', + 'margin_top' => '15mm', + 'margin_left' => '5mm', + 'gap_x' => '2mm', + 'gap_y' => '0mm', + 'page_width' => '210mm', + 'page_height' => '297mm', + ] +]; + +$templateId = $_REQUEST['template'] ?? 'custom_roll'; +$tpl = $templates[$templateId] ?? $templates['custom_roll']; + +$pageWidth = $tpl['page_width'] ?? '210mm'; +$pageHeight = $tpl['page_height'] ?? '297mm'; +$pageCssSize = (isset($tpl['page_width']) && $tpl['page_width'] !== '210mm') ? "{$tpl['page_width']} {$tpl['page_height']}" : "A4 portrait"; + +if ($templateId !== 'custom_roll') { + $customWidth = floatval(str_replace('mm', '', $tpl['width'])); + $customHeight = floatval(str_replace('mm', '', $tpl['height'])); +} + +// Prepare labels to print +$labelsToPrint = []; +if (!empty($items)) { + // Check if quantities are posted + if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['qty'])) { + foreach ($_POST['qty'] as $sku => $qty) { + if (isset($items[$sku])) { + for ($i = 0; $i < (int)$qty; $i++) { + $itemData = $items[$sku]; + $itemData['prod_date'] = $_POST['prod_date'][$sku] ?? date('Y-m'); + $itemData['exp_date'] = $_POST['exp_date'][$sku] ?? date('Y-m', strtotime('+1 year')); + $labelsToPrint[] = $itemData; + } + } + } + } else { + // Default 1 per item + foreach ($skus as $sku) { + if (isset($items[$sku])) { + $itemData = $items[$sku]; + $itemData['prod_date'] = date('Y-m'); + $itemData['exp_date'] = date('Y-m', strtotime('+1 year')); + $labelsToPrint[] = $itemData; + } + } + } +} + +$isSinglePrint = isset($_GET['sku']) && count($skus) === 1; +$companyName = current_lang() === 'ar' ? get_setting('company_name_ar', 'حلوى الريامي') : get_setting('company_name_en', 'Al Riyami Sweets'); + +?> + + +
+ +