From ec5e25fdd0397a0bd4ae8930b0f8fa07a0037dfd Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 23 Apr 2026 15:28:01 +0000 Subject: [PATCH] Autosave: 20260423-152803 --- print_label_dates.php | 386 +++++++++++++++++++++++++++++++++++++++++ print_labels.php | 3 + print_single_label.php | 3 + stock.php | 7 + 4 files changed, 399 insertions(+) create mode 100644 print_label_dates.php 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'); + +?> + + + + + <?= h(tr('طباعة ملصقات مع التواريخ', 'Print Labels with Dates')) ?> + + + + + + + +
+
+
+
+ +
+
+
+
+ +
+ + +
+
+ + +
+ +
+ +
+
+ +
+ + + + + + + + + + + + $item): + ?> + + + + + + + + + + + + +
SKU
+ + + + + + +
+ + +
+
+
+ +
+ +
+
+
+
+ + + + +
+ +
+ + + + + \ No newline at end of file diff --git a/print_labels.php b/print_labels.php index 10e56c0..0b376e8 100644 --- a/print_labels.php +++ b/print_labels.php @@ -157,6 +157,7 @@ if (!empty($items)) { } $isSinglePrint = isset($_GET['sku']) && count($skus) === 1; +$companyName = current_lang() === 'ar' ? get_setting('company_name_ar', 'حلوى الريامي') : get_setting('company_name_en', 'Al Riyami Sweets'); ?> @@ -206,6 +207,7 @@ $isSinglePrint = isset($_GET['sku']) && count($skus) === 1; text-align: center; } + .label-company { font-size: 9px; font-weight: bold; margin-bottom: 1px; text-transform: uppercase; } .label-name { font-size: 9px; font-weight: bold; line-height: 1.1; margin-bottom: 2px; max-height: 20px; overflow: hidden; } .label-price { font-size: 10px; font-weight: bold; margin-top: 1px; } .label-sku { font-size: 8px; color: #555; } @@ -328,6 +330,7 @@ $isSinglePrint = isset($_GET['sku']) && count($skus) === 1;
+
@@ -206,6 +207,7 @@ $isSinglePrint = isset($_GET['sku']) && count($skus) === 1; text-align: center; } + .label-company { font-size: 9px; font-weight: bold; margin-bottom: 1px; text-transform: uppercase; } .label-name { font-size: 9px; font-weight: bold; line-height: 1.1; margin-bottom: 2px; max-height: 20px; overflow: hidden; } .label-price { font-size: 10px; font-weight: bold; margin-top: 1px; } .label-sku { font-size: 8px; color: #555; } @@ -337,6 +339,7 @@ $isSinglePrint = isset($_GET['sku']) && count($skus) === 1;
+
+ @@ -759,6 +762,10 @@ function printSingleLabel(sku) { } window.location.href = 'print_single_label.php?sku=' + encodeURIComponent(sku); } + +function printLabelDates(sku) { + window.location.href = 'print_label_dates.php?sku=' + encodeURIComponent(sku); +} \ No newline at end of file