Example #1
0
 function generate_report()
 {
     access_control($this);
     $schooldetails = $this->session->userdata('schoolinfo');
     # Get the passed details into the url data array if any
     $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
     # Pick all assigned data
     $data = assign_to_data($urldata);
     if ($this->input->post('generatepdf') || $this->input->post('generateexcel')) {
         $required_fields = array('type');
         $_POST = clean_form_data($_POST);
         $validation_results = validate_form('', $_POST, $required_fields);
         if ($validation_results['bool']) {
             $_POST = clean_form_data($_POST);
             $searchstring = '1';
             if ($_POST['type'] == 1) {
                 if (isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "") {
                     $searchstring .= " AND  UNIX_TIMESTAMP(i.datecreated) <= '" . strtotime($_POST['dateto'] . ' 23:59:59') . "' AND UNIX_TIMESTAMP(i.datecreated) >= '" . strtotime($_POST['datefrom']) . "'";
                 }
                 if (isset($_POST['item']) && $_POST['item'] != "") {
                     $searchstring .= " AND i.itemid=" . $_POST['item'];
                 }
                 $querycode = 'get_inventory_list';
                 $data['dateto'] = $_POST['dateto'];
                 $data['datefrom'] = $_POST['datefrom'];
                 #Get the paginated list of the purchases
                 $data = paginate_list($this, $data, $querycode, array('isactive' => 'Y', 'searchstring' => ' i.school = ' . $schooldetails['id'] . ' AND (' . $searchstring . ')'));
                 $report_type = 'purchases_report';
                 $report_name = "PURCHASES REPORT";
                 if ($this->input->post('generateexcel')) {
                     $size = sizeof($data['page_list']);
                     $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][$size - 1]['datecreated']));
                     $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['datecreated']));
                     if (!empty($data['datefrom'])) {
                         $from = date("j M, Y", GetTimeStamp($data['datefrom']));
                     } else {
                         $from = $maxdate;
                     }
                     if (!empty($data['dateto'])) {
                         $to = date("j M, Y", GetTimeStamp($data['dateto']));
                     } else {
                         $to = $mindate;
                     }
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "From :", $from, "", "", "To :", $to);
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date", "Item Name", "Supplier", "Invoice Number", "Quanity", "Price");
                     $this->excelexport->addRow($mydata);
                     $sum = 0;
                     foreach ($data['page_list'] as $row) {
                         $price = $row['price'] * $row['quantity'];
                         $sum += $price;
                         $mydata = array(date("j M, Y", GetTimeStamp($row['datecreated'])), $row['itemname'], $row['supplier'], $row['invoicenumber'], $row['quantity'], number_format($price, 0, '.', ','));
                         $this->excelexport->addRow($mydata);
                     }
                     $mydata = array("Total", "", "", "", "", number_format($sum, 0, '.', ','));
                     $this->excelexport->addRow($mydata);
                 }
             } elseif ($_POST['type'] == 3) {
                 if (isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "") {
                     $searchstring .= " AND  UNIX_TIMESTAMP(i.datecreated) <= '" . strtotime($_POST['dateto'] . ' 23:59:59') . "' AND UNIX_TIMESTAMP(i.datecreated) >= '" . strtotime($_POST['datefrom']) . "'";
                 }
                 if (isset($_POST['item']) && $_POST['item'] != "") {
                     $searchstring .= " AND i.itemid=" . $_POST['item'];
                 }
                 $querycode = 'get_inventory_list';
                 $data['dateto'] = $_POST['dateto'];
                 $data['datefrom'] = $_POST['datefrom'];
                 #Get the paginated list of the deals
                 $data = paginate_list($this, $data, 'get_transaction_list', array('isactive' => 'Y', 'searchstring' => ' t.school = ' . $schooldetails['id'] . ' AND (' . $searchstring . ')'));
                 $report_type = 'issuing_report';
                 $report_name = "ISSUING REPORT";
                 if ($this->input->post('generateexcel')) {
                     $size = sizeof($data['page_list']);
                     $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][$size - 1]['dateadded']));
                     $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['dateadded']));
                     if (!empty($data['datefrom'])) {
                         $from = date("j M, Y", GetTimeStamp($data['datefrom']));
                     } else {
                         $from = $maxdate;
                     }
                     if (!empty($data['dateto'])) {
                         $to = date("j M, Y", GetTimeStamp($data['dateto']));
                     } else {
                         $to = $mindate;
                     }
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "From :", $from, "", "", "To :", $to);
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date", "Item Name", "Quantity", "Issued To");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         $mydata = array(date("j M, Y", GetTimeStamp($row['dateadded'])), $row['itemname'], $row['quantity'], $row['firstname'] . " " . $row['lastname']);
                         $this->excelexport->addRow($mydata);
                     }
                 }
             } elseif ($_POST['type'] == 2) {
                 #Get the paginated list of the inventory
                 $data = paginate_list($this, $data, 'get_item_list', array('isactive' => 'Y', 'searchstring' => ' school = ' . $schooldetails['id']));
                 $report_type = 'inventory_report';
                 $report_name = "INVENTORY REPORT";
                 if ($this->input->post('generateexcel')) {
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "", date("j M, Y", time()));
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Item Name", "In", "Out", "Stocked", "Units");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         $stocked = get_stocked($this, $row['id']);
                         $sold = get_sold($this, $row['id']);
                         $remaining = $stocked - $sold;
                         #Assign zeros to empty values
                         if (empty($stocked)) {
                             $stocked = 0;
                         }
                         if (empty($sold)) {
                             $sold = 0;
                         }
                         $mydata = array($row['itemname'], $remaining, $sold, $stocked, $row['unitspecification']);
                         $this->excelexport->addRow($mydata);
                     }
                 }
             }
             #Format the statement
             $report_html = '';
             #$financial_details = array();
             $this->load->library('parser');
             $data['schoolname'] = $schooldetails['schoolname'];
             $data['report_html'] = $report_html;
             $output = $this->parser->parse('reports/' . $report_type, $data, true);
             if ($this->input->post('generatepdf')) {
                 gen_pdf($this, $output);
             } else {
                 $this->excelexport->download($report_type . '.xls');
             }
         }
         if ((empty($validation_results['bool']) || !empty($validation_results['bool']) && !$validation_results['bool']) && empty($data['msg'])) {
             $data['msg'] = "WARNING: The highlighted fields are required.";
         }
         $data['requiredfields'] = $validation_results['requiredfields'];
         $data['formdata'] = $_POST;
     }
     $this->load->view('inventory/new_report_view');
 }
Example #2
0
 function generate_report()
 {
     access_control($this);
     $schooldetails = $this->session->userdata('schoolinfo');
     # Get the passed details into the url data array if any
     $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
     # Pick all assigned data
     $data = assign_to_data($urldata);
     if ($this->input->post('generatepdf') || $this->input->post('generateexcel')) {
         $required_fields = array('type');
         $_POST = clean_form_data($_POST);
         $validation_results = validate_form('', $_POST, $required_fields);
         if ($validation_results['bool']) {
             $_POST = clean_form_data($_POST);
             $searchstring = '1';
             if ($_POST['type'] == 7) {
                 if (isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "") {
                     $searchstring .= " AND  UNIX_TIMESTAMP(b.datetaken) <= '" . strtotime($_POST['dateto'] . ' 23:59:59') . "' AND UNIX_TIMESTAMP(b.datetaken) >= '" . (strtotime($_POST['datefrom']) - 86400) . "'";
                 }
                 if (isset($_POST['item']) && $_POST['item'] != "") {
                     $searchstring .= " AND b.stockid=" . $_POST['item'];
                 }
                 $data['dateto'] = $_POST['dateto'];
                 $data['datefrom'] = $_POST['datefrom'];
                 #Get the paginated list of the purchases
                 $data = paginate_list($this, $data, 'get_borrower_list', array('isactive' => 'Y', 'searchstring' => ' b.school = ' . $schooldetails['id'] . ' AND (' . $searchstring . ')'));
                 $report_type = 'borrowing_report';
                 $report_name = "BORROWING REPORT";
                 if ($this->input->post('generateexcel')) {
                     $size = sizeof($data['page_list']);
                     $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][$size - 1]['datetaken']));
                     $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['datetaken']));
                     if (!empty($data['datefrom'])) {
                         $from = date("j M, Y", GetTimeStamp($data['datefrom']));
                     } else {
                         $from = $maxdate;
                     }
                     if (!empty($data['dateto'])) {
                         $to = date("j M, Y", GetTimeStamp($data['dateto']));
                     } else {
                         $to = $mindate;
                     }
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "From :", $from, "", "To :", $to);
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date Borrowed", "Title", "Returned / Borrowed", "Name", "Date Expected");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         #check expiry of rental period
                         $currentdate = date("Y-m-d H:i:s");
                         $borrower_status = check_borrower_status($this, $row['borrowerid']);
                         $mydata = array(date("j M, Y", GetTimeStamp($row['datetaken'])), $row['stocktitle'], $row['copiestaken'] - $borrower_status . "/" . $row['copiestaken'], $row['firstname'] . " " . $row['lastname'], date("j M, Y", GetTimeStamp($row['returndate'])));
                         $this->excelexport->addRow($mydata);
                     }
                 }
             } elseif ($_POST['type'] == 5) {
                 if (isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "") {
                     $searchstring .= " AND  UNIX_TIMESTAMP(l.createdon) <= '" . strtotime($_POST['dateto'] . ' 23:59:59') . "' AND UNIX_TIMESTAMP(l.createdon) >= '" . (strtotime($_POST['datefrom']) - 86400) . "'";
                 }
                 if (isset($_POST['item']) && $_POST['item'] != "") {
                     $searchstring .= " AND i.itemid=" . $_POST['item'];
                 }
                 $data['dateto'] = $_POST['dateto'];
                 $data['datefrom'] = $_POST['datefrom'];
                 #Get the paginated list of the purchases
                 $data = paginate_list($this, $data, 'get_stock_items_list', array('isactive' => 'Y', 'searchstring' => ' s.school = ' . $schooldetails['id'] . ' AND (' . $searchstring . ')'));
                 $report_type = 'library_stock_report';
                 $report_name = "LIBRARY STOCK REPORT";
                 if ($this->input->post('generateexcel')) {
                     $size = sizeof($data['page_list']);
                     $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][$size - 1]['datecreated']));
                     $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['datecreated']));
                     if (!empty($data['datefrom'])) {
                         $from = date("j M, Y", GetTimeStamp($data['datefrom']));
                     } else {
                         $from = $maxdate;
                     }
                     if (!empty($data['dateto'])) {
                         $to = date("j M, Y", GetTimeStamp($data['dateto']));
                     } else {
                         $to = $mindate;
                     }
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "From :", $from, "", "To :", $to);
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date Added", "Serial Number", "Title", "ISBN Number");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         $mydata = array(date("j M, Y", GetTimeStamp($row['datecreated'])), $row['serialnumber'], $row['stocktitle'], $row['isbnnumber']);
                         $this->excelexport->addRow($mydata);
                     }
                 }
             } elseif ($_POST['type'] == 4) {
                 #Get the paginated list of the inventory
                 $data = paginate_list($this, $data, 'get_stock_list', array('isactive' => 'Y', 'searchstring' => ' school = ' . $schooldetails['id']));
                 $report_type = 'library_report';
                 $report_name = "LIBRARY REPORT";
                 if ($this->input->post('generateexcel')) {
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "", date("j M, Y", time()));
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date", "Title", "Stocked", "Available", "Out");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         $stocked = get_all_stock_items($this, $row['id']);
                         $in = get_stock_items($this, $row['id'], 1);
                         $out = get_stock_items($this, $row['id'], 0);
                         $mydata = array(date("j M, Y", GetTimeStamp($row['createdon'])), $row['stocktitle'], $stocked, $in, $out);
                         $this->excelexport->addRow($mydata);
                     }
                 }
             } elseif ($_POST['type'] == 8) {
                 if (isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "") {
                     $searchstring .= " AND  UNIX_TIMESTAMP(r.returndate) <= '" . strtotime($_POST['dateto'] . ' 23:59:59') . "' AND UNIX_TIMESTAMP(r.returndate) >= '" . (strtotime($_POST['datefrom']) - 86400) . "'";
                 }
                 if (isset($_POST['item']) && $_POST['item'] != "") {
                     $searchstring .= " AND s.id=" . $_POST['item'];
                 }
                 $data['dateto'] = $_POST['dateto'];
                 $data['datefrom'] = $_POST['datefrom'];
                 #Get the paginated list of the purchases
                 $data = paginate_list($this, $data, 'get_return_list', array('isactive' => 'Y', 'searchstring' => ' b.school = ' . $schooldetails['id'] . ' AND (' . $searchstring . ')'));
                 $report_type = 'returning_report';
                 $report_name = "RETURNING REPORT";
                 if ($this->input->post('generateexcel')) {
                     $size = sizeof($data['page_list']);
                     $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][$size - 1]['returndate']));
                     $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['returndate']));
                     if (!empty($data['datefrom'])) {
                         $from = date("j M, Y", GetTimeStamp($data['datefrom']));
                     } else {
                         $from = $maxdate;
                     }
                     if (!empty($data['dateto'])) {
                         $to = date("j M, Y", GetTimeStamp($data['dateto']));
                     } else {
                         $to = $mindate;
                     }
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "From :", $from, "", "To :", $to);
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date Returned", "Title", "Serial Number");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         $mydata = array(date("j M, Y", GetTimeStamp($row['returndate'])), $row['stocktitle'], $row['stocktitle'], $row['serialnumber']);
                         $this->excelexport->addRow($mydata);
                     }
                 }
             }
             #Format the statement
             $report_html = '';
             #$financial_details = array();
             $this->load->library('parser');
             $data['schoolname'] = $schooldetails['schoolname'];
             $data['report_html'] = $report_html;
             $output = $this->parser->parse('reports/' . $report_type, $data, true);
             if ($this->input->post('generatepdf')) {
                 gen_pdf($this, $output);
             } else {
                 $this->excelexport->download($report_type . '.xls');
             }
         }
         if ((empty($validation_results['bool']) || !empty($validation_results['bool']) && !$validation_results['bool']) && empty($data['msg'])) {
             $data['msg'] = "WARNING: The highlighted fields are required.";
         }
         $data['requiredfields'] = $validation_results['requiredfields'];
         $data['formdata'] = $_POST;
     }
     $this->load->view('library/new_report_view');
 }
Example #3
0
 function print_transaction()
 {
     # Get the passed details into the url data array if any
     $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
     # Pick all assigned data
     $data = assign_to_data($urldata);
     #Get the transaction data
     $transactionid = decryptValue($data['i']);
     $transaction_details = $this->Query_reader->get_row_as_array('search_student_accounts', array('isactive' => 'Y', 'limittext' => '', 'searchstring' => ' AND id = ' . $transactionid));
     $data['transaction'] = $transaction_details;
     #Get the student's details
     $data['studentdetails'] = $this->Query_reader->get_row_as_array('get_students_list', array('isactive' => 'Y', 'limittext' => '', 'searchstring' => ' AND id = ' . $transaction_details['student']));
     #Get the author details
     $data['author'] = $this->Query_reader->get_row_as_array('search_school_users', array('isactive' => 'Y', 'limittext' => '', 'searchstring' => ' AND id = ' . $transaction_details['author']));
     #Get the fee lines
     $data['feedetails'] = $this->Query_reader->get_row_as_array('search_fees_structure', array('isactive' => 'Y', 'limittext' => '', 'searchstring' => ' AND id = ' . $transaction_details['fee']));
     #Check if the student belongs to the current user's school
     if ($data['studentdetails']['school'] != $this->myschool['id']) {
         $data = array();
         $studentid = '';
         $data['msg'] = 'ERROR : The student data could not be found.';
     }
     #Format the statement
     $report_html = '';
     #$financial_details = array();
     $this->load->library('parser');
     $data['report_html'] = $report_html;
     $output = $this->parser->parse('incl/transaction', $data, true);
     gen_pdf($this, $output);
     #$this->load->view('incl/print_data', $data);
 }