コード例 #1
0
ファイル: _report.php プロジェクト: nwtug/pss-version-1.0
 function stats($type, $financialYear = '')
 {
     $financialYear = !empty($financialYear) ? $financialYear : get_current_quarter('financial_year');
     switch ($type) {
         case 'pde':
             return $this->_query_reader->get_row_as_array('get_pde_stats', array('pde_id' => $this->native_session->get('__organization_id'), 'start_date' => get_quarter_date($financialYear . '-all', 'start'), 'end_date' => get_quarter_date($financialYear . '-all', 'end')));
             break;
             # TODO: add more stats here
         # TODO: add more stats here
         default:
             return array();
             break;
     }
 }
コード例 #2
0
 function add_details($data)
 {
     $reason = '';
     $data['financialperiod'] = $data['fystart__financialperiods'] . '-all';
     if (empty($data['plan_id'])) {
         $planCount = $this->_query_reader->get_count('get_procurement_plan_by_data', array('pde_id' => $data['pde_id'], 'financial_year_start' => get_quarter_date($data['financialperiod'], 'start'), 'financial_year_end' => get_quarter_date($data['financialperiod'], 'end')));
     }
     # proceed with the addition if this is a unique plan
     if (!empty($data['plan_id']) || empty($data['plan_id']) && $planCount == 0) {
         $planId = $this->_query_reader->add_data((!empty($data['plan_id']) ? 'edit' : 'add') . '_procurement_plan', array('organization_id' => $data['pde_id'], 'financial_year_start' => get_quarter_date($data['financialperiod'], 'start'), 'financial_year_end' => get_quarter_date($data['financialperiod'], 'end'), 'title' => htmlentities($data['name'], ENT_QUOTES), 'details' => '', 'document_url' => '', 'status' => $data['status__procurementplanstatus'], 'user_id' => $this->native_session->get('__user_id'), 'plan_id' => !empty($data['plan_id']) ? $data['plan_id'] : ''));
         $planId = !empty($data['plan_id']) ? $data['plan_id'] : $planId;
         # proceed with processing the procurement plan details
         if (!empty($planId)) {
             $this->native_session->set('plan_id', $planId);
             require_once HOME_URL . 'external_libraries/phpexcel/PHPExcel.php';
             $objPHPExcel = PHPExcel_IOFactory::load(UPLOAD_DIRECTORY . $data['document']);
             $sheetData = $objPHPExcel->getActiveSheet()->toArray('', true, true, true);
             $DATA_START = 9;
             $result = TRUE;
             $usefulData = array();
             # extract the useful data
             foreach ($sheetData as $i => $row) {
                 if ($i >= $DATA_START && !is_empty_row($row)) {
                     # where they can not edit
                     if (!empty($row['B']) && trim($row['B']) == 'DO NOT EDIT BELOW THIS LINE') {
                         break;
                     }
                     # put only categories with data
                     if (in_array(trim(strtolower($row['B'])), get_option_list($this, 'procurementcategories', 'array')) && !empty($sheetData[$i + 1]['D'])) {
                         array_push($usefulData, $row);
                     } else {
                         if (!empty($row['D'])) {
                             # convert back to UK format if excel importer converted the dates to US format
                             $tempRow = $row;
                             foreach ($tempRow as $key => $value) {
                                 if (strtolower($key) > 'd') {
                                     if (strpos($value, '/', 3) !== FALSE) {
                                         $value = date('m-d-y', strtotime(make_us_date($value)));
                                     }
                                     # correct dates in the format 12-31-15 as they can not be converted correctly
                                     if (strpos($value, '-', 3) !== FALSE && strlen($value) == 8) {
                                         $valueParts = explode('-', $value);
                                         if (count($valueParts) > 2) {
                                             $value = substr(@date('Y'), 0, 2) . $valueParts[2] . '-' . $valueParts[0] . '-' . $valueParts[1];
                                         }
                                     }
                                     $row[$key] = !empty($value) ? date('d/m/Y', strtotime($value)) : '';
                                 }
                             }
                             array_push($usefulData, $row);
                         }
                     }
                 }
             }
             # remove the old sheet data
             if (!empty($usefulData) && !empty($data['plan_id'])) {
                 $result = $this->_query_reader->run('remove_plan_detail_rows', array('plan_id' => $data['plan_id']));
             }
             # add the new sheet data
             foreach ($usefulData as $row) {
                 # save the rows with data
                 $rowData = array_merge($row, array('plan_id' => $planId, 'user_id' => $this->native_session->get('__user_id')));
                 $result = $this->_query_reader->run('add_plan_detail_row', $rowData);
             }
             # return with the list of added items for immediate display
             if ($result) {
                 return $this->_query_reader->get_list('get_procurement_plan_details', array('plan_id' => $planId));
             } else {
                 $reason = "The plan details could not be fully recorded.";
             }
         } else {
             $reason = "The plan headers could not be recorded.";
         }
     } else {
         $reason = "This PDE already has a plan for the same financial period. Please edit that instead.";
     }
     return $reason;
 }