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

(-)a/cataloguing/value_builder/stocknumberam123.pl (-35 / +27 lines)
Lines 49-54 sub plugin_javascript { Link Here
49
        }
49
        }
50
50
51
        function Blur$field_number() {
51
        function Blur$field_number() {
52
                return 1;
53
        }
54
55
        function Clic$field_number() {
52
                var code = document.getElementById('$field_number');
56
                var code = document.getElementById('$field_number');
53
                var url = '../cataloguing/plugin_launcher.pl?plugin_name=stocknumberam123.pl&code=' + code.value;
57
                var url = '../cataloguing/plugin_launcher.pl?plugin_name=stocknumberam123.pl&code=' + code.value;
54
                var blurcallbackstocknumber = {
58
                var blurcallbackstocknumber = {
Lines 61-70 sub plugin_javascript { Link Here
61
                var transaction = YAHOO.util.Connect.asyncRequest('GET',url, blurcallbackstocknumber, null);
65
                var transaction = YAHOO.util.Connect.asyncRequest('GET',url, blurcallbackstocknumber, null);
62
                return 1;
66
                return 1;
63
        }
67
        }
64
65
        function Clic$field_number() {
66
            return 1;
67
        }
68
    </script>
68
    </script>
69
    ";
69
    ";
70
70
Lines 75-116 sub plugin { Link Here
75
    my ($input) = @_;
75
    my ($input) = @_;
76
    my $code = $input->param('code');
76
    my $code = $input->param('code');
77
77
78
    my ($template, $loggedinuser, $cookie) = get_template_and_user({
78
    my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
79
        template_name   => "cataloguing/value_builder/ajax.tmpl",
79
        {   template_name   => "cataloguing/value_builder/ajax.tmpl",
80
        query           => $input,
80
            query           => $input,
81
        type            => "intranet",
81
            type            => "intranet",
82
        authnotrequired => 0,
82
            authnotrequired => 0,
83
        flagsrequired   => {editcatalogue => '*'},
83
            flagsrequired   => { editcatalogue => '*' },
84
        debug           => 1,
84
            debug           => 1,
85
    });
85
        }
86
    );
86
87
87
    my $dbh = C4::Context->dbh;
88
    my $dbh = C4::Context->dbh;
88
    # If the textbox is empty, we return a simple incremented stocknumber
89
89
    if ( $code eq "" ) {
90
        my $sth = $dbh->prepare("SELECT MAX(CAST(stocknumber AS SIGNED)) FROM items");
91
        $sth->execute;
92
    
93
        if ( my $max = $sth->fetchrow ) {
94
            $template->param(
95
                return => $max+1,
96
            );
97
        }
98
    # If a prefix is submited, we look for the highest stocknumber with this prefix, and return it incremented
90
    # If a prefix is submited, we look for the highest stocknumber with this prefix, and return it incremented
99
    } elsif ( $code =~ m/^[A-Z]+$/ ) {
91
    if ( $code =~ m/^[A-Z]+$/ ) {
100
        my $sth = $dbh->prepare("SELECT MAX(CAST(SUBSTRING_INDEX(stocknumber,' ',-1) AS SIGNED)) FROM items WHERE stocknumber LIKE ?");
92
        my $sth = $dbh->prepare("SELECT lib FROM authorised_values WHERE category='INVENTORY' AND authorised_value=?");
101
        $sth->execute($code.' %');
93
        $sth->execute( $code);
102
        
94
103
        if ( my $max = $sth->fetchrow ) {
95
        if ( my $valeur = $sth->fetchrow ) {
104
            $template->param(
96
            $template->param( return => $code . ' ' . sprintf( '%010s', ( $valeur + 1 ) ), );
105
                return => $code.' '.sprintf('%010s',($max+1)),
97
            my $sth2 = $dbh->prepare("UPDATE authorised_values SET lib=? WHERE category='INVENTORY' AND authorised_value=?");
106
            );
98
            $sth2->execute($valeur+1,$code);
99
        } else {
100
                $template->param( return => "There is no defined value for $code");
107
        }
101
        }
108
    # The user entered a custom value, we don't touch it, this could be handled in js
102
        # The user entered a custom value, we don't touch it, this could be handled in js
109
    } else {
103
    } else {
110
        $template->param(
104
        $template->param( return => $code, );
111
            return => $code,
112
        );
113
    }
105
    }
106
114
    output_html_with_http_headers $input, $cookie, $template->output;
107
    output_html_with_http_headers $input, $cookie, $template->output;
115
}
108
}
116
109
117
- 

Return to bug 7992