function __construct($orientation, $metric, $size, $startdate, $enddate)
 {
     $this->fromdate = convertStringToDate($startdate);
     $this->todate = convertStringToDate($enddate);
     $eventid = $_POST['eventid'];
     $dynamicY = 0;
     parent::__construct($orientation, $metric, $size);
     $this->SetAutoPageBreak(true, 30);
     $this->AddPage();
     try {
         $total = array();
         $total[0] = 0;
         $total[1] = 0;
         $total[2] = 0;
         $total[3] = 0;
         $total[4] = 0;
         if ($eventid == 0) {
             $sql = "SELECT A.id, A.name, A.retailprice, B.stock \n\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}product A \n\t\t\t\t\t\t\tLEFT OUTER JOIN {$_SESSION['DB_PREFIX']}eventproductmatrix B\n\t\t\t\t\t\t\tON B.productid = A.id\n\t\t\t\t\t\t\tORDER BY A.name";
         } else {
             $sql = "SELECT A.id, A.name, A.retailprice, B.stock \n\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}product A \n\t\t\t\t\t\t\tLEFT OUTER JOIN {$_SESSION['DB_PREFIX']}eventproductmatrix B\n\t\t\t\t\t\t\tON B.productid = A.id\n\t\t\t\t\t\t\tAND B.eventid = {$eventid}\n\t\t\t\t\t\t\tORDER BY A.name";
         }
         $result = mysql_query($sql);
         if ($result) {
             while ($member = mysql_fetch_assoc($result)) {
                 $productid = $member['id'];
                 $productname = $member['name'];
                 $stock = $member['stock'];
                 $retailprice = $member['retailprice'];
                 $sold = 0;
                 $broken = 0;
                 $demo = 0;
                 if ($eventid == 0) {
                     $sql = "SELECT \n\t\t\t\t\t\t\t\t\tIFNULL(SUM(B.amount), 0) AS amount \n\t\t\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}eventtransaction B \n\t\t\t\t\t\t\t\t\tWHERE B.productid = {$productid} \n\t\t\t\t\t\t\t\t\tAND B.type = 'S'\n\t\t\t\t\t\t\t\t\tAND B.eventdate BETWEEN '{$this->fromdate}' AND '{$this->todate}'";
                 } else {
                     $sql = "SELECT \n\t\t\t\t\t\t\t\t\tIFNULL(SUM(B.amount), 0) AS amount \n\t\t\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}eventtransaction B \n\t\t\t\t\t\t\t\t\tWHERE B.productid = {$productid} \n\t\t\t\t\t\t\t\t\tAND B.eventid = {$eventid}\n\t\t\t\t\t\t\t\t\tAND B.type = 'S'\n\t\t\t\t\t\t\t\t\tAND B.eventdate BETWEEN '{$this->fromdate}' AND '{$this->todate}'";
                 }
                 $itemresult = mysql_query($sql);
                 if ($itemresult) {
                     while ($itemmember = mysql_fetch_assoc($itemresult)) {
                         $sold = $itemmember['amount'];
                     }
                 } else {
                     logError($sql . " - " . mysql_error());
                 }
                 if ($eventid == 0) {
                     $sql = "SELECT \n\t\t\t\t\t\t\t\t\tIFNULL(SUM(B.amount), 0) AS amount \n\t\t\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}eventtransaction B \n\t\t\t\t\t\t\t\t\tWHERE B.productid = {$productid} \n\t\t\t\t\t\t\t\t\tAND B.type = 'B'\n\t\t\t\t\t\t\t\t\tAND B.eventdate BETWEEN '{$this->fromdate}' AND '{$this->todate}'";
                 } else {
                     $sql = "SELECT \n\t\t\t\t\t\t\t\t\tIFNULL(SUM(B.amount), 0) AS amount \n\t\t\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}eventtransaction B \n\t\t\t\t\t\t\t\t\tWHERE B.productid = {$productid} \n\t\t\t\t\t\t\t\t\tAND B.eventid = {$eventid}\n\t\t\t\t\t\t\t\t\tAND B.type = 'B'\n\t\t\t\t\t\t\t\t\tAND B.eventdate BETWEEN '{$this->fromdate}' AND '{$this->todate}'";
                 }
                 $itemresult = mysql_query($sql);
                 if ($itemresult) {
                     while ($itemmember = mysql_fetch_assoc($itemresult)) {
                         $broken = $itemmember['amount'];
                     }
                 } else {
                     logError($sql . " - " . mysql_error());
                 }
                 if ($eventid == 0) {
                     $sql = "SELECT \n\t\t\t\t\t\t\t\t\tIFNULL(SUM(B.amount), 0) AS amount \n\t\t\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}eventtransaction B \n\t\t\t\t\t\t\t\t\tWHERE B.productid = {$productid} \n\t\t\t\t\t\t\t\t\tAND B.type = 'G'\n\t\t\t\t\t\t\t\t\tAND B.eventdate BETWEEN '{$this->fromdate}' AND '{$this->todate}'";
                 } else {
                     $sql = "SELECT \n\t\t\t\t\t\t\t\t\tIFNULL(SUM(B.amount), 0) AS amount \n\t\t\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}eventtransaction B \n\t\t\t\t\t\t\t\t\tWHERE B.productid = {$productid} \n\t\t\t\t\t\t\t\t\tAND B.eventid = {$eventid}\n\t\t\t\t\t\t\t\t\tAND B.type = 'G'\n\t\t\t\t\t\t\t\t\tAND B.eventdate BETWEEN '{$this->fromdate}' AND '{$this->todate}'";
                 }
                 $itemresult = mysql_query($sql);
                 if ($itemresult) {
                     while ($itemmember = mysql_fetch_assoc($itemresult)) {
                         $demo = $itemmember['amount'];
                     }
                 } else {
                     logError($sql . " - " . mysql_error());
                 }
                 $total[0] += $sold;
                 $total[1] += $broken;
                 $total[2] += $demo;
                 $total[3] += $stock;
                 $total[4] += $sold * $retailprice;
                 $line = array(GetEventName($_POST['eventid']) => $productname, "SOLD" => $sold, "BROKEN" => $broken, "DEMO" => $demo, "BALANCE" => number_format($stock, 0), "SALES" => number_format($sold * $retailprice, 2));
                 $this->addLine($this->GetY(), $line, 5);
             }
         } else {
             logError($sql . " - " . mysql_error());
         }
         $line = array(GetEventName($_POST['eventid']) => "Total", "SOLD" => " " . $total[0], "BROKEN" => " " . $total[1], "DEMO" => " " . $total[2], "BALANCE" => " " . $total[3], "SALES" => " " . number_format($total[4], 2));
         $this->addLine($this->GetY() + 2, $line, 5);
     } catch (Exception $e) {
         logError($e->getMessage());
     }
 }
 function __construct($orientation, $metric, $size, $startdate)
 {
     $this->fromdate = convertStringToDate($startdate);
     $this->todate = date("Y-m-d", strtotime("+1 week", strtotime($this->fromdate)));
     $eventid = $_POST['eventid'];
     $dynamicY = 0;
     parent::__construct($orientation, $metric, $size);
     $this->SetAutoPageBreak(true, 30);
     $this->AddPage();
     try {
         $total = array();
         $total[0] = 0;
         $total[1] = 0;
         $total[2] = 0;
         $total[3] = 0;
         $total[4] = 0;
         $total[5] = 0;
         $total[6] = 0;
         $sql = "SELECT A.id, A.name \n\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}product A \n\t\t\t\t\t\tORDER BY A.name";
         $result = mysql_query($sql);
         if ($result) {
             while ($member = mysql_fetch_assoc($result)) {
                 $productid = $member['id'];
                 $productname = $member['name'];
                 $date = $this->fromdate;
                 $amounts = array();
                 while (strtotime($date) <= strtotime($this->todate)) {
                     if ($eventid == 0) {
                         $sql = "SELECT IFNULL(SUM(B.amount), 0) AS amount\n\t\t\t\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}eventtransaction B \n\t\t\t\t\t\t\t\t\t\tWHERE B.productid = {$productid} \n\t\t\t\t\t\t\t\t\t\tAND B.eventdate = '{$date}'";
                     } else {
                         $sql = "SELECT IFNULL(SUM(B.amount), 0) AS amount\n\t\t\t\t\t\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}eventtransaction B \n\t\t\t\t\t\t\t\t\t\tWHERE B.productid = {$productid} \n\t\t\t\t\t\t\t\t\t\tAND B.eventid = {$eventid}\n\t\t\t\t\t\t\t\t\t\tAND B.eventdate = '{$date}'";
                     }
                     $itemresult = mysql_query($sql);
                     if ($itemresult) {
                         while ($itemmember = mysql_fetch_assoc($itemresult)) {
                             array_push($amounts, $itemmember['amount']);
                         }
                     } else {
                         logError($sql . " - " . mysql_error());
                     }
                     $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
                 }
                 $total[0] += $amounts[0];
                 $total[1] += $amounts[1];
                 $total[2] += $amounts[2];
                 $total[3] += $amounts[3];
                 $total[4] += $amounts[4];
                 $total[5] += $amounts[5];
                 $total[6] += $amounts[6];
                 $line = array(GetEventName($_POST['eventid']) => $productname, $this->dates[0] => $amounts[0], $this->dates[1] => $amounts[1], $this->dates[2] => $amounts[2], $this->dates[3] => $amounts[3], $this->dates[4] => $amounts[4], $this->dates[5] => $amounts[5], $this->dates[6] => $amounts[6]);
                 $this->addLine($this->GetY(), $line, 5);
             }
         } else {
             logError($sql . " - " . mysql_error());
         }
         $line = array(GetEventName($_POST['eventid']) => "Total", $this->dates[0] => " " . $total[0], $this->dates[1] => " " . $total[1], $this->dates[2] => " " . $total[2], $this->dates[3] => " " . $total[3], $this->dates[4] => " " . $total[4], $this->dates[5] => " " . $total[5], $this->dates[6] => " " . $total[6]);
         $this->addLine($this->GetY() + 2, $line, 5);
     } catch (Exception $e) {
         logError($e->getMessage());
     }
 }