public function _new()
 {
     $flash = Flash::Instance();
     parent::_new();
     // Get the Purchase Invoice Line Object - if loaded, this is an edit
     $pinvoiceline = $this->_uses[$this->modeltype];
     if (!$pinvoiceline->isLoaded()) {
         if (empty($this->_data['invoice_id'])) {
             $flash->addError('No Purchase Invoice supplied');
             sendBack();
         }
         $pinvoiceline->invoice_id = $this->_data['invoice_id'];
     } else {
     }
     $pinvoice = DataObjectFactory::Factory('Pinvoice');
     $pinvoice->load($pinvoiceline->invoice_id);
     if (isset($this->_data[$this->modeltype])) {
         // We've had an error so refresh the page
         $pinvoiceline->line_number = $this->_data['PInvoiceLine']['line_number'];
         $_glaccount_id = $this->_data['PInvoiceLine']['glaccount_id'];
     } elseif ($pinvoiceline->isLoaded()) {
         $_glaccount_id = $pinvoiceline->glaccount_id;
     } else {
         $pinvoiceline->due_delivery_date = $pinvoice->due_date;
     }
     $glaccounts = $this->getAccount();
     $this->view->set('glaccount_options', $glaccounts);
     if (empty($_glaccount_id)) {
         $_glaccount_id = key($glaccounts);
     }
     $this->view->set('glcentre_options', $this->getCentres($_glaccount_id));
     $this->view->set('taxrate_options', $this->getTaxRate());
     $this->view->set('pinvoice', $pinvoice);
 }
 public function _new()
 {
     parent::_new();
     $flash = Flash::Instance();
     $sopackingslip = $this->_uses[$this->modeltype];
     if ($sopackingslip->isLoaded()) {
         // Get current packed totals on this packing list
         $contents = unserialize(base64_decode($sopackingslip->contents));
         $this->view->set('contents', $contents);
     }
     $order = DataObjectFactory::Factory('SOrder');
     $order->load($this->_data['order_id']);
     if ($order->isLoaded()) {
         $lines = array();
         $packed = $order->packing_slips->getPackedTotals();
         $this->view->set('packed', $packed);
         foreach ($order->lines as $line) {
             // Get total of all items on the order, excluding cancelled items
             if ($line->status != $line->cancelStatus()) {
                 $key = str_replace('"', '', $line->description);
                 if (isset($lines[$key])) {
                     $lines[$key] += $line->revised_qty;
                 } else {
                     $lines[$key] = $line->revised_qty;
                 }
             }
         }
         $this->view->set('lines', $lines);
     } else {
         $flash->addError('Cannot load order');
         sendBack();
     }
     $this->view->set('no_ordering', TRUE);
 }
Example #3
0
 public function _new($followup = FALSE)
 {
     if (array_key_exists('followup', $this->_data)) {
         $followup = $this->_data['followup'];
     }
     $this->view->set('page_title', 'New CRM Activity');
     // New follow-up activity
     if ($followup) {
         $this->view->set('page_title', 'New CRM Follow-up Activity');
         unset($this->_data['id']);
         $activity = new Activity();
         $activity->load($followup);
         $this->_data['person_id'] = $activity->person_id;
         $this->_data['company_id'] = $activity->company_id;
         $this->_data['name'] = $activity->name;
         $this->_data['description'] = $activity->description;
         $this->_data['completed'] = '';
     }
     // Edit existing activity
     if (isset($this->_data['id'])) {
         $this->view->set('page_title', 'Edit CRM Activity');
     }
     // New activity from opportunity
     if (isset($this->_data['opportunity_id'])) {
         $this->view->set('page_title', 'New CRM Activity');
         $opportunity = DataObjectFactory::Factory('Opportunity');
         $opportunity->load($this->_data['opportunity_id']);
         $this->_data['person_id'] = $opportunity->person_id;
         $this->_data['company_id'] = $opportunity->company_id;
     }
     parent::_new();
 }
Example #4
0
 public function clone_item()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     parent::_new();
 }
 public function _new()
 {
     // need to store the ajax flag in a different variable and the unset the original
     // this is to prevent any functions that are further called from returning the wrong datatype
     $ajax = isset($this->_data['ajax']);
     unset($this->_data['ajax']);
     parent::_new();
     $product = $this->_uses[$this->modeltype];
     $prod_groups = $this->getProductGroups();
     $this->view->set('prod_groups', $prod_groups);
     $glaccount = DataObjectFactory::Factory('GLAccount');
     $gl_accounts = $glaccount->nonControlAccounts();
     $this->view->set('gl_accounts', $gl_accounts);
     if (isset($_POST[$this->modeltype]['prod_group_id'])) {
         $product->prod_group_id = $_POST[$this->modeltype]['prod_group_id'];
     } elseif (!$product->isLoaded()) {
         $product->prod_group_id = key($prod_groups);
     }
     if (isset($_POST[$this->modeltype]['glaccount_id'])) {
         $product->glaccount_id = $_POST[$this->modeltype]['glaccount_id'];
     } elseif (!$product->isLoaded()) {
         $product->glaccount_id = key($gl_accounts);
     }
     $this->view->set('gl_centres', $this->getCentres($product->glaccount_id));
     $stitem_list = array('' => 'None');
     if ($product->isLoaded()) {
         $this->_data['stitem_id'] = $product->stitem_id;
         $product_lines = $product->getLineIds();
         $order_lines = $product->checkOrderlines($product_lines);
         $invoice_lines = $product->checkInvoicelines($product_lines);
     } else {
         $product_lines = array();
         $order_lines = array();
         $invoice_lines = array();
     }
     if (!empty($this->_data['stitem_id'])) {
         $stitem = $this->getItem($this->_data['stitem_id']);
         $this->view->set('stitem', $stitem);
         $this->view->set('description', $stitem);
         $product_group = $this->getProductGroups($this->_data['stitem_id']);
         $product->prod_group_id = $this->_data['prod_group_id'] = key($product_group);
         $this->view->set('product_group', current($product_group));
         $this->view->set('uoms', $this->getUomList($this->_data['stitem_id']));
     } else {
         $stitem_list = $this->getItems($product->prod_group_id);
         $this->view->set('stitems', $stitem_list);
         $this->view->set('uoms', $uom_list);
     }
     $tax_rates = array();
     if ($product && $product->tax_rate_id && !empty($this->_data['stitem_id'])) {
         $tax_rates[$product->tax_rate_id] = $product->tax_rate;
     } else {
         $taxrate = DataObjectFactory::Factory('TaxRate');
         $tax_rates = $taxrate->getAll();
     }
     $this->view->set('tax_rates', $tax_rates);
 }
Example #6
0
 public function _new()
 {
     parent::_new();
     // Get the Dataset dObject - if loaded, this is an edit
     $dataset = $this->_uses[$this->modeltype];
     if ($dataset->isLoaded()) {
         $this->view->set('dataset_model', new DataObject($dataset->name));
     }
 }
 public function _new()
 {
     parent::_new();
     $resource = DataObjectFactory::Factory('MFResource');
     $this->view->set('resource', $resource->getAll());
     $workschedule = $this->_uses[$this->modeltype];
     if ($workschedule->isLoaded()) {
         $eng_resource = DataObjectFactory::Factory('EngineeringResource');
         $this->view->set('assigned', $eng_resource->getAssigned($workschedule->id));
     }
 }
 public function _new()
 {
     $calendar = new Calendar();
     $this->view->set('calendar_id', $calendar->getWritableCalendars());
     parent::_new();
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('Actions', array('view_events' => array('link' => array('module' => 'calendar', 'controller' => 'calendarevents', 'action' => 'index'), 'tag' => 'view_events')));
     $sidebar->addList('calendar_views', array('view_calendar' => array('link' => array('module' => 'calendar'), 'tag' => 'View Calendar')));
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }
 public function _new()
 {
     parent::_new();
     if (isset($this->_data['transaction_date'])) {
         $trandate = fix_date($this->_data['transaction_date']);
         $period_text = $this->getPeriod($trandate);
     } else {
         $period = DataObjectFactory::Factory('GLPeriod');
         $period->getCurrentPeriod();
         $trandate = $period->enddate;
         $period_text = $period->getIdentifierValue();
     }
     $this->view->set('transaction_date', $trandate);
     $this->view->set('period', $period_text);
     $this->view->set('periods', $this->getPeriods(un_fix_date($trandate)));
 }
 public function _new()
 {
     // need to store the ajax flag in a different variable and the unset the original
     // this is to prevent any functions that are further called from returning the wrong datatype
     $ajax = isset($this->_data['ajax']);
     unset($this->_data['ajax']);
     parent::_new();
     $product = $this->_uses[$this->modeltype];
     $product_header = DataObjectFactory::Factory('POProductlineHeader');
     if (isset($this->_data['productline_header_id'])) {
         $product_header->load($this->_data['productline_header_id']);
     } elseif (isset($this->_data['stitem_id'])) {
         $product_header->loadBy('stitem_id', $this->_data['stitem_id']);
         if ($product_header->isLoaded()) {
             $this->_data['productline_header_id'] = $product_header->id;
         }
     }
     if (!$product->isLoaded()) {
         if (isset($this->_data['productline_header_id']) && $product_header->isLoaded()) {
             $product->productline_header_id = $this->_data['productline_header_id'];
         } else {
             $headers = $product_header->getAll();
             $this->view->set('headers', $headers);
             $product->productline_header_id = key($headers);
         }
     } else {
         $this->_data['productline_header_id'] = $product->productline_header_id;
     }
     $glaccount = DataObjectFactory::Factory('GLAccount');
     $gl_accounts = $glaccount->nonControlAccounts();
     $this->view->set('gl_accounts', $gl_accounts);
     if ($product->isLoaded()) {
         $default_glaccount_id = $product->glaccount_id;
         $default_supplier = $product->plmaster_id;
     } else {
         $default_supplier = '';
     }
     $data = $this->getHeaderData($product->productline_header_id, $default_supplier);
     if (!$product->isLoaded()) {
         $this->view->set('price', $data['price']['data']);
         $this->view->set('discount', $data['discount']['data']);
         $default_glaccount_id = $data['glaccount_id']['data'];
     }
     $this->view->set('gl_account', $default_glaccount_id);
     $this->view->set('gl_centres', $this->getCentres($default_glaccount_id));
 }
 public function _new()
 {
     $event = $this->_templateobject;
     if ($this->_data['action'] == 'edit_event') {
         $event->load($this->_data['id']);
     }
     $this->view->set('model', $event);
     if (isset($this->_data['calendar_id'])) {
         $this->view->set('crm_calendar_id', $this->_data['calendar_id']);
     }
     // set sidebar
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('Actions', array('crm_calendar' => array('link' => array('modules' => $this->_modules, 'controller' => 'crmcalendars', 'action' => 'index'), 'tag' => 'CRM Calendar'), 'manage_calendars' => array('link' => array('modules' => $this->_modules, 'controller' => 'crmcalendars', 'action' => 'view_calendars'), 'tag' => 'Manage Calendars')));
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     parent::_new();
 }
Example #12
0
 public function _new()
 {
     $ao =& AccessObject::Instance(EGS_USERNAME);
     if ($ao->hasPermission('crm')) {
         $this->view->set('crm_access', true);
     }
     $categories = DataObjectFactory::Factory('Contactcategory');
     $this->view->set('contact_categories', $categories->getCompanyCategories());
     parent::_new();
 }
Example #13
0
 public function _new()
 {
     parent::_new();
     $roles = DataObjectFactory::Factory('Role');
     $this->view->set('roles', $roles->getAll());
     $sc = DataObjectFactory::Factory('Systemcompany');
     $companies = new SystemcompanyCollection($sc);
     $this->view->set('companies', $companies->getCompanies());
     $sc->load(EGS_COMPANY_ID);
     $current_people = $sc->getCurrentPeople();
     $assigned_users = $this->_uses[$this->modeltype]->getAssignedPeople();
     $this->view->set('people', array_diff_key($current_people, $assigned_users));
     $debug = DataObjectFactory::Factory('DebugOption');
     $this->view->set('debug_options', $debug->getEnumOptions('options'));
 }
Example #14
0
 public function _new()
 {
     parent::_new();
     // Get the Person Object
     $person = $this->_uses[$this->modeltype];
     // get company list
     $companylist = $this->getOptions($this->_templateobject, 'company_id', 'getOptions', 'getOptions');
     // get the default/current selected company
     $company_id = '';
     $addresses = array('' => 'Enter new address');
     $_person_id = '';
     if ($person->isLoaded()) {
         $company_id = $person->company_id;
         $pic = DataObjectFactory::Factory('PeopleInCategories');
         $selected = $pic->getCategoryID($person->{$person->idField});
         $this->view->set('selected_categories', $selected);
         $_person_id = $person->{$person->idField};
         $company_id = $person->company_id;
     } elseif (isset($this->_data['company_id'])) {
         $company_id = $this->_data['company_id'];
     } elseif (isset($this->_data[$this->modeltype]['company_id'])) {
         $company_id = $this->_data[$this->modeltype]['company_id'];
     }
     $addresses = $addresses + $this->getAddresses($company_id, $_person_id);
     $this->view->set('addresses', $addresses);
     $categories = DataObjectFactory::Factory('Contactcategory');
     $this->view->set('contact_categories', $categories->getPersonCategories());
     $address = DataObjectFactory::Factory('address');
     $company = DataObjectFactory::Factory('Company');
     if (!empty($company_id)) {
         $company->load($company_id);
         $this->view->set('company', $company->name);
         $this->_data['company_id'] = $company_id;
         $this->view->set('reports_to', $this->getAllByCompany($company_id));
         $this->view->set('phone', $company->phone->contactmethod);
         $this->view->set('mobile', $company->mobile->contactmethod);
         $this->view->set('fax', $company->fax->contactmethod);
         $this->view->set('email', $company->email->contactmethod);
     } else {
         $this->view->set('company', '');
         $this->view->set('reports_to', $this->getAllByCompany(''));
         $this->view->set('phone', DataObjectFactory::Factory('contactmethod'));
         $this->view->set('mobile', DataObjectFactory::Factory('contactmethod'));
         $this->view->set('fax', DataObjectFactory::Factory('contactmethod'));
         $this->view->set('email', DataObjectFactory::Factory('contactmethod'));
         $this->view->set('address', DataObjectFactory::Factory('address'));
     }
     if ($person->isLoaded()) {
         $address->{$address->idField} = $person->main_address->address_id;
     }
     if ($person->phone->contactmethod->isLoaded()) {
         $this->view->set('phone', $person->phone->contactmethod);
     }
     if ($person->mobile->contactmethod->isLoaded()) {
         $this->view->set('mobile', $person->mobile->contactmethod);
     }
     if ($person->fax->contactmethod->isLoaded()) {
         $this->view->set('fax', $person->fax->contactmethod);
     }
     if ($person->email->contactmethod->isLoaded()) {
         $this->view->set('email', $person->email->contactmethod);
     }
     $this->view->set('address', $address);
 }
Example #15
0
 public function _new()
 {
     parent::_new();
     // Get the OrderObject - if loaded, this is an edit
     $sorder = $this->_uses[$this->modeltype];
     // Prevent changes to the order if the customer is on stop
     if ($sorder->isLoaded() and !$this->actionAllowedOnStop($sorder->customerdetails)) {
         $flash = Flash::Instance();
         $flash->addError($sorder->getFormatted('type') . ' cannot be changed');
         sendBack();
     }
     // get customer list
     if ($sorder->isLoaded() && $sorder->net_value != 0) {
         $customers = array($sorder->slmaster_id => $sorder->customer);
     } else {
         $customers = $this->getOptions($this->_templateobject, 'slmaster_id', 'getOptions', 'getOptions', array('use_collection' => true));
     }
     if (isset($this->_data['type'])) {
         $sorder->type = $this->_data['type'];
     }
     // get the default/current selected customer
     if (isset($this->_data['slmaster_id'])) {
         // this is set if there has been error and we are redisplaying the screen
         $default_customer = $this->_data['slmaster_id'];
         $customer = $this->getCustomer($default_customer);
     } elseif (isset($this->_data[$this->modeltype]['slmaster_id'])) {
         // this is set if there has been error and we are redisplaying the screen
         $default_customer = $this->_data[$this->modeltype]['slmaster_id'];
     } else {
         if (!$sorder->isLoaded()) {
             $default_customer = $this->getDefaultValue($this->modeltype, 'slmaster_id', '');
         } else {
             $default_customer = $sorder->slmaster_id;
         }
     }
     if (empty($default_customer)) {
         $default_customer = key($customers);
     }
     $customer = $this->getCustomer($default_customer);
     // Prevent the new order action for customers on stop but allow the form
     // to be shown when the slmaster_id is not set. Otherwise, if the default
     // customer is on stop, then the form will never display.
     if (!$this->actionAllowedOnStop($customer) and isset($this->_data['slmaster_id'])) {
         $flash = Flash::Instance();
         // Assume it will be a new order if the order object has no type
         $message_type = "order";
         if (strtolower($sorder->getFormatted('type')) != '') {
             $message_type = strtolower($sorder->getFormatted('type'));
         }
         $flash->addError("Cannot add new {$message_type}, customer on stop");
         sendBack();
     }
     $this->view->set('company_id', $customer->company_id);
     if (!$sorder->isLoaded()) {
         $sorder->slmaster_id = $default_customer;
         // get delivery term for default customer
         $this->view->set('customer_term', $this->getDeliveryTerm($default_customer));
     }
     $this->view->set('selected_customer', $default_customer);
     // get people based on customer
     $people = $this->getPeople($default_customer);
     if (isset($this->_data[$this->modeltype]['person_id'])) {
         // this is set if there has been error and we are redisplaying the screen
         $default_person = $this->_data[$this->modeltype]['person_id'];
     } else {
         if (!$sorder->isLoaded()) {
             $default_person = $this->getDefaultValue($this->modeltype, 'person_id', '');
         } else {
             $default_person = $sorder->person_id;
         }
     }
     if (empty($default_person)) {
         $default_person = key($people);
     }
     $this->view->set('selected_people', $default_person);
     if ($sorder->isLoaded()) {
         $this->view->set('default_despatch_action', $sorder->despatch_action);
     } else {
         $this->view->set('default_despatch_action', $this->getDespatchAction($default_customer));
     }
     // get delivery address list for default person or first in person
     $delivery_address = $this->getPersonAddresses($default_person, 'shipping', $default_customer);
     $this->view->set('deliveryAddresses', $delivery_address);
     // get invoice address list for default person or first in person
     $invoice_address = $this->getPersonAddresses($default_person, 'billing', $default_customer);
     // Set default invoice address to delivery address if it exists
     // otherwise use customer default billing address
     if (isset($invoice_address[key($delivery_address)])) {
         $this->view->set('invoice_address', key($delivery_address));
         $this->view->set('invoiceAddresses', array(key($delivery_address) => current($delivery_address)));
     } else {
         $this->view->set('invoice_address', $customer->billing_address_id);
         $this->view->set('invoiceAddresses', $invoice_address);
     }
     $this->view->set('default_inv_address', $customer->billing_address_id);
     // get payment terms list for default customer or first in customer
     $this->payment_terms($default_customer);
     // get Sales Order Notes for default customer or first in customer
     $this->getNotes($person, $default_customer);
     // get despatch actions
     $despatch_actions = WHAction::getDespatchActions();
     $this->view->set('despatch_actions', $despatch_actions);
     if (!is_null($sorder->type)) {
         $this->view->set('page_title', $this->_data['action'] . ' ' . $sorder->getFormatted('type'));
     }
     // This bit allows for projects and tasks
     $projects = $this->getProjects($default_customer);
     $this->view->set('projects', $projects);
     if (!$sorder->isLoaded() && !empty($this->_data['project_id'])) {
         $sorder->project_id = $this->_data['project_id'];
     }
     $this->view->set('tasks', $this->getTaskList($sorder->project_id));
 }
Example #16
0
 public function converttoaccount()
 {
     $company = $this->_uses['Lead'];
     if (isset($this->_data['Lead']) && isset($this->_data['Lead'][$company->idField])) {
         $id = $this->_data['Lead'][$company->idField];
         $data = $this->_data['Lead'];
     } elseif (isset($this->_data[$company->idField])) {
         $id = $this->_data[$company->idField];
     } else {
         $flash = Flash::Instance();
         $flash->addError('Select a Lead to convert');
         sendTo('leads', 'index', array('contacts'));
     }
     $company->load($id);
     if (!$company->isLoaded()) {
         $flash = Flash::instance();
         $flash->addError('You do not have permission to edit this lead.');
         sendTo($this->name, 'index', $this->_modules);
         return;
     }
     $pl = new PreferencePageList('recently_viewed_leads' . EGS_COMPANY_ID);
     $pl->removePage(new Page(array('module' => 'contacts', 'controller' => 'leads', 'action' => 'view', 'id' => $company->id), 'company', $company->name));
     $pl->save();
     $pl = new PreferencePageList('recently_viewed_companies' . EGS_COMPANY_ID);
     $pl->addPage(new Page(array('module' => 'contacts', 'controller' => 'companys', 'action' => 'view', 'id' => $company->id), 'company', $company->name));
     $pl->save();
     $system_prefs = SystemPreferences::instance();
     $autoGenerate = $system_prefs->getPreferenceValue('auto-account-numbering', 'contacts');
     if (!(empty($autoGenerate) || $autoGenerate === 'off')) {
         $company->update($id, array('is_lead', 'accountnumber'), array('false', $company->createAccountNumber()));
         sendTo('companys', 'view', array('contacts'), array('id' => $company->id));
     } else {
         if (isset($data['accountnumber'])) {
             $company->update($id, array('is_lead', 'accountnumber'), array('false', $data['accountnumber']));
             sendTo('companys', 'view', array('contacts'), array('id' => $company->id));
         } else {
             parent::_new();
         }
     }
 }
 public function _new()
 {
     // need to store the ajax flag in a different variable and the unset the original
     // this is to prevent any functions that are further called from returning the wrong datatype
     $ajax = isset($this->_data['ajax']);
     unset($this->_data['ajax']);
     parent::_new();
     $product = $this->_uses[$this->modeltype];
     $product_header = DataObjectFactory::Factory('SOProductlineHeader');
     if (isset($this->_data['productline_header_id'])) {
         $product_header->load($this->_data['productline_header_id']);
     } elseif (isset($this->_data['stitem_id'])) {
         $product_header->loadBy('stitem_id', $this->_data['stitem_id']);
         if ($product_header->isLoaded()) {
             //				echo 'data<pre>'.print_r($_GET, true).'</pre><br>';
             $_POST['productline_header_id'] = $this->_data['productline_header_id'] = $product_header->id;
         }
         //			else
         //			{
         //				echo 'Could not load header for item '.$this->_data['stitem_id'].'<br>';
         //			}
     }
     if (!$product->isLoaded()) {
         if (isset($this->_data['productline_header_id']) && $product_header->isLoaded()) {
             $product->productline_header_id = $this->_data['productline_header_id'];
         } else {
             $headers = $product_header->getAll();
             $this->view->set('headers', $headers);
             $product->productline_header_id = key($headers);
         }
     } else {
         $this->_data['productline_header_id'] = $product->productline_header_id;
     }
     $glaccount = DataObjectFactory::Factory('GLAccount');
     $gl_accounts = $glaccount->nonControlAccounts();
     $this->view->set('gl_accounts', $gl_accounts);
     if ($product->isLoaded()) {
         $default_glaccount_id = $product->glaccount_id;
         $default_customer = $product->slmaster_id;
     } else {
         $default_customer = '';
     }
     $data = $this->getHeaderData($product->productline_header_id, $default_customer);
     if (!$product->isLoaded()) {
         $this->view->set('price', $data['price']['data']);
         $this->view->set('discount', $data['discount']['data']);
         $default_glaccount_id = $data['glaccount_id']['data'];
     }
     $this->view->set('gl_account', $default_glaccount_id);
     $this->view->set('gl_centres', $this->getCentres($default_glaccount_id));
     $this->view->set('gross_price', $this->_templateobject->getGrossPrice());
 }
Example #18
0
 function edit_gcal()
 {
     $flash = Flash::Instance();
     $calendar = new Calendar();
     $calendar->load($this->_data['id']);
     $this->view->set('calendar', $calendar);
     if (!$calendar->isOwner($this->_data['id'])) {
         $flash->addError("You cannot edit a calendar that doesn't belong to you");
         sendTo('calendars', 'index', 'calendar');
     }
     $colours = $calendar->getEnumOptions('colour');
     $this->view->set('colours', $colours);
     $user = new User();
     $users = $user->getAll();
     foreach ($users as $key => $value) {
         if ($value != EGS_USERNAME) {
             $usernames[$key] = $value;
         }
     }
     $this->view->set('users', $usernames);
     $shared_users = array();
     $shared_user = new CalendarShareCollection(new CalendarShare());
     $sh = new SearchHandler($shared_user, false);
     $sh->addConstraint(new Constraint('calendar_id', '=', $this->_data['id']));
     $sh->addConstraint(new Constraint('username', '!=', EGS_USERNAME));
     $sh->setFields(array('id', 'calendar_id', 'username'));
     $shared_user->load($sh);
     if (count($shared_user->getArray()) > 0) {
         foreach ($shared_user->getArray() as $key => $value) {
             $shared_users[$key] = $value['username'];
         }
     }
     $this->view->set('shared_users', $shared_users);
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('calendar_views', array('view_calendar' => array('link' => array('module' => 'calendar'), 'tag' => 'View Calendar')));
     $sidebar->addList('calendars', array('manage_calendars' => array('link' => array('module' => 'calendar', 'controller' => 'calendars', 'action' => 'index'), 'tag' => 'Manage Calendars')));
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     parent::_new();
 }
Example #19
0
 public function _new()
 {
     $flash = Flash::Instance();
     parent::_new();
     // Get the Order Line Object - if loaded, this is an edit
     $sorderline = $this->_uses[$this->modeltype];
     if (!$sorderline->isLoaded()) {
         if (empty($this->_data['order_id'])) {
             $flash->addError('No Sales Order supplied');
             sendBack();
         }
         $sorderline->order_id = $this->_data['order_id'];
     }
     $sorder = DataObjectFactory::Factory('SOrder');
     $sorder->load($sorderline->order_id);
     // Prevent any changes to the order line if the customer is on stop
     if ($sorder->isLoaded() and !$this->actionAllowedOnStop($sorder->customerdetails)) {
         $flash->addError($sorder->getFormatted('type') . ' cannot be changed');
         sendBack();
     }
     $_slmaster_id = $sorder->slmaster_id;
     if (isset($this->_data[$this->modeltype])) {
         // We've had an error so refresh the page
         $_slmaster_id = $this->_data['SOrder']['slmaster_id'];
         $sorderline->line_number = $this->_data['SOrderLine']['line_number'];
         $_product_search = $this->_data['SOrderLine']['product_search'];
         if (!empty($this->_data['SOrderLine']['productline_id'])) {
             $_productline_id = $this->_data['SOrderLine']['productline_id'];
         } else {
             $_productline_id = '';
         }
         $_glaccount_id = $this->_data['SOrderLine']['glaccount_id'];
     } elseif ($sorderline->isLoaded()) {
         // This needs changing - get the product line if productline_id not null
         // then, check if this is in productline_options, if not, add it
         $_product_search = $sorderline->description;
         $_productline_id = $sorderline->productline_id;
         $_glaccount_id = $sorderline->glaccount_id;
     } else {
         $sorderline->due_despatch_date = $sorder->despatch_date;
         $sorderline->due_delivery_date = $sorder->due_date;
     }
     $display_fields = $sorderline->getDisplayFields();
     if (isset($display_fields['product_search'])) {
         if (empty($_product_search)) {
             $_product_search = 'None';
             $productline_options = array('' => 'None');
         } else {
             $productline_options = $this->getProductLines($_slmaster_id, $_product_search);
         }
     } else {
         $productline_options = $this->getProductLines($_slmaster_id);
     }
     if (empty($_productline_id)) {
         $_productline_id = key($productline_options);
     }
     $this->view->set('display_fields', $display_fields);
     $this->view->set('product_search', $_product_search);
     $this->view->set('productline_options', $productline_options);
     $data = $this->getProductLineData($_productline_id, $_slmaster_id);
     $this->view->set('stuom_options', $data['stuom_id']);
     $this->view->set('glaccount_options', $data['glaccount_id']);
     if (empty($_glaccount_id)) {
         $_glaccount_id = key($data['glaccount_id']);
     }
     $this->view->set('glcentre_options', $this->getCentre($_glaccount_id, $_productline_id));
     $this->view->set('taxrate_options', $data['tax_rate_id']);
     $this->view->set('sorder', $sorder);
 }
Example #20
0
 public function _new()
 {
     parent::_new();
     $sinvoice = $this->_uses[$this->modeltype];
     // get customer list
     if ($sinvoice->isLoaded() && $sinvoice->net_value != 0) {
         $customers = array($sinvoice->slmaster_id => $sinvoice->customer);
     } else {
         $customers = $this->getOptions($this->_templateobject, 'slmaster_id', 'getOptions', 'getOptions', array('use_collection' => true));
         if (!$sinvoice->isLoaded()) {
             if (isset($this->_data['transaction_type'])) {
                 $sinvoice->transaction_type = $this->_data['transaction_type'];
             } else {
                 $sinvoice->transaction_type = 'I';
             }
         }
     }
     if (!is_null($sinvoice->transaction_type)) {
         $transaction_type_desc = $sinvoice->getFormatted('transaction_type');
         $this->view->set('transaction_type_desc', $transaction_type_desc);
     }
     $this->_templateobject->setTitle('Sales ' . $transaction_type_desc);
     // get the default/current selected customer
     if (isset($this->_data['slmaster_id'])) {
         // this is set if there has been error and we are redisplaying the screen
         $default_customer = $this->_data['slmaster_id'];
     } elseif (isset($this->_data[$this->modeltype]['slmaster_id'])) {
         // this is set if there has been error and we are redisplaying the screen
         $default_customer = $this->_data[$this->modeltype]['slmaster_id'];
     } else {
         if (!$sinvoice->isLoaded()) {
             $default_customer = $this->getDefaultValue($this->modeltype, 'slmaster_id', '');
         } else {
             $default_customer = $sinvoice->slmaster_id;
         }
     }
     if (empty($default_customer)) {
         $default_customer = key($customers);
     }
     if (!$sinvoice->isLoaded()) {
         $sinvoice->slmaster_id = $default_customer;
     }
     $this->view->set('selected_customer', $default_customer);
     $customer = $this->getCustomer($default_customer);
     $this->view->set('company_id', $customer->company_id);
     // get people based on default customer or first in customer
     $people = $this->getPeople($default_customer);
     $this->view->set('people', $people);
     if ($sinvoice->isLoaded()) {
         $default_person = $sinvoice->person_id;
     } elseif (isset($this->_data['person_id'])) {
         // this is set if there has been error nad we are redisplaying the screen
         $default_person = $this->_data['person_id'];
     } else {
         $default_person = $this->getDefaultValue($this->modeltype, 'person_id', '');
         if (empty($default_person)) {
             $default_person = key($people);
         }
     }
     $this->view->set('selected_people', $default_person);
     // get delivery address list for customer/person
     $delivery_address = $this->getPersonAddresses($default_person, 'shipping', $default_customer);
     $this->view->set('deliveryAddresses', $delivery_address);
     // get invoice address list for customer/person
     $invoice_address = $this->getPersonAddresses($default_person, 'billing', $default_customer);
     // Set default invoice address to delivery address if it exists
     // otherwise use customer default billing address
     if (isset($invoice_address[key($delivery_address)])) {
         $this->view->set('invoice_address', key($delivery_address));
         $this->view->set('invoiceAddresses', array(key($delivery_address) => current($delivery_address)));
     } else {
         $this->view->set('invoice_address', $customer->billing_address_id);
         $this->view->set('invoiceAddresses', $invoice_address);
     }
     $this->view->set('default_inv_address', $customer->billing_address_id);
     // get Sales Invoice Notes for default customer or first in customer
     $this->getNotes($person, $default_customer);
     // Get Projects and tasks
     $projects = $this->getProjects($default_customer);
     $this->view->set('projects', $projects);
     if (!$sinvoice->isLoaded() && !empty($this->_data['project_id'])) {
         $sinvoice->project_id = $this->_data['project_id'];
     }
     $this->view->set('tasks', $this->getTaskList($sinvoice->project_id));
 }
 public function _new()
 {
     $glheader = DataObjectFactory::Factory($this->_header_model);
     $unposted = $glheader->unpostedTransactionFactory();
     $transaction_model = get_class($unposted);
     $this->_templateobject = DataObjectFactory::Factory($transaction_model);
     $this->uses($this->_templateobject);
     $this->loadData();
     $default_glaccount_id = '';
     $default_glcentre_id = '';
     if ($this->_templateobject->isLoaded()) {
         $glheader->loadBy('docref', $this->_templateobject->docref);
         $default_glaccount_id = $this->_templateobject->glaccount_id;
         $default_glcentre_id = $this->_templateobject->glcentre_id;
     } elseif ($this->checkParams('header_id')) {
         $glheader->load($this->_data['header_id']);
     }
     if (empty($default_glaccount_id)) {
         if (!empty($this->_data[$transaction_model]['glaccount_id'])) {
             $default_glaccount_id = $this->_data[$transaction_model]['glaccount_id'];
         } elseif (!empty($this->_data['glaccount_id'])) {
             $default_glaccount_id = $this->_data['glaccount_id'];
         }
     }
     if (empty($default_glcentre_id)) {
         if (!empty($this->_data[$transaction_model]['glcentre_id'])) {
             $default_glcentre_id = $this->_data[$transaction_model]['glcentre_id'];
         } elseif (!empty($this->_data['glcentre_id'])) {
             $default_glcentre_id = $this->_data['glcentre_id'];
         }
     }
     $this->_templateName = $this->getTemplateName('new');
     if (!$glheader->isLoaded()) {
         $this->dataError('Cannot find GL Header');
         sendBack();
     }
     $this->view->set('gltransaction_header', $glheader);
     parent::_new();
     $this->view->set('gltransaction', $this->_templateobject);
     $glaccount = DataObjectFactory::Factory('GLAccount');
     $accounts = $glaccount->nonControlAccounts();
     $this->view->set('accounts', $accounts);
     $this->view->set('default_account', $default_glaccount_id);
     if (empty($default_glaccount_id)) {
         $default_glaccount_id = key($accounts);
     }
     $centres = $this->getCentres($default_glaccount_id);
     $this->view->set('centres', $centres);
     $this->view->set('default_centre', $default_glcentre_id);
 }
Example #22
0
 public function _new()
 {
     parent::_new();
     $pinvoice = $this->_uses[$this->modeltype];
     // get supplier list
     if ($pinvoice->isLoaded() && $pinvoice->net_value != 0) {
         $suppliers = array($pinvoice->plmaster_id => $pinvoice->supplier);
         if ($this->settlement_discount == 0 && $pinvoice->transaction_type == 'I') {
             $pinvoice->settlement_discount = $pinvoice->getSettlementDiscount();
         }
     } else {
         $suppliers = $this->getOptions($this->_templateobject, 'plmaster_id', 'getOptions', 'getOptions', array('use_collection' => true));
         if (!$pinvoice->isLoaded()) {
             if (isset($this->_data['transaction_type'])) {
                 $pinvoice->transaction_type = $this->_data['transaction_type'];
             } else {
                 $pinvoice->transaction_type = 'I';
             }
         }
     }
     if (!is_null($pinvoice->transaction_type)) {
         $transaction_type_desc = $pinvoice->getFormatted('transaction_type');
         $this->view->set('transaction_type_desc', $transaction_type_desc);
     }
     $this->_templateobject->setTitle('Purchase ' . $transaction_type_desc);
     // get the default/current selected supplier
     if (isset($this->_data['plmaster_id'])) {
         // this is set if there has been error and we are redisplaying the screen
         $defaultsupplier = $this->_data['plmaster_id'];
     } else {
         if (!$pinvoice->isLoaded()) {
             $defaultsupplier = $this->getDefaultValue($this->modeltype, 'plmaster_id', '');
         } else {
             $defaultsupplier = $pinvoice->plmaster_id;
         }
     }
     if (empty($defaultsupplier)) {
         $defaultsupplier = key($suppliers);
     }
     if (!$pinvoice->isLoaded()) {
         $pinvoice->plmaster_id = $defaultsupplier;
     }
     $this->view->set('selected_supplier', $defaultsupplier);
     // get Purchase Invoice Notes for default customer or first in customer
     $this->getNotes($defaultsupplier);
     // This bit allows for projects and tasks to be linked
     if (!$pinvoice->isLoaded() && !empty($this->_data['project_id'])) {
         $pinvoice->project_id = $this->_data['project_id'];
     }
     $this->view->set('tasks', $this->getTaskList($pinvoice->project_id));
 }