View | Details | Raw Unified | Return to bug 8425
Collapse All | Expand All

(-)a/C4/Barcodes/ValueBuilder.pm (-1 / +4 lines)
Lines 63-70 sub get_barcode { Link Here
63
                            .siblings("select")
63
                            .siblings("select")
64
                            .val();
64
                            .val();
65
65
66
        if(typeof offset == 'undefined'){
67
            var offset = 0;
68
        }
66
        if ( \$(elt).val() == '' ) {
69
        if ( \$(elt).val() == '' ) {
67
            \$(elt).val(homebranch + '$nextnum');
70
            \$(elt).val(homebranch + ($nextnum + offset));
68
        }
71
        }
69
    ~;
72
    ~;
70
    return $nextnum, $scr;
73
    return $nextnum, $scr;
(-)a/cataloguing/value_builder/barcode.pl (-5 / +59 lines)
Lines 90-112 my $builder = sub { Link Here
90
    # default js body (if not filled by hbyymmincr)
90
    # default js body (if not filled by hbyymmincr)
91
    $scr or $scr = <<END_OF_JS;
91
    $scr or $scr = <<END_OF_JS;
92
if (\$('#' + id).val() == '' || force) {
92
if (\$('#' + id).val() == '' || force) {
93
    \$('#' + id).val('$nextnum');
93
    if ( autobarcodetype == "annual"){
94
        const [prefix, numberStr] = '$nextnum'.split('-');
95
        const incrementedNumber = parseInt(numberStr, 10) + offset;
96
        const newNumberStr = incrementedNumber.toString().padStart(numberStr.length, '0');
97
        \$('#' + id).val(prefix + '-' + newNumberStr);
98
    }
99
    else if ( autobarcodetype == "EAN13" ) {
100
        \$('#' + id).val(incrementEAN13($nextnum, offset));
101
    }
102
    else if ( incremental_barcode ) {
103
        \$('#' + id).val($nextnum + offset);
104
    }
105
    else {
106
        \$('#' + id).val('$nextnum');
107
    }
94
};
108
};
95
END_OF_JS
109
END_OF_JS
96
110
97
    my $js  = <<END_OF_JS;
111
    my $js  = <<END_OF_JS;
98
<script>
112
<script>
99
function set_barcode(id, force) {
113
if(typeof autobarcodetype == 'undefined') {
114
    var autobarcodetype = "$autoBarcodeType";
115
    var attempt = -1
116
    var incrementalBarcodeTypes = ["hbyymmincr", "incremental", "annual", "EAN13"];
117
    var incremental_barcode = incrementalBarcodeTypes.includes(autobarcodetype);
118
}
119
120
function set_barcode(id, force, offset=0) {
100
$scr
121
$scr
101
}
122
}
102
123
124
function calculateChecksum(ean12) {
125
    let sum = 0;
126
    for (let i = 0; i < ean12.length; i++) {
127
        const digit = parseInt(ean12[i], 10);
128
        sum += (i % 2 === 0) ? digit : digit * 3;
129
    }
130
    const checksum = (10 - (sum % 10)) % 10;
131
    return checksum;
132
}
133
134
function incrementEAN13(ean13, offset) {
135
    // Increment the first 12 digits and recompute the checksum
136
    let ean12 = String(ean13).slice(0, 12);
137
    let incrementedNumber = (parseInt(ean12, 10) + offset).toString().padStart(12, '0');
138
    const newChecksum = calculateChecksum(incrementedNumber);
139
    return incrementedNumber + newChecksum;
140
}
141
103
function Focus$function_name(event) {
142
function Focus$function_name(event) {
104
    set_barcode(event.data.id, false);
143
    if (incremental_barcode){
144
        if (document.getElementById(event.data.id).value == ''){
145
            attempt += 1
146
        }
147
        set_barcode(event.data.id, false, attempt);
148
    }
149
    else{
150
        set_barcode(event.data.id, false);
151
    }
105
    return false;
152
    return false;
106
}
153
}
107
154
108
function Click$function_name(event) {
155
function Click$function_name(event) {
109
    set_barcode(event.data.id, true);
156
    if (incremental_barcode){
157
        if (document.getElementById(event.data.id).value == ''){
158
            attempt += 1
159
        }
160
        set_barcode(event.data.id, false, attempt);
161
    }
162
    else{
163
        set_barcode(event.data.id, false);
164
    }
110
    return false;
165
    return false;
111
}
166
}
112
</script>
167
</script>
113
- 

Return to bug 8425