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

(-)a/reports/itemtypes.plugin (-49 / +24 lines)
Lines 40-96 sub calculate { Link Here
40
	my $branch = @$parameters[0];
40
	my $branch = @$parameters[0];
41
	my $dbh = C4::Context->dbh;
41
	my $dbh = C4::Context->dbh;
42
	my $sth;
42
	my $sth;
43
	if ($branch) {
43
    if ( C4::Context->preference('item-level_itypes') ) {
44
		if (C4::Context->preference('item-level_itypes')) {
44
        $sth = $dbh->prepare( q|
45
		$sth = $dbh->prepare("
45
            SELECT itemtypes.itemtype, description, COUNT(*) AS total
46
        SELECT itemtype, description, items.itype as itemtype, COUNT(*) AS total
46
            FROM itemtypes, items
47
			FROM itemtypes,items         
47
            WHERE items.itype=itemtypes.itemtype
48
		WHERE items.itype=itemtypes.itemtype         
48
            | . ( $branch ? q| AND items.holdingbranch=? | : () ) . q|
49
		AND items.holdingbranch=?            
49
            GROUP BY itemtypes.itemtype, description, items.itype
50
		GROUP BY items.itype
50
            ORDER BY itemtypes.description
51
		ORDER BY itemtypes.description");
51
        |);
52
52
    }
53
		}
53
    else {
54
		else {
54
        $sth = $dbh->prepare( q|
55
		$sth = $dbh->prepare("
55
            SELECT itemtypes.itemtype, description, COUNT(*) AS total
56
        SELECT biblioitems.itemtype, description, biblioitems.itemtype, COUNT(*) AS total
56
            FROM itemtypes, biblioitems, items
57
			FROM itemtypes, biblioitems, items 
57
            WHERE biblioitems.itemtype=itemtypes.itemtype
58
		WHERE biblioitems.itemtype=itemtypes.itemtype 
58
            AND items.biblioitemnumber=biblioitems.biblioitemnumber
59
		AND items.biblioitemnumber=biblioitems.biblioitemnumber
59
            | . ( $branch ? q| AND items.holdingbranch=? | : () ) . q|
60
		AND items.holdingbranch=?
60
            GROUP BY itemtypes.itemtype, description
61
			GROUP BY  biblioitems.itemtype
61
            ORDER BY itemtypes.description
62
			ORDER BY itemtypes.description");
62
        |);
63
		}
63
    }
64
		$sth->execute($branch);
64
    $sth->execute($branch || ());
65
	} else {
65
    my ($itemtype, $description,$total);
66
		if (C4::Context->preference('item-level_itypes')) {
67
		$sth = $dbh->prepare("
68
        SELECT biblioitems.itemtype, description,items.itype AS itemtype, COUNT(*) AS total
69
			FROM itemtypes,items
70
		WHERE items.itype=itemtypes.itemtype
71
			GROUP BY items.itype
72
			ORDER BY itemtypes.description");
73
		}
74
		else {
75
        $sth = $dbh->prepare("SELECT itemtype, description, biblioitems.itemtype, COUNT(*) AS total
76
			FROM itemtypes, biblioitems,items 
77
		WHERE biblioitems.itemtype=itemtypes.itemtype 
78
		AND biblioitems.biblioitemnumber = items.biblioitemnumber
79
			GROUP BY biblioitems.itemtype
80
			ORDER BY itemtypes.description");
81
		}
82
		$sth->execute;
83
	}
84
    my ($itemtype, $description,$biblioitems,$total);
85
	my $grantotal = 0;
66
	my $grantotal = 0;
86
	my $count = 0;
67
	my $count = 0;
87
    while (($itemtype, $description,$biblioitems,$total) = $sth->fetchrow) {
68
    while (($itemtype, $description,$total) = $sth->fetchrow) {
88
		my %line;
69
		my %line;
89
		if($count % 2){
90
			$line{toggle} = 1;
91
			} else {
92
				$line{toggle} = 0;
93
			}
94
        $line{itemtype} = $itemtype;
70
        $line{itemtype} = $itemtype;
95
		$line{count} = $total;
71
		$line{count} = $total;
96
		$grantotal += $total;
72
		$grantotal += $total;
97
- 

Return to bug 26090