function showToolChangeLog()
 {
     $db = Database::getInstance();
     $cxn = $db->getConnection();
     if ($this->toolstockid != '') {
         if (strpos($this->toolstockid, '-')) {
             $q = "SELECT Tool_Stock_ID,Component_Name, Part_NO,Operation_Desc,Mfg_Batch_NO,Ope_Tool_OH,otb.Cutting_Mins,Qty,Tool_Condition FROM Ope_Tool_Batch as otb \n\t\t\tINNER JOIN Ope_Drawing as oped ON oped.Ope_Drawing_ID=otb.Ope_Drawing_ID\n\t\t\tINNER JOIN Operation as op ON op.Operation_ID=oped.Link_ID\n\t\t\tINNER JOIN Component as comp ON comp.Drawing_ID=op.Drawing_ID \n\t\t\tINNER JOIN Ope_Tool as ot ON ot.Ope_Tool_ID=otb.Ope_Tool_ID \n\t\t\tINNER JOIN Batch_NO as bn ON bn.Batch_ID=otb.Batch_ID \n\t\t\tINNER JOIN Tool_Condition as tc ON tc.Tool_Condition_ID=otb.Tool_Condition_ID\n\t\t\t WHERE otb.Tool_Stock_ID like('%{$this->toolstockid}%')";
         } else {
             $q = "SELECT Tool_Stock_ID,Component_Name,Holder_Description, Part_NO,Operation_Desc,Mfg_Batch_NO,Ope_Tool_OH,otb.Cutting_Mins,Qty,Tool_Condition FROM Ope_Tool_Batch as otb \n\t\t\tINNER JOIN Ope_Drawing as oped ON oped.Ope_Drawing_ID=otb.Ope_Drawing_ID\n\t\t\tINNER JOIN Operation as op ON op.Operation_ID=oped.Link_ID\n\t\t\tINNER JOIN Component as comp ON comp.Drawing_ID=op.Drawing_ID \n\t\t\tINNER JOIN Ope_Tool as ot ON ot.Ope_Tool_ID=otb.Ope_Tool_ID \n\t\t\tINNER JOIN Batch_NO as bn ON bn.Batch_ID=otb.Batch_ID \n\t\t\tINNER JOIN Holder_Stock as hs on hs.Stock_ID=otb.Holder_Stock_ID\n\t\t\tINNER JOIN Holder as hld on hld.Holder_ID=hs.Holder_ID\n\t\t\tINNER JOIN Tool_Condition as tc ON tc.Tool_Condition_ID=otb.Tool_Condition_ID\n\t\t\t WHERE otb.Tool_Stock_ID='{$this->toolstockid}'";
         }
         //	   	print("<br>$q");
         if (!($res = $cxn->query($q))) {
             exit("error (showToolChangeLog): {$cxn->error}");
         }
         $n = $res->num_rows;
         $tu = '';
         $tm = 0;
         if ($n > 0) {
             echo '<p><label>The Tool Usage Report</label></p>';
             $tu .= '<table class="t"><tr><th>Part</th><th>Operation Description</th><th>Tool Stock</th><th>Holder</th><th>Tool OH</th><th>Tool Condition</th><th>Cutting Mins</th><th>No of Parts</th></tr>';
             while ($r = mysqli_fetch_assoc($res)) {
                 $tm += $r['Cutting_Mins'];
                 $tu .= "<tr><td>{$r['Component_Name']} : {$r['Part_NO']}</td><td>{$r['Operation_Desc']}</td><td>{$r['Tool_Stock_ID']}</td><td></td><td>{$r['Ope_Tool_OH']}</td><td>{$r['Tool_Condition']}</td><td>{$r['Cutting_Mins']}</td><td>{$r['Qty']}</td></tr>";
             }
         } else {
             $tu .= '<p>Not Usage Records of this Tool Found</p>';
         }
         echo '<p><label>Total usage ' . $tm . ' Mins</label></p>';
         echo $tu;
     }
     if ($this->batchid != '') {
         if ($this->operevid != '') {
             $opr = " AND Ope_Drawing_ID={$this->operevid}";
         } else {
             $opr = '';
         }
         $q1 = "SELECT Ope_Tool_Batch_ID FROM Ope_Tool_Batch WHERE Batch_ID={$this->batchid} {$opr}";
         if (!($res = $cxn->query($q1))) {
             exit("error (showToolChangeLog1): {$cxn->error}");
         }
         $n = $res->num_rows;
         if ($n > 0) {
             $totaltoolingcost = 0;
             echo '<p><label>The Tool Usage Report</label></p>';
             echo '<table class="t"><tr><th>OPETBID</th><th>Operation</th><th>Tool Description</th><th>Tool Part No</th><th>Tool Price</th><th>Tool Stock No</th><th>Tool Body ID</th><th>Tool OH</th><th>Holder</th><th>Holder ID</th><th>Tool Condition</th><th>Cutting Mins</th><th>No of Parts</th><th>Tooling Cost</th><th>Remarks</th></tr>';
             while ($r1 = mysqli_fetch_assoc($res)) {
                 $q2 = "SELECT Tool_Stock_ID FROM Ope_Tool_Batch WHERE Ope_Tool_Batch_ID={$r1['Ope_Tool_Batch_ID']} {$opr}";
                 if (!($res2 = $cxn->query($q2))) {
                     exit("error (showToolChangeLog2): {$cxn->error}");
                 }
                 $row2 = mysqli_fetch_assoc($res2);
                 $tsid = explode(',', $row2['Tool_Stock_ID']);
                 $ii = 0;
                 while ($ii < count($tsid)) {
                     $q3 = "SELECT t.Mfg_Part_NO,Tool_Desc,Price,ts.Cutting_Dia FROM ToolStock as ts INNER JOIN Tool as t on t.Tool_ID=ts.Tool_ID WHERE Stock_ID='{$tsid[$ii]}'";
                     if (!($res3 = $cxn->query($q3))) {
                         exit("error (showToolChangeLog3) {$q3} : {$cxn->error}");
                     }
                     $row3 = mysqli_fetch_assoc($res3);
                     $q = "SELECT Ope_Tool_Batch_ID, Tool_Stock_ID,Operation_Desc,Holder_Description,otb.Holder_Stock_ID,otb.Tool_Body_Stock_ID, Ope_Tool_OH,otb.Cutting_Mins,otb.Remarks,Qty,tc.Tool_Condition FROM Ope_Tool_Batch as otb \n\t\t\t\t\tINNER JOIN Ope_Drawing as oped ON oped.Ope_Drawing_ID=otb.Ope_Drawing_ID\n\t\t\t\t\tINNER JOIN Operation as op ON op.Operation_ID=oped.Link_ID\n\t\t\t\t\tINNER JOIN Ope_Tool as ot ON ot.Ope_Tool_ID=otb.Ope_Tool_ID \n\t\t\t\t\tINNER JOIN Batch_NO as bn ON bn.Batch_ID=otb.Batch_ID \n\t\t            INNER JOIN Tool_Condition as tc ON tc.Tool_Condition_ID=otb.Tool_Condition_ID\n\t\t\t\t\tINNER JOIN Holder_Stock as hs on hs.Stock_ID=otb.Holder_Stock_ID\n\t\t\t\t\tINNER JOIN Holder as hld on hld.Holder_ID=hs.Holder_ID\n\t\t\t\t\t WHERE otb.Ope_Tool_Batch_ID={$r1['Ope_Tool_Batch_ID']} ";
                     //	   	print("<br>$q");
                     if (!($res1 = $cxn->query($q))) {
                         exit("error (showToolChangeLog4): {$cxn->error}");
                     }
                     while ($r = mysqli_fetch_assoc($res1)) {
                         $tso = new Toolstock();
                         $tso->setValue('toolstockid', $tsid[$ii]);
                         $tl = $this->getToolLife($row3['Cutting_Dia'], $tso->getToolTypeID());
                         if ($row3['Price'] > 0) {
                             $tp = $row3['Price'];
                         } else {
                             $tp = $tl[1];
                         }
                         $tc = round($tp / $tl[0] * $r['Cutting_Mins'], 2);
                         $totaltoolingcost += $tc;
                         echo "<tr><td>{$r['Ope_Tool_Batch_ID']}</td><td>{$r['Operation_Desc']}</td><td>{$row3['Tool_Desc']}</td><td>{$row3['Mfg_Part_NO']}</td><td>{$row3['Price']}</td><td>{$r['Tool_Stock_ID']}</td><td>{$r['Tool_Body_Stock_ID']}</td><td>{$r['Ope_Tool_OH']}</td><td>{$r['Holder_Description']}</td><td>{$r['Holder_Stock_ID']}</td><td>{$r['Tool_Condition']}</td><td>{$r['Cutting_Mins']}</td><td>{$r['Qty']}</td><td>{$tc}</td><td>{$r['Remarks']}</td></tr>";
                     }
                     $ii++;
                 }
                 //end of $ii loop
             }
             echo '</table>';
             echo '<p>Total Tooling Cost ' . $totaltoolingcost . '</p>';
         } else {
             echo '<p>Not Usage Records For This Batch Found</p>';
         }
     }
     if ($this->holderstockid != '') {
         $q = "SELECT otb.Holder_Stock_ID, Tool_Stock_ID,Component_Name,Holder_Description, Part_NO,Operation_Desc,Tool_Desc,Mfg_Batch_NO,Ope_Tool_OH,SUBSTRING_INDEX(SUBSTRING_INDEX(Mfg_Batch_NO, '-', 4),'-',-3) as bdate FROM Ope_Tool_Batch as otb \n\t\t\tINNER JOIN Ope_Drawing as oped ON oped.Ope_Drawing_ID=otb.Ope_Drawing_ID\n\t\t\tINNER JOIN Operation as op ON op.Operation_ID=oped.Link_ID\n\t\t\tINNER JOIN Component as comp ON comp.Drawing_ID=op.Drawing_ID \n\t\t\tINNER JOIN Ope_Tool as ot ON ot.Ope_Tool_ID=otb.Ope_Tool_ID \n\t\t\tINNER JOIN Batch_NO as bn ON bn.Batch_ID=otb.Batch_ID \n\t\t\tINNER JOIN Holder_Stock as hs on hs.Stock_ID=otb.Holder_Stock_ID\n\t\t\tINNER JOIN Holder as hld on hld.Holder_ID=hs.Holder_ID\n\t\t\tINNER JOIN ToolStock as ts ON ts.Stock_ID=otb.Tool_Stock_ID\n\t\t\tINNER JOIN Tool as t ON t.Tool_ID=ts.Tool_ID\n\t\t\tINNER JOIN Tool_Condition as tc ON tc.Tool_Condition_ID=otb.Tool_Condition_ID\n\t\t\t WHERE otb.Holder_Stock_ID='{$this->holderstockid}' ORDER BY bdate Desc LIMIT 4";
         //print($q);
         if (!($res = $cxn->query($q))) {
             exit("error (showToolChangeLog holder) {$q}: {$cxn->error}");
         }
         $n = $res->num_rows;
         if ($n > 0) {
             echo '<p><label>Holder Usage Report</label></p>';
             echo '<table class="t"><tr><th>Part</th><th>Operation Description</th><th>Tool Stock</th><th>Tool Description</th><th>Holder</th><th>Holder ID</th><th>Tool OH</th><th>Batch NO</th></tr>';
             while ($r = mysqli_fetch_assoc($res)) {
                 echo "<tr><td>{$r['Component_Name']} : {$r['Part_NO']}</td><td>{$r['Operation_Desc']}</td><td>{$r['Tool_Stock_ID']}</td><td>{$r['Tool_Desc']}</td><td>{$r['Holder_Description']}</td><td>{$r['Holder_Stock_ID']}</td><td>{$r['Ope_Tool_OH']}</td><td>{$r['Mfg_Batch_NO']}</td></tr>";
             }
         } else {
             echo '<p>Not Usage Records of this Holder Found</p>';
         }
     }
 }
     } else {
         $id = 'ToolBody_ID';
     }
     if (isset($_GET['filterinsert'])) {
         $toolbody->setFilterInsert();
     }
     $toolbody->createToolBodyList();
     $sel = new selectlist($id, $toolbody->getToolBodyList(), 'Select Tool Body', 'ToolBody_ID', 'td', '', '');
     break;
 case 'toolstock':
     $toolstock = new Toolstock();
     if (isset($_GET['tid'])) {
         $toolstock->setToolID($_GET['tid']);
     }
     if (isset($_GET['tsv'])) {
         $toolstock->setValue('tsv', $_GET['tsv']);
     }
     $toolstock->createToolStockList();
     if (isset($_GET['tsv'])) {
         $sel = new selectlist('ToolStock_ID', $toolstock->getToolStockList(), 'Select Tool', 'Stock_ID', 'Stock_ID', '', '');
     } else {
         $sel = new selectlist('ToolStock_ID', $toolstock->getToolStockList(), 'Select Tool', 'ToolStock_ID', 'tsid', '', '');
     }
     break;
 case 'toolbodystock':
     $toolbodystock = new Toolbodystock();
     if (isset($_GET['tid'])) {
         $toolbodystock->setToolBodyID($_GET['tid']);
     }
     $toolbodystock->createToolBodyStockList();
     $sel = new selectlist('ToolBody_Stock_ID', $toolbodystock->getToolBodyStockList(), 'Select Tool Body', 'ToolBody_Stock_ID', 'tsid', '', '');