function setData($bacs_reference, $payments, &$errors = array(), $data, $plpayment) { $this->bacs_reference = $bacs_reference; $this->payments = $payments; $this->plpayment = $plpayment; $account = DataObjectFactory::Factory('CBAccount'); if (isset($data['cb_account_id'])) { $account->load($data['cb_account_id']); } $this->account = $account; $userPreferences = UserPreferences::instance(EGS_USERNAME); $defaultPrinter = $userPreferences->getPreferenceValue('default_printer', 'shared'); $params = $data['print']; $print_params = array(); $params['printer'] = empty($data['printer']) ? $defaultPrinter : $data['printer']; if (!$this->controller->setPrintParams($params, $print_params, $errors)) { $errors[] = 'Failed to set print parameters'; } $year = date('y'); $create_date = bcadd(date('z'), 1, 0); $this->create_date = $year . str_pad($create_date, 3, '0', STR_PAD_LEFT); $expiry_date = bcadd(date('z', strtotime($this->plpayment->payment_date)), 1, 0); $processing_date = bcadd(date('z', strtotime($this->getProcessDate($plpayment->payment_date))), 1, 0); $this->processing_date = $year . str_pad($processing_date, 3, '0', STR_PAD_LEFT); $this->expiry_date = $year . str_pad($expiry_date, 3, '0', STR_PAD_LEFT); if ($plpayment->override === 'f') { $this->validate(array('payment_date' => un_fix_date($plpayment->payment_date)), $errors); if ($this->processing_date <= $this->create_date) { $errors[] = 'Invalid Processing Date'; } } }
function __construct($getCurrentValues = true) { parent::__construct(); $userPreferences = UserPreferences::instance(); $this->setModuleName('contacts'); $roleCollection = new RoleCollection(); $sh = new SearchHandler($roleCollection, false); $sh->AddConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); $sh->setOrderby('name'); $roleCollection->load($sh); $roles = array(); foreach ($roleCollection->getContents() as $role) { $roles[$role->id] = array('value' => $role->id, 'label' => $role->name); if ($getCurrentValues) { if (in_array($role->id, $userPreferences->getPreferenceValue('default-read-roles', 'contacts'))) { $roles[$role->id]['selected'] = true; } } } $this->registerPreference(array('name' => 'default-read-roles', 'display_name' => 'Default Read Access', 'type' => 'select_multiple', 'data' => $roles, 'default' => array())); foreach ($roleCollection->getContents() as $role) { $roles[$role->id] = array('value' => $role->id, 'label' => $role->name); if ($getCurrentValues) { if (in_array($role->id, $userPreferences->getPreferenceValue('default-write-roles', 'contacts'))) { $roles[$role->id]['selected'] = true; } } } $this->registerPreference(array('name' => 'default-write-roles', 'display_name' => 'Default Write Access', 'type' => 'select_multiple', 'data' => $roles, 'default' => array())); }
function __construct($getCurrentValues = true) { parent::__construct(); $userPreferences = UserPreferences::instance(); $this->setModuleName('calendar'); $view = 'day'; if ($getCurrentValues) { $view = $userPreferences->getPreferenceValue('default-calendar-view', 'calendar'); } $this->registerPreference(array('name' => 'default-calendar-view', 'display_name' => 'Default View', 'type' => 'select', 'value' => $view, 'data' => array(array('label' => 'Day', 'value' => 'day'), array('label' => 'Week', 'value' => 'week'), array('label' => 'Month', 'value' => 'month')), 'default' => 'week')); }
public function Index() { $userPreferences = UserPreferences::instance(EGS_USERNAME); if ($userPreferences->userCanSetPreferences() && !$userPreferences->userHasPreferences()) { $message = "<strong>Welcome to EGS. It looks like this is your first time using the system, or you have not yet got round to setting your preferences.</strong><br />\n You can <a href=\"/?module=dashboard&controller=preferences\">setup your preferences now</a>, or use the 'Preferences' link that is available in the top right of your screen when using the system."; $this->view->set("info_message", $message); } parent::index(); $this->view->set('usealternative', false); $this->view->set('page_title', $this->getPageName()); }
function smarty_function_advanced_search($params, &$smarty) { $data = array('action' => ''); $self = $smarty->getTemplateVars('self'); unset($self['pid'], $self['module'], $self['modules'], $self['controller'], $self['action']); $data['additional_data'] = $self; if (isset($params['action'])) { $data['action'] = $params['action']; } $userPreferences = UserPreferences::instance(); $pdf_browser_printing = $userPreferences->getPreferenceValue('pdf-browser-printing', 'shared'); if (!empty($pdf_browser_printing) && $pdf_browser_printing == 'on') { $data['additional_data']['printaction'] = 'quick_output'; } // fetch smarty plugin template return smarty_plugin_template($smarty, $data, 'function.advanced_search'); }
public function save() { $module = $this->getPreferenceClass($this->_data['__moduleName']); $preferenceNames = $module->getPreferenceNames(); $flash = Flash::Instance(); $userPreferences = UserPreferences::instance(); // FIXME: Validate incomming data against supplied values foreach ($preferenceNames as $preferenceName) { if (isset($this->_data[$preferenceName])) { $pref = $module->getPreference($preferenceName); if (isset($pref['type']) && $pref['type'] == 'numeric') { if (!is_numeric($this->_data[$preferenceName])) { $flash->addError($pref['display_name'] . ' must be numeric'); continue; } } $userPreferences->setPreferenceValue($preferenceName, $this->_data['__moduleName'], $this->_data[$preferenceName]); } else { $preference = $module->getPreference($preferenceName); switch ($preference['type']) { case 'checkbox': $userPreferences->setPreferenceValue($preferenceName, $this->_data['__moduleName'], 'off'); break; case 'select_multiple': $userPreferences->setPreferenceValue($preferenceName, $this->_data['__moduleName'], array()); break; } } } $handled = $module->getHandledPreferences(); foreach ($handled as $name => $preference) { if (!empty($this->_data[$name]) && isset($preference['callback'])) { $callback = array($module, $preference['callback']); call_user_func($callback, $this->_data); } } // Do stuff. $flash->addMessage(prettify($this->_data['__moduleName']) . ' preferences saved successfully'); sendTo('', '', $this->_modules); }
public function printMultipleBalance() { $flash = Flash::Instance(); $errors = array(); $extra = array(); if (!isset($this->_data['WHLocation_location']) || empty($this->_data['WHLocation_location'])) { $errors[] = 'Location is a required field'; } if (!isset($this->_data['WHBin_bins']) || empty($this->_data['WHBin_bins'])) { $errors[] = 'Bin is a required field'; } if (count($errors) > 0) { $flash->addErrors($errors); sendBack(); } // Check and set default print set $userPreferences = UserPreferences::instance(EGS_USERNAME); $defaultPrinter = $userPreferences->getPreferenceValue('default_printer', 'shared'); if (empty($defaultPrinter)) { $flash->addError('Cannot print without a default printer set'); sendBack(); } else { $this->_data['printtype'] = 'pdf'; $this->_data['printaction'] = 'Print'; $this->_data['printer'] = $defaultPrinter; } // construct constraint against bins $stbalances = new STBalanceCollection(); $sh = new SearchHandler($stbalances, FALSE); $sh->addConstraint(new Constraint('balance', '<>', 0)); $sh->addConstraint(new Constraint('whstore_id', '=', $this->_data['WHStore_store'])); $sh->addConstraint(new Constraint('whlocation_id', '=', $this->_data['WHLocation_location'])); $binlist = implode(',', $this->_data['WHBin_bins']); $sh->addConstraint(new Constraint('whbin_id', 'in', '(' . $binlist . ')')); $sh->setOrderby(array('whbin', 'stitem'), array('ASC', 'ASC')); $stbalances->load($sh); // set title $WHLocation = $this->_templateobject; $WHLocation->load($this->_data['WHLocation_location']); $WHStore = DataObjectFactory::Factory('WHStore'); $WHStore->load($this->_data['WHStore_store']); $extra['title'] = 'Stock Balance for ' . $WHStore->description . ' / ' . $WHLocation->description . ' as at ' . un_fix_date(fix_date(date(DATE_FORMAT))); // construct xml $xml = $this->generateXML(array('model' => $stbalances, 'load_relationships' => FALSE, 'extra' => $extra)); // build a basic list of options $options = array('report' => 'MF_MultipleStockBalance', 'xmlSource' => $xml); // construct the document, caputre the response $response = json_decode($this->constructOutput($this->_data, $options)); // output success / failure message if ($response->status !== TRUE) { $flash->addError("Error printing document » " . $response->message); } else { $flash->addMessage("Document printed successfully"); } // return back to eglet sendBack(); }
function getCalendars() { $userPreferences = UserPreferences::instance(); $view = $userPreferences->getPreferenceValue('default-calendar-view', 'calendar'); $display_options = unserialize($userPreferences->getPreferenceValue('display-calendar-filter', 'calendar')); $calendars = array(); $calendars = $this->getCalendarList($display_options); echo json_encode($calendars); exit; }
function save() { $userPreferences = UserPreferences::instance(); $userPreferences->setPreferenceValue($this->name, '_pagelists', $this->queue); }
static function getPreferencesClass($username = EGS_USERNAME) { if ($username == EGS_USERNAME) { // get preferences for logged in user $prefs =& UserPreferences::instance($username); } else { // get preferences for named user $prefs =& ManagedUserPreferences::instance($username); } return $prefs; }
/** * Gets the printing preferences * * @access public * @return array */ public function get_printing_preferences($options) { $prefs = array('pdf_preview' => FALSE, 'pdf_browser_printing' => FALSE); // the success page structure will depend on pdf-preview and pdf-browser-printing // being enabled, go fetch these values from the users preferences $userPreferences = UserPreferences::instance(); $pdf_preview = $userPreferences->getPreferenceValue('pdf-preview', 'shared'); $pdf_browser_printing = $userPreferences->getPreferenceValue('pdf-browser-printing', 'shared'); // set pdf_preview + pdf_browser_printing states if (!empty($pdf_preview) && $pdf_preview == 'on' && HAS_CONVERT === TRUE) { $prefs['pdf_preview'] = TRUE; } if (!empty($pdf_browser_printing) && $pdf_browser_printing == 'on') { $prefs['pdf_browser_printing'] = TRUE; } if ($prefs['pdf_preview'] === TRUE) { $prefs['pdf_preview_build_link'] = htmlspecialchars_decode(link_to(array('module' => $this->module, 'controller' => $this->name, 'action' => 'build_pdf_preview'), FALSE, FALSE)); $prefs['pdf_preview_location'] = $options['paths']['temp_file_path']; } // merge prefs back in with options $options += $prefs; return $options; }
public function printAction() { $userPreferences = UserPreferences::instance(EGS_USERNAME); $defaultPrinter = $userPreferences->getPreferenceValue('default_printer', 'shared'); if (empty($defaultPrinter)) { // Use normal print action parent::printAction(); $this->printtype = array('pdf' => 'PDF'); $this->printaction = array('Print' => 'Print'); } else { // Overide print action $data = array(); $data['id'] = $this->_data['id']; $data['printtype'] = 'pdf'; $data['printaction'] = 'Print'; $data['printer'] = $defaultPrinter; sendTo($this->name, $this->_data['printaction'], $this->_modules, $data); } }
public function save_confirmsale() { if (!isset($this->_data) || !$this->loadData()) { $this->dataError(); sendBack(); } $sorder = $this->_uses[$this->modeltype]; $sorder_data = $this->_data[$this->modeltype]; $flash = Flash::Instance(); $errors = array(); $db = DB::Instance(); $db->startTrans(); $slcustomer = DataObjectFactory::Factory('SLCustomer'); $slcustomer->load($sorder->slmaster_id); // save the customer details // Existing or new person? $person_data = array(); if (!empty($sorder_data['person_id']) && $sorder_data['person_id'] > 0) { // Existing person $sorder->person_id = $sorder_data['person_id']; $person = DataObjectFactory::Factory('Person'); $person->load($sorder_data['person_id']); if ($person->isLoaded()) { $sorder_data['party_id'] = $person->party_id; } } elseif (!empty($sorder_data['surname'])) { // TODO: Saving of person and party data needs to move to appropriate model // See also EmployeesController, CompanysController and PersonsController // new person $sorder_data['party_id'] = ''; $person_data['Party']['id'] = ''; $person_data['Party']['type'] = 'Person'; $person_data['Person']['title'] = $sorder_data['title']; $person_data['Person']['firstname'] = $sorder_data['firstname']; $person_data['Person']['surname'] = $sorder_data['surname']; $person_data['Person']['id'] = ''; $person_data['Person']['party_id'] = ''; $person_data['Person']['company_id'] = $slcustomer->company_id; $index = 0; foreach (array('phone', 'email') as $contact_type) { if (!empty($sorder_data[$contact_type])) { $cm = DataObjectFactory::Factory('PartyContactMethod'); $person_data[$index]['Contactmethod']['id'] = ''; $person_data[$index]['Contactmethod']['contact'] = $sorder_data[$contact_type]; $person_data[$index]['PartyContactMethod']['id'] = ''; $person_data[$index]['PartyContactMethod']['contactmethod_id'] = ''; $person_data[$index]['PartyContactMethod']['party_id'] = ''; $person_data[$index]['PartyContactMethod']['name'] = 'MAIN'; $person_data[$index]['PartyContactMethod']['type'] = $cm->getType($contact_type); $person_data[$index]['PartyContactMethod']['main'] = 't'; $person_data[$index]['PartyContactMethod']['billing'] = 't'; $person_data[$index]['PartyContactMethod']['shipping'] = 't'; $person_data[$index]['PartyContactMethod']['payment'] = 't'; $person_data[$index]['PartyContactMethod']['technical'] = 't'; $index++; } } if (parent::save('Person', $person_data, $errors)) { foreach ($this->saved_models as $model) { if (isset($model['Person'])) { $person = $model['Person']; $sorder->person_id = $person->id; $sorder_data['party_id'] = $person->party_id; } } } else { $errors[] = 'Error saving Customer Details : ' . $db->ErrorMsg(); } } foreach (array('invoice' => $sorder_data['inv_address_id'], 'delivery' => $sorder_data['del_address_id']) as $address_type => $address_id) { $address_data = array(); if (!empty($sorder_data[$address_type]['street1'])) { // New address $address_data['Address']['id'] = ''; $address_data['Address']['street1'] = $sorder_data[$address_type]['street1']; $address_data['Address']['street2'] = $sorder_data[$address_type]['street2']; $address_data['Address']['street3'] = $sorder_data[$address_type]['street3']; $address_data['Address']['town'] = $sorder_data[$address_type]['town']; $address_data['Address']['county'] = $sorder_data[$address_type]['county']; $address_data['Address']['postcode'] = $sorder_data[$address_type]['postcode']; $address_data['Address']['countrycode'] = $sorder_data[$address_type]['countrycode']; $address_data['PartyAddress']['address_id'] = ''; } elseif (!empty($person_data['Person'])) { // Existing address needs to be linked to new person $address_data['PartyAddress']['address_id'] = $address_id; } if (!empty($sorder_data[$address_type]['street1']) || !empty($person_data['Person'])) { // If new address or new person, link address to party $address_data['PartyAddress']['id'] = ''; $address_data['PartyAddress']['party_id'] = $sorder_data['party_id']; $address_data['PartyAddress']['name'] = 'MAIN'; $address_data['PartyAddress']['main'] = $address_type == 'invoice' ? 't' : 'f'; $address_data['PartyAddress']['billing'] = $address_type == 'invoice' ? 't' : 'f'; $address_data['PartyAddress']['shipping'] = $address_type == 'delivery' ? 't' : 'f'; $address_data['PartyAddress']['payment'] = $address_type == 'invoice' ? 't' : 'f'; $address_data['PartyAddress']['technical'] = 'f'; if (parent::save('Address', $address_data, $errors)) { foreach ($this->saved_models as $model) { if (isset($model['Address'])) { $address = $model['Address']; if ($address_type == 'invoice') { $sorder_data['inv_address_id'] = $address->id; } else { $sorder_data['del_address_id'] = $address->id; } } } } else { $errors[] = 'Error saving Customer ' . $address_type . ' Address Details : ' . $db->ErrorMsg(); } } } if (!empty($sorder_data['inv_address_id']) && $sorder_data['inv_address_id'] > 0) { $sorder->inv_address_id = $sorder_data['inv_address_id']; } if (!empty($sorder_data['del_address_id']) && $sorder_data['del_address_id'] > 0) { $sorder->del_address_id = $sorder_data['del_address_id']; } else { $sorder->del_address_id = $sorder_data['inv_address_id']; } if (count($errors) > 0 || !$sorder->save()) { $errors[] = 'Error updating customer order details'; } // create and post the invoice if (count($errors) == 0) { $invoice = $this->createPostInvoice($sorder, $errors); } // Create the Payment if (count($errors) == 0) { $cb_data = array(); $cb_data['cb_account_id'] = $slcustomer->cb_account_id; $cb_data['source'] = 'S'; $cb_data['slmaster_id'] = $sorder->slmaster_id; $cb_data['company_id'] = $slcustomer->company_id; if ($sorder->person_id > 0) { $cb_data['person_id'] = $sorder->person_id; } $cb_data['ext_reference'] = $sorder_data['ext_reference']; $cb_data['payment_term_id'] = $slcustomer->payment_term_id; $cb_data['payment_type_id'] = $sorder_data['payment_type_id']; $cb_data['transaction_type'] = 'R'; $cb_data['currency_id'] = $sorder->currency_id; $cb_data['transaction_date'] = date(DATE_FORMAT); // $cb_data['net_value'] = $sorder_data['gross_value']; $cb_data['net_value'] = bcsub($invoice->gross_value, $invoice->settlement_discount); if (!SLTransaction::saveTransaction($cb_data, $errors)) { $errors[] = 'Error saving Payment Details'; } } // Match Payment to Invoice if (count($errors) == 0) { if ($invoice->isLoaded()) { $invoice_trans = DataObjectFactory::Factory('SLTransaction'); $invoice_trans->identifierField = gross_value; $cc = new ConstraintChain(); $cc->add(new Constraint('transaction_type', '=', 'I')); $cc->add(new Constraint('status', '=', 'O')); $cc->add(new Constraint('our_reference', '=', $invoice->invoice_number)); $transactions = $invoice_trans->getAll($cc); $transactions[$cb_data['ledger_transaction_id']] = $cb_data['payment_value']; // Save settlement discount if present? if ($invoice->settlement_discount > 0) { $payment_term = DataObjectFactory::Factory('PaymentTerm'); $payment_term->load($slcustomer->payment_term_id); // Create GL Journal for settlement discount $discount = $cb_data; $discount['gross_value'] = $discount['net_value'] = $invoice->settlement_discount; $discount['glaccount_id'] = $payment_term->sl_discount_glaccount_id; $discount['glcentre_id'] = $payment_term->sl_discount_glcentre_id; $discount['tax_value'] = '0.00'; $discount['source'] = 'S'; $discount['transaction_type'] = 'SD'; $discount['description'] = !empty($payment_term->sl_discount_description) ? $payment_term->sl_discount_description . ' ' : ''; $discount['description'] .= $cb_data->description; $discount['status'] = 'P'; $sldiscount = SLTransaction::Factory($discount, $errors, 'SLTransaction'); if ($sldiscount && $sldiscount->save('', $errors) && $sldiscount->saveGLTransaction($discount, $errors)) { $transactions[$sldiscount->{$sldiscount->idField}] = bcadd($discount['net_value'], 0); } else { $errors[] = 'Errror saving Settlement Discount : ' . $db->ErrorMsg(); $flash->addErrors($errors); } } if (!SLTransaction::allocatePayment($transactions, $invoice->slmaster_id, $errors) || !SLAllocation::saveAllocation($transactions, $errors)) { $errors[] = 'Error allocating Payment'; } } else { $errors[] = 'Error matching to Invoice'; } } // Check for errors if (count($errors) > 0) { $flash->clear(); $flash->addErrors($errors); $flash->addError('Sale confirmation failed'); $db->failTrans(); } else { $flash->addMessage('Sale Confirmed'); } $db->CompleteTrans(); if (count($errors) == 0) { // now print the invoice to the users default printer $userPreferences = UserPreferences::instance(EGS_USERNAME); $defaultPrinter = $userPreferences->getPreferenceValue('default_printer', 'shared'); if (empty($defaultPrinter)) { // Use normal print action // ATTN: what happens here? If we don't have a default printer set it's going to ignore our request? $this->_data['invoice_id'] = $invoice->id; $this->_data['printaction'] = 'printinvoice'; parent::printaction(); $this->printaction = array('Print' => 'Print'); $this->printtype = array('pdf' => 'PDF'); $this->_templateName = $this->getTemplateName('printaction'); return; } else { // Overide print action $data = array(); $data['invoice_id'] = $invoice->id; $data['printtype'] = 'pdf'; $data['printaction'] = 'Print'; $data['printer'] = $defaultPrinter; // call printInvoice and decode the response, output errors / messages $response = json_decode($this->printInvoice($invoice, $data)); if ($response->status === true) { $flash->addMessage('Print Sales Invoice Completed'); $invoice->update($invoice->id, array('date_printed', 'print_count'), array(fix_date(date(DATE_FORMAT)), $invoice->print_count + 1)); } else { $flash->addError('Print Sales Invoice Failed'); $flash->addError($response->message); } } // we're not using JavaScript to get here // so just go back to the order view } sendTo($this->name, 'view', $this->_modules, array('id' => $sorder->id)); }
public function extractPaging($page = '', $perpage = '') { if (!empty($perpage)) { $this->perpage = $perpage; } elseif (isset($_GET['perpage'])) { $this->perpage = intval($_GET['perpage']); } elseif (defined('EGS_USERNAME')) { $userPreferences = UserPreferences::instance(EGS_USERNAME); $this->perpage = $userPreferences->getPreferenceValue('items-per-page', 'shared'); } else { $this->perpage = 10; } if (!is_numeric($this->perpage)) { $this->perpage = 10; } if (!empty($page)) { $this->page = $page; } elseif (isset($_GET['page'])) { $this->page = intval($_GET['page']); } else { $this->page = 1; } if (!is_numeric($this->page)) { $this->page = 1; } if ($this->page > $this->lastpage) { $this->page = $this->lastpage; } elseif ($this->page < 1) { $this->page = 1; } $this->offset = ($this->page - 1) * $this->perpage; }