/** * Changes sign position based on language * @param float $number * @param string $currency * @param array $options * @return string */ public function currency($number, $currency = 'USD', $options = array()) { // Every total and price and stored in cents in DB $number = round(intval($number) / 100, 2); if (Configure::read('Config.language') == 'fr') { $options['wholePosition'] = 'after'; $options['decimals'] = ','; } $options['fractionSymbol'] = '¢'; $indicator = sprintf('<i class="currency">%s</i>', Configure::read('Config.language') == 'fr' ? 'CA' : 'C'); $result = parent::currency($number, $currency, $options); if (Configure::read('Config.language') == 'fr') { return $result . ' ' . $indicator; } else { return $indicator . ' ' . $result; } }
public function downloadExcel() { $this->autoRender = false; $this->layout = ''; $data['Linnworksapi']['order_type'] = $this->request->data['Linnworksapis']['order_type']; $data['Linnworksapi']['location'] = $this->request->data['Linnworksapis']['location']; $data['Linnworksapi']['source'] = $this->request->data['Linnworksapis']['source']; $data['Linnworksapi']['subsource'] = $this->request->data['Linnworksapis']['subsource']; $data['Linnworksapi']['datefrom'] = $this->request->data['Linnworksapis']['datefrom']; $data['Linnworksapi']['dateto'] = $this->request->data['Linnworksapis']['dateto']; $data['Linnworksapi']['orderid'] = $this->request->data['Linnworksapis']['orderid']; App::import('Helper', 'Soap'); $SoapHelper = new SoapHelper(new View(null)); $getData = $SoapHelper->getFilteredOrder($data); App::import('Helper', 'Number'); $numberHelper = new NumberHelper(new View(null)); App::import('Vendor', 'PHPExcel/IOFactory'); App::import('Vendor', 'PHPExcel'); $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', 'OrderItemNumber'); $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Name'); $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Address'); $objPHPExcel->getActiveSheet()->setCellValue('D1', 'Postcode'); $objPHPExcel->getActiveSheet()->setCellValue('E1', 'Country'); $objPHPExcel->getActiveSheet()->setCellValue('F1', 'Item Count'); $objPHPExcel->getActiveSheet()->setCellValue('G1', 'Contents'); $objPHPExcel->getActiveSheet()->setCellValue('H1', 'Total Packet Value'); $objPHPExcel->getActiveSheet()->setCellValue('I1', 'Weight'); $objPHPExcel->getActiveSheet()->setCellValue('J1', 'HS'); $objPHPExcel->getActiveSheet()->setCellValue('K1', 'Deposit'); $objPHPExcel->getActiveSheet()->setCellValue('L1', 'Invoice Number'); $objPHPExcel->getActiveSheet()->setCellValue('M1', 'Bag barcode'); $i = 2; foreach ($getData->GetFilteredOrdersResponse->GetFilteredOrdersResult->Orders->Order as $order) { $contents = array(); $orderItems = array(); foreach ($order->OrderItems->OrderItem as $item) { $contents[] = $item->Qty . ' X ' . $item->ItemTitle; $orderItems[] = $item->OrderItemNumber; } $content = implode(" \n", $contents); $orderItem = implode(" \n", $orderItems); $itemCount = count($order->OrderItems->OrderItem); $address = $order->ShippingAddress->Address1 . ',' . $order->ShippingAddress->Address2 . ',' . $order->ShippingAddress->Address3; $address = explode(',', $address); $address = implode(" \n ", $address); $objPHPExcel->getActiveSheet()->setCellValue('A' . $i . '', $orderItem); $objPHPExcel->getActiveSheet()->setCellValue('B' . $i . '', $order->ShippingAddress->Name); $objPHPExcel->getActiveSheet()->setCellValue('C' . $i . '', $address); $objPHPExcel->getActiveSheet()->setCellValue('D' . $i . '', $order->ShippingAddress->PostCode); $objPHPExcel->getActiveSheet()->setCellValue('E' . $i . '', $order->ShippingAddress->CountryCode); $objPHPExcel->getActiveSheet()->setCellValue('F' . $i . '', $itemCount); $totlaCost = $numberHelper->currency($order->TotalCost, 'EUR'); $objPHPExcel->getActiveSheet()->setCellValue('G' . $i . '', $content); $objPHPExcel->getActiveSheet()->setCellValue('H' . $i . '', $totlaCost); $objPHPExcel->getActiveSheet()->setCellValue('I' . $i . '', '5'); $objPHPExcel->getActiveSheet()->setCellValue('J' . $i . '', '5'); $objPHPExcel->getActiveSheet()->setCellValue('K' . $i . '', '5'); $objPHPExcel->getActiveSheet()->setCellValue('L' . $i . '', '5'); $objPHPExcel->getActiveSheet()->setCellValue('M' . $i . '', '5'); $i++; } if ($this->request->data['Linnworksapis']['order_type'] == 0) { $objPHPExcel->getActiveSheet()->setTitle('Open Order'); $objPHPExcel->createSheet(); $name = 'Open Order'; } if ($this->request->data['Linnworksapis']['order_type'] == 1) { $objPHPExcel->getActiveSheet()->setTitle('Processed Order'); $objPHPExcel->createSheet(); $name = 'Procesed Order'; } if ($this->request->data['Linnworksapis']['order_type'] == 2) { $objPHPExcel->getActiveSheet()->setTitle('Cancelled Order'); $objPHPExcel->createSheet(); $name = 'Cancelled Order'; } header('Content-Encoding: UTF-8'); header('Content-type: text/csv; charset=UTF-8'); header('Content-Disposition: attachment;filename="' . $name . '.csv"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV'); $objWriter->save('php://output'); }
function search_result() { App::import('Helper', 'Number'); $number = new NumberHelper(); $search_options = $this->Session->read('search_options'); if (empty($search_options['Property']['property_types'])) { $search_options['Property']['property_types'][] = 'RESI'; } /* debug($search_options); */ $this->pageTitle = 'Search Results'; $properties = null; $search_list = array(); $conditions = array(); if (!empty($search_options['County']['id'])) { $this->County->recursive = -1; $county_name = $this->County->read('County.name', $search_options['County']['id']); $county = $county_name['County']['name']; $conditions[] = array('Property.County' => $county); $search_list[] = 'County: ' . $county; } if (!empty($search_options['City']) && !isset($search_options['Property']['search_by_county'])) { //$conditions[] = array('Property.City' => Inflector::humanize($search_options['City'])); // find by city if (count($search_options['City']) == 1) { if (is_string($search_options['City'])) { $search_options['City'] = Inflector::humanize($search_options['City']); $search_list[] = 'City: ' . Inflector::humanize($search_options['City']); } } if ($search_options['City'] != '---') { /* $conditions[] = array('Property.City' => $search_options['City']); // find by city */ // if we get no results try using the city slug as a lookup $my_slug = null; /* debug($search_options['City']); */ if (is_string($search_options['City'])) { $my_slug = strtolower(Inflector::slug($search_options['City'])); } else { if (is_array($search_options['City'])) { } } $this->City->recursive = -1; if (!empty($my_slug)) { $search_city = $this->City->find('first', array('conditions' => array('City.slug' => $my_slug))); } $city_variants = array(); if (!empty($search_city['City']['name'])) { $city_variants[] = $search_city['City']['name']; } if (!empty($search_city['City']['slug'])) { $city_variants[] = $search_city['City']['slug']; } if (!empty($search_options['City'])) { $city_variants[] = $search_options['City']; } $city_variants = $city_variants[0]; $conditions[] = array('Property.City' => $city_variants); } if (is_array($search_options['City'])) { foreach ($search_options['City'] as $key => $value) { $search_list[] = 'City: ' . Inflector::humanize($value); } sort($search_list); } } if (isset($search_options['City']) && is_string($search_options['City'])) { $search_options['City'] = Inflector::humanize($search_options['City']); } if (isset($search_options['Property']['search_by_county'])) { $search_list[] = 'County: ' . $search_options['County']['name']; if ($search_options['County']['name']) { $conditions[] = array('Property.County' => $search_options['County']['name']); } if (true) { if (!empty($search_options['City']['name'])) { $conditions[] = array('Property.City' => $search_options['City']['name']); } } } if (!empty($search_options['Property']['zip_code'])) { // find by zip code $conditions[] = array('Property.Zip_Code' => $search_options['Property']['zip_code']); $search_list[] = 'Zip Code ' . $search_options['Property']['zip_code']; } if (!empty($search_options['Property']['price_low'])) { // find by min price /* preg_replace ('/[^\d]/', '', $search_options['Property']['price_low']) */ /* $conditions[] = array('Property.Search_Price >=' => $search_options['Property']['price_low']); */ $conditions[] = array('Property.Search_Price >=' => $search_options['Property']['price_low']); $search_list[] = 'Min. Price: ' . $number->currency($search_options['Property']['price_low']); } if (!empty($search_options['Property']['price_high'])) { // find by max price /* $conditions[] = array('Property.Search_Price <=' => $search_options['Property']['price_high']); */ $conditions[] = array('Property.Search_Price <=' => $search_options['Property']['price_high']); $search_list[] = 'Max. Price: ' . $number->currency($search_options['Property']['price_high']); } if (!empty($search_options['Property']['bedrooms'])) { // find by min. bedrooms $conditions[] = array('Property.Bedrooms >= ' => $search_options['Property']['bedrooms']); $search_list[] = 'Min. Bedrooms: ' . $search_options['Property']['bedrooms']; } if (!empty($search_options['Property']['bathrooms'])) { // find by min. bedrooms $conditions[] = array('Property.Full_Bathrooms >= ' => $search_options['Property']['bathrooms']); $search_list[] = 'Min. Bathrooms: ' . $search_options['Property']['bathrooms']; } if (!empty($search_options['Property']['senior'])) { // find by senior community foreach ($search_options['Property']['property_types'] as $my_property_type) { $conditions['OR'][] = array('Property.' . strtoupper($my_property_type) . '_Senior_Desc' => array('Yes', 1)); } $search_list[] = 'Senior Communities Only'; } if (isset($search_options['City'])) { if ((is_string($search_options['City']) || count($search_options['City']) == 1) && $search_options['City'] != 0) { $search_list[] = 'City: ' . $search_options['City']; } } if (isset($search_options['Property']['transaction_type']) && !empty($search_options['Property']['transaction_type'])) { $conditions[] = array('Property.transaction_type' => $search_options['Property']['transaction_type']); foreach ($search_options['Property']['transaction_type'] as $value) { $search_list[] = 'Transaction Type: ' . $this->transaction_types[$value]; } } if (isset($search_options['Property']['property_types']) && !empty($search_options['Property']['property_types'])) { $conditions[] = array('Property.Property_Type' => $search_options['Property']['property_types']); foreach ($search_options['Property']['property_types'] as $value) { $prop_type = $this->PropertyType->find('first', array('conditions' => array('PropertyType.code' => $value))); $search_list[] = 'Property Type: ' . $prop_type['PropertyType']['name']; } } if (is_array(@$search_options['Property']['property_subtype_1_display'])) { $search_options['Property']['property_subtype_1_display'] = array_merge($search_options['Property']['property_subtype_1_display'], $this->hidden_subtypes); } if (isset($search_options['Property']['property_subtype_1_display']) && !empty($search_options['Property']['property_subtype_1_display'])) { $conditions[] = array('Property.Property_Subtype_1_Display' => $search_options['Property']['property_subtype_1_display']); foreach ($search_options['Property']['property_subtype_1_display'] as $value) { if (isset($this->resi_subtypes[$value])) { $search_list[] = 'Property Type: ' . $this->resi_subtypes[$value]; } } } /* if(isset($search_options['Property']['limit'])){ //$conditions[] = array('limit' => $search_options['Property']['limit']); $this->params['named']['limit'] = $search_options['Property']['limit']; } */ /* $conditions[] = array('Property.County' => $search_options['County']['name']); */ /* debug($conditions); */ /* debug($search_options); */ if (isset($search_options['Property']['open_house_search'])) { /* $start_date = $search_options['Property']['Open_House_Start_Date']['month'].'-'.$search_options['Property']['Open_House_Start_Date']['day'].'-'.$search_options['Property']['Open_House_Start_Date']['year']; */ $start_date = $search_options['Property']['Open_House_Start_Date']['year'] . '-' . $search_options['Property']['Open_House_Start_Date']['month'] . '-' . $search_options['Property']['Open_House_Start_Date']['day']; $start_time = $search_options['Property']['Open_House_Start_Time']['hour'] . ':' . str_pad($search_options['Property']['Open_House_Start_Time']['min'], 2, '0', STR_PAD_RIGHT) . ' ' . $search_options['Property']['Open_House_Start_Time']['meridian']; //debug($start_time); $start_time = strtotime($start_time); //debug($start_time); $start_time = date("H:i:s", $start_time); //debug($start_time); $end_date = $search_options['Property']['Open_House_End_Date']['year'] . '-' . $search_options['Property']['Open_House_End_Date']['month'] . '-' . $search_options['Property']['Open_House_End_Date']['day']; $end_time = $search_options['Property']['Open_House_End_Time']['hour'] . ':' . str_pad($search_options['Property']['Open_House_End_Time']['min'], 2, '0', STR_PAD_RIGHT) . ' ' . $search_options['Property']['Open_House_End_Time']['meridian']; $end_time = strtotime($end_time); $end_time = date("H:i:s", $end_time); /* debug($start_date); debug($start_time); debug($end_date); debug($end_time); */ $start_date = $start_date . ' ' . $start_time; $end_date = $end_date . ' ' . $end_time; $conditions[] = array('Property.Open_House_Start_Timestamp >= ' => $start_date, 'Property.Open_House_Start_Timestamp <= ' => $end_date, 'Property.City <> ' => 'Y'); $search_list[] = 'Open Houses: ' . $start_date . ' - ' . $end_date; $this->set('open_house', 1); $this->paginate['order'] = 'Property.Open_House_Start_Timestamp ASC'; } $properties = $this->paginate('Property', $conditions); $this->Session->write('search_list', $search_list); $this->set('search_list', $search_list); if (count($properties) == 1) { // only 1 listing? Go straight to detail view $this->redirect(array('controller' => 'properties', 'action' => 'view', $properties[0]['Property']['ML_Number_Display'])); exit; } if (empty($properties)) { // no listings? print error and redirect to search form, add "filter" param to let search know we are modifying a previous set of inputs $this->Session->setFlash('Sorry, no properties were found matching your specified search criteria.'); if (Configure::read('debug') > 0) { exit; } /* if(Configure::read('debug') > 0){ */ $return_county = null; $return_open_house = null; if (isset($search_options['County']['name'])) { $return_county = '/county:' . strtolower(Inflector::slug($search_options['County']['name'])); } if (isset($search_options['Property']['open_house_search'])) { $return_open_house = '/open_house:1'; } $return_url = array('controller' => 'properties', 'action' => 'search', $return_county . $return_open_house); $this->redirect($return_url); /* } if(Configure::read('debug') ==0){ $this->redirect(array('controller' => 'properties', 'action' => 'search', 'filter')); } */ } else { // we have listings ... prep for render $count = 0; /*foreach($properties as $property){ // loop thru our current page and load the extra info (city/county data) $city = $this->City->find('first', array('conditions' => array('City.name' => $property['Property']['city']), 'fields' => 'City.id, City.name, County.id, County.name')); $properties[$count]['City'] = $city['City']; $properties[$count]['County'] = $city['County']; $count++; } */ $this->set(compact('properties')); if ($this->Session->valid('search_list')) { $this->set('search_list', $this->Session->read('search_list')); } /* debug($search_options); */ $this->set('search_options', $search_options); $this->render('index'); } }
/** * Wrapper to Number->currency() * * @param float $number * @param string $currency Valid values are 'USD', 'EUR', 'GBP' * @param array $options f.e. 'before' and 'after' options. */ static function currency($var, $curr = 'USD', $opts = array()) { $number = new NumberHelper(); return $number->currency($var, $curr, $opts); }