public function makePayments()
 {
     $flash = Flash::Instance();
     $errors = array();
     // set context from calling module
     $defaults = array();
     if (isset($this->_data['cb_account_id'])) {
         $defaults['cb_account_id'] = $this->_data['cb_account_id'];
     }
     if (isset($this->_data['company_id'])) {
         $defaults['company_id'] = $this->_data['company_id'];
     }
     if (isset($this->_data['source'])) {
         $defaults['source'] = $this->_data['source'];
     }
     if (isset($this->_data['status'])) {
         $defaults['status'] = $this->_data['status'];
     }
     if (isset($this->_data['frequency'])) {
         $defaults['frequency'] = $this->_data['frequency'];
     }
     if (isset($this->_data['from_date'])) {
         $defaults['next_due_date']['from'] = un_fix_date($this->_data['from_date']);
         $defaults['next_due_date']['to'] = un_fix_date($this->_data['from_date']);
     }
     if (isset($this->_data['to_date'])) {
         $defaults['next_due_date']['to'] = un_fix_date($this->_data['to_date']);
         if (!isset($this->_data['from_date'])) {
             $defaults['next_due_date']['from'] = un_fix_date($this->_data['to_date']);
         }
     }
     $this->setSearch('PeriodicPaymentsSearch', 'makePayments', $defaults);
     parent::index(new PeriodicPaymentCollection($this->_templateobject));
     $this->view->set('clickaction', 'view');
 }
Exemple #2
0
 function getRemittance(&$_data = array(), &$model = array(), &$extra = array(), &$errors = array())
 {
     // load the model
     $supplier = DataObjectFactory::Factory('PLSupplier');
     $supplier->load($this->plmaster_id);
     $_data['email_subject'] = $supplier->name . ' Remittance ' . $this->transaction_date;
     $_data['filename'] = 'Remittance-' . $this->id;
     // get the payment method
     $plpayment = DataObjectFactory::Factory('PLPayment');
     $plpayment->load($this->cross_ref);
     // get the remittance list
     $pltransactions = new PLAllocationCollection(DataObjectFactory::Factory('PLAllocation'));
     $pltransactions->remittanceList($this->id);
     $model = array($supplier, $pltransactions);
     // set date
     // a bit messy nesting in so many functions
     $extra['date'] = un_fix_date(fix_date(date(DATE_FORMAT)));
     // set company name
     $company = DataObjectFactory::Factory('Company');
     $company->load(COMPANY_ID);
     $extra['company_name'] = $company->name;
     // set company address
     $company_address = array('name' => $company->name);
     $output = array();
     $parts = array("street1", "street2", "street3", "town", "county", "postcode", "country");
     $address = $company->getAddress();
     foreach ($parts as $part) {
         if (!is_null($address->{$part})) {
             $output[$part] = $address->{$part};
         }
     }
     $company_address += $output;
     $extra['company_address'] = $company_address;
     // set the company details
     $email = $company->getContactDetail('E', 'REMITTANCE');
     if (empty($email)) {
         $email = $company->getContactDetail('E');
     }
     $_data['replyto'] = $email;
     $extra['company_details'] = array('tel' => 'Tel: ' . $company->getContactDetail('T'), 'fax' => 'Fax: ' . $company->getContactDetail('F'), 'email' => 'Email: ' . $email, 'vat_number' => 'VAT Number: ' . $company->vatnumber, 'company_number' => 'Company Number: ' . $company->companynumber);
     // set supplier address
     $supplier_address = array('name' => $supplier->name);
     $output = array();
     $parts = array("street1", "street2", "street3", "town", "county", "postcode", "country");
     $address = $supplier->getBillingAddress();
     foreach ($parts as $part) {
         if (!is_null($address->{$part})) {
             $output[$part] = $address->{$part};
         }
     }
     $supplier_address += $output;
     $extra['supplier_address'] = $supplier_address;
     // set document details
     $document_reference = array();
     $document_reference[]['line'] = array('label' => 'Payment Date', 'value' => un_fix_date($this->transaction_date));
     $document_reference[]['line'] = array('label' => 'Payment Value', 'value' => bcmul($this->gross_value, -1, 2));
     $document_reference[]['line'] = array('label' => 'Currency', 'value' => $plpayment->currency);
     $document_reference[]['line'] = array('label' => 'Payment Method', 'value' => $plpayment->payment_type);
     $extra['document_reference'] = $document_reference;
 }
Exemple #3
0
 public function validate($_value, &$errors = array())
 {
     switch ($this->data_type) {
         case 'date':
             $date = fix_date($_value, $this->external_format, $errors);
             if ($date === false) {
                 return $_value;
             }
             return un_fix_date($date);
             break;
     }
 }
Exemple #4
0
 function makePaymentTransaction()
 {
     $data = array();
     $this->getLedgerData($data);
     $data['glaccount_id'] = $this->glaccount_id;
     $data['glcentre_id'] = $this->glcentre_id;
     $data['cb_account_id'] = $this->cb_account_id;
     $data['currency_id'] = $this->currency_id;
     $data['tax_rate_id'] = $this->tax_rate_id;
     $data['company_id'] = $this->company_id;
     $data['person_id'] = $this->person_id;
     $data['payment_type_id'] = $this->payment_type_id;
     $data['transaction_date'] = un_fix_date($this->next_due_date);
     $data['source'] = substr($this->source, 0, 1);
     $data['transaction_type'] = $data['type'] = substr($this->source, 1, 1);
     return $data;
 }
 public function index()
 {
     $errors = array();
     $s_data = array();
     // Set context from calling module
     if (isset($this->_data['status'])) {
         $s_data['status'] = $this->_data['status'];
     }
     if (isset($this->_data['stitem_id'])) {
         $s_data['stitem_id'] = $this->_data['stitem_id'];
     }
     if (isset($this->_data['whlocation_id'])) {
         $s_data['whlocation_id'] = $this->_data['whlocation_id'];
     }
     if (empty($this->_data['from'])) {
         $s_data['created']['from'] = date(DATE_FORMAT, strtotime('-7 days'));
     } else {
         $s_data['created']['from'] = un_fix_date($this->_data['from']);
     }
     if (empty($this->_data['to'])) {
         $s_data['created']['to'] = date(DATE_FORMAT);
     } else {
         $s_data['created']['to'] = un_fix_date($this->_data['to']);
     }
     $this->setSearch('sttransactionsSearch', 'useDefault', $s_data);
     $sttransactions = new STTransactionCollection($this->_templateobject);
     if (!isset($this->_data['orderby']) && !isset($this->_data['page'])) {
         $sh = $this->setSearchHandler($sttransactions);
         $cc = new ConstraintChain();
         $cc->add(new Constraint('error_qty', '<', 0));
         $cc->add(new Constraint('qty', '<', 0), 'OR');
         $sh->addConstraintChain($cc);
         $sh->setOrderby('created', 'DESC');
         parent::index($sttransactions, $sh);
     } else {
         parent::index($sttransactions);
     }
     $this->view->set('clickaction', 'view');
 }
Exemple #6
0
 public function viewEuSalesList()
 {
     $collection = new VatCollection($this->_templateobject);
     $collection->setParams();
     if (isset($this->_data['start_date'])) {
         $s_data['invoice_date']['from'] = un_fix_date($this->_data['start_date']);
     }
     if (isset($this->_data['end_date'])) {
         $s_data['invoice_date']['to'] = un_fix_date($this->_data['end_date']);
     }
     $this->setSearch('VatSearch', 'Transactions', $s_data, 'invoice_date');
     $sh = $this->setSearchHandler($collection);
     $collection->eu_saleslist($sh);
     $measure_fields = array('vat_number' => '', 'report' => '');
     $aggregate_fields = array('base_tax_value' => array('normal_enable_formatting' => 'true', 'normal_decimal_places' => 2, 'normal_justify' => 'right', 'normal_method' => 'sum', 'normal_total' => 'report'), 'base_net_value' => array('normal_enable_formatting' => 'true', 'normal_decimal_places' => 2, 'normal_justify' => 'right', 'normal_method' => 'sum', 'normal_total' => 'report'));
     $this->setBreakLevels($measure_fields, $aggregate_fields);
     $this->view->set('clickaction', 'none');
     return $this->viewEUTransactions($collection, $sh);
 }
 public function printStatement($status = 'generate')
 {
     // Set the time limit on entry - may be one of a batch of statements
     set_time_limit(30);
     $customer = DataObjectFactory::Factory('SLCustomer');
     $customer->load($this->_data['id']);
     $bank_account = $customer->bank_account_detail;
     /*
      * if (SYSTEM_COMPANY<>'') {
      * $data['subject']='Statement from '.SYSTEM_COMPANY;
      * }
      */
     // set options
     $options = array('type' => array('pdf' => '', 'xml' => ''), 'output' => array('print' => '', 'save' => '', 'email' => '', 'view' => ''), 'report' => 'Statement', 'filename' => 'Statements_' . fix_date(date(DATE_FORMAT)));
     if (strtolower($this->_data['printaction']) == 'printstatement' && !is_null($customer->email_statement())) {
         $options['default_print_action'] = 'email';
         $options['email'] = $customer->email_statement();
         $options['email_subject'] = 'Statement';
     }
     // if we're dealing with the dialog, just return the options...
     if (strtolower($status) == 'dialog') {
         return $options;
     }
     // ...otherwise continue with the function
     $sh = new SearchHandler(new SLTransactionCollection(), false);
     $sh->addConstraint(new Constraint('status', '<>', 'P'));
     $sh->setOrderby(array('due_date'), array('ASC'));
     $customer->addSearchHandler('transactions', $sh);
     $extra = array();
     // get the company address
     $company_address = array('name' => $this->getCompanyName());
     $company_address += $this->formatAddress($this->getCompanyAddress());
     $extra['company_address'] = $company_address;
     // get the company details
     $extra['company_details'] = $this->getCompanyDetails();
     // get the invoice address
     $payment_address = array();
     $payment_address['name'] = $customer->name;
     $payment_address += $this->formatAddress($customer->getBillingAddress());
     $extra['payment_address'] = $payment_address;
     // get current date
     $extra['current_date'] = un_fix_date(fix_date(date(DATE_FORMAT)));
     // get aged debtor summary
     foreach ($customer->getAgedDebtorSummary(3) as $key => $value) {
         $extra['aged_debtor_summary'][]['line'] = $value;
     }
     // get bank details
     if (!is_null($bank_account->bank_account_number)) {
         $extra['bank_account']['bank_name'] = $bank_account->bank_name;
         $extra['bank_account']['bank_sort_code'] = $bank_account->bank_sort_code;
         $extra['bank_account']['bank_account_number'] = $bank_account->bank_account_number;
         $extra['bank_account']['bank_address'] = $bank_account->bank_address;
         $extra['bank_account']['bank_iban_number'] = $bank_account->bank_iban_number;
         $extra['bank_account']['bank_bic_code'] = $bank_account->bank_bic_code;
     }
     // generate the XML, include the extras array too
     $options['xmlSource'] = $this->generateXML(array('model' => $customer, 'extra' => $extra, 'relationship_whitelist' => array('transactions')));
     // construct the document, capture the response
     $json_response = $this->constructOutput($this->_data['print'], $options);
     // decode response, if it was successful update the print count
     $response = json_decode($json_response, true);
     if ($response['status'] === true) {
         if (!$customer->update($customer->id, 'last_statement_date', fix_date(date(DATE_FORMAT)))) {
             // if we cannot update the date, update json_responce with an error
             $json_response = $this->returnResponse(false, array('message' => 'Statement output correctly, but failed to update statement date for customer ' . $customer->name));
         }
     }
     // now we've done our checks, output the original JSON for jQuery to use
     // echo the response if we're using ajax, return the response otherwise
     if (isset($this->_data['ajax'])) {
         echo $json_response;
     } else {
         return $json_response;
     }
     exit;
 }
 function getHeaderData($_header_id = '', $_slmaster_id = '')
 {
     // store the ajax status in a different var, then unset the current one
     // we do this because we don't want the functions we all to get confused
     $ajax = isset($this->_data['ajax']);
     unset($this->_data['ajax']);
     if ($ajax) {
         if (!empty($this->_data['productline_header_id'])) {
             $_header_id = $this->_data['productline_header_id'];
         }
         if (!empty($this->_data['slmaster_id'])) {
             $_slmaster_id = $this->_data['slmaster_id'];
         }
     }
     if (!empty($_header_id)) {
         $header = $this->loadHeader($_header_id);
         $this->view->set('SOProductlineHeader', $header);
         $output['description'] = array('data' => $header->description, 'is_array' => false);
         $output['discount'] = array('data' => $this->getPriceDiscount($header->prod_group_id, $header->stitem_id, $_slmaster_id), 'is_array' => false);
         $output['price'] = array('data' => $this->_templateobject->getPrice($header->prod_group_id, $header->stitem_id, $_slmaster_id), 'is_array' => false);
         $output['glaccount_id'] = array('data' => $header->glaccount_id, 'is_array' => false);
         $output['start_date'] = array('data' => un_fix_date($header->start_date), 'is_array' => false);
         $output['end_date'] = array('data' => un_fix_date($header->end_date), 'is_array' => false);
     }
     if ($ajax) {
         $html = $this->view->fetch($this->getTemplateName('header_data'));
         $output['header_data'] = array('data' => $html, 'is_array' => false);
         $this->view->set('data', $output);
         $this->setTemplateName('ajax_multiple');
     } else {
         return $output;
     }
 }
Exemple #9
0
 public function getStartEndDate($_project_id = '', $_task_id = '')
 {
     if (!empty($this->_data['project_id'])) {
         $_project_id = $this->_data['project_id'];
     }
     if (!empty($this->_data['task_id'])) {
         $_task_id = $this->_data['task_id'];
     }
     $obj = '';
     if (!empty($_task_id)) {
         $obj = new Task();
         $obj->load($_task_id);
     } elseif (!empty($_project_id)) {
         $obj = new Project();
         $obj->load($_project_id);
     }
     if ($obj instanceof DataObject && $obj->isLoaded()) {
         $start_date = un_fix_date($obj->start_date, true);
         $end_date = un_fix_date($obj->end_date, true);
     } else {
         $start_date = $end_date = date(DATE_FORMAT) . ' 00:00';
     }
     $dates = array('start_date' => $start_date, 'end_date' => $end_date);
     $start_date_hours = array_shift(explode(':', array_pop(explode(' ', $start_date))));
     $start_date_minutes = array_pop(explode(':', array_pop(explode(' ', $start_date))));
     $start_date = array_shift(explode(' ', $start_date));
     $end_date_hours = array_shift(explode(':', array_pop(explode(' ', $end_date))));
     $end_date_minutes = array_pop(explode(':', array_pop(explode(' ', $end_date))));
     $end_date = array_shift(explode(' ', $end_date));
     $output['start_date'] = array('data' => $start_date, 'is_array' => is_array($start_date));
     $output['start_date_hours'] = array('data' => $start_date_hours, 'is_array' => is_array($start_date_hours));
     $output['start_date_minutes'] = array('data' => $start_date_minutes, 'is_array' => is_array($start_date_minutes));
     $output['end_date'] = array('data' => $end_date, 'is_array' => is_array($end_date));
     $output['end_date_hours'] = array('data' => $end_date_hours, 'is_array' => is_array($end_date_hours));
     $output['end_date_minutes'] = array('data' => $end_date_minutes, 'is_array' => is_array($end_date_minutes));
     if (isset($this->_data['ajax'])) {
         $this->view->set('data', $output);
         $this->setTemplateName('ajax_multiple');
     } else {
         return $dates;
     }
 }
 public function view_hours_summary()
 {
     $errors = array();
     $s_data = array();
     if (!empty($this->_data['person_id'])) {
         $s_data['person_id'] = $this->_data['person_id'];
     }
     if (isset($this->_data['start_date'])) {
         $s_data['start_time']['from'] = empty($this->_data['start_date']) ? '' : un_fix_date($this->_data['start_date']);
     } else {
         $s_data['start_time']['from'] = date(DATE_FORMAT, strtotime("previous Monday"));
     }
     if (isset($this->_data['end_date'])) {
         $s_data['start_time']['to'] = empty($this->_data['end_date']) ? '' : un_fix_date($this->_data['end_date']);
     } else {
         $s_data['start_time']['to'] = date(DATE_FORMAT, strtotime("next Monday") - 1);
     }
     // Set context from calling module
     $this->setSearch('hoursSearch', 'person', $s_data);
     $date_range = $this->search->getValue('start_time');
     if (!empty($date_range['from'])) {
         $this->view->set('start_date', fix_date($date_range['from']));
     }
     if (!empty($date_range['to'])) {
         $this->view->set('end_date', fix_date($date_range['to']));
     }
     $hours = new HourCollection();
     $sh = $this->setSearchHandler($hours);
     $fields = array('type_id', 'person', 'person_id', 'type');
     if (!isset($this->_data['page']) && !isset($this->_data['orderby'])) {
         $sh->setOrderBy($fields);
     }
     $sh->setGroupBy($fields);
     $this->_templateobject->identifierField = 'person_id';
     $this->_templateobject->authorisationPolicy();
     $employee_list = $this->_templateobject->getAll();
     if (empty($employee_list)) {
         $employee_list = array(-1);
     }
     $sh->addConstraint(new Constraint('person_id', 'in', '(' . implode(',', $employee_list) . ')'));
     $fields[] = 'sum(duration) as total_hours';
     $sh->setFields($fields);
     parent::index($hours, $sh);
     $this->view->set('fields', array('person', 'type', 'total_hours'));
     $this->view->set('page_title', 'Hours Summary');
     $this->view->set('clickcontroller', 'hours');
     $this->view->set('clickaction', 'view');
     $this->view->set('linkfield', 'person_id');
     $this->view->set('linkvaluefield', 'name');
     $this->setTemplateName('hours_index');
     $sidebar = new SidebarController($this->view);
     $sidebarlist = array();
     $sidebarlist['new'] = array('tag' => 'Enter Employee Hours', 'link' => array('modules' => $this->_modules, 'controller' => 'hours', 'action' => 'new', 'company_id' => COMPANY_ID));
     $sidebar->addList('Actions', $sidebarlist);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }
Exemple #11
0
 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';
         }
     }
 }
Exemple #12
0
 function getNewStartPeriod(&$errors = array())
 {
     $glperiod = DataObjectFactory::Factory('GLPeriod');
     $cc = new ConstraintCHain();
     $cc->add(new Constraint('year', '=', $this->year + 1));
     $cc->add(new Constraint('period', '=', 0));
     $result = $glperiod->loadBy($cc);
     if (!$result) {
         $data['year'] = $this->year + 1;
         $data['period'] = 0;
         $data['description'] = 'B/f Balances';
         $data['enddate'] = un_fix_date($this->enddate);
         $data['closed'] = true;
         $data['tax_period'] = 0;
         $data['tax_period_closed'] = true;
         $glperiod = DataObject::Factory($data, $errors, 'GLPeriod');
         $result = false;
         if ($glperiod) {
             $result = $glperiod->save();
         }
     }
     if ($result) {
         return $glperiod;
     } else {
         $errors[] = 'Failed to create Start Year Period';
         return false;
     }
 }
 public function getRateTypeData($_employee = '', $_payment_type_id = '')
 {
     if (isset($this->_data['ajax'])) {
         if (!empty($this->_data['employee_id'])) {
             $_employee = DataObjectFactory::Factory('employee');
             $_employee->load($this->_data['employee_id']);
         }
         if (!empty($this->_data['payment_type_id'])) {
             $_payment_type_id = $this->_data['payment_type_id'];
         }
     }
     if (empty($_employee) || empty($_payment_type_id)) {
         return array('start_date' => array('data' => '', 'is_array' => FALSE), 'current_rates' => array('data' => '', 'is_array' => FALSE));
     }
     $collection = new EmployeeRateCollection($this->_templateobject);
     $sh = $this->setSearchHandler($collection);
     $sh->addConstraint(new Constraint('employee_id', '=', $_employee->id));
     $sh->addConstraint(new Constraint('payment_type_id', '=', $_payment_type_id));
     $this->view->set('clickaction', 'view');
     parent::index($collection, $sh);
     if ($collection->count() > 0) {
         $latest = $collection->current();
         if (!is_null($latest->end_date)) {
             $start_date = date(DATE_FORMAT, strtotime($latest->end_date . ' + 1 day'));
         } elseif ($latest->start_date > fix_date(date(DATE_FORMAT))) {
             $start_date = date(DATE_FORMAT, strtotime($latest->start_date . ' + 1 day'));
         } else {
             $start_date = date(DATE_FORMAT);
         }
     } else {
         $start_date = un_fix_date($_employee->start_date);
     }
     $output['start_date'] = array('data' => $start_date, 'is_array' => FALSE);
     // could we return the data as an array here? save having to re use it in the new / edit?
     // do a condition on $ajax, and return the array if false
     $this->view->set('no_ordering', true);
     $this->view->set('clickaction', 'none');
     if (isset($this->_data['ajax'])) {
         $this->view->set('collection', $collection);
         $current_rates = $this->view->fetch('datatable');
         $output['current_rates'] = array('data' => $current_rates, 'is_array' => FALSE);
         $this->view->set('data', $output);
         $this->setTemplateName('ajax_multiple');
     } else {
         return $output;
     }
 }
Exemple #14
0
function next_working_day($date)
{
    $dayno = date('w', strtotime($date));
    if ($dayno == 0) {
        return date(DATE_FORMAT, strtotime('+1 days', strtotime($date)));
    }
    if ($dayno == 6) {
        return date(DATE_FORMAT, strtotime('+2 days', strtotime($date)));
    }
    return un_fix_date($date);
}
 public function printInvoicelist($status = 'generate')
 {
     /*
      * The sales version of this invoice never shows any lines
      */
     // this function is very extensive, and thus we'll remove the max_execution_time
     set_time_limit(0);
     // construct title
     $title = $this->_data['type'] . ' Sales Invoices';
     // build options array
     $options = array('type' => array('pdf' => '', 'xml' => ''), 'output' => array('print' => '', 'save' => '', 'email' => '', 'view' => ''), 'filename' => $title, 'report' => 'InvoiceList');
     if (strtolower($status) == "dialog") {
         return $options;
     }
     $invoices = new SInvoiceCollection($this->_templateobject);
     // load the model
     switch ($this->_data['type']) {
         case 'New':
             $sh = new SearchHandler($invoices, false);
             $sh->setOrderby('due_date');
             $sh->addConstraint(new Constraint('transaction_type', '=', 'I'));
             $sh->addConstraint(new Constraint('status', '=', 'N'));
             $title .= ' as at ' . un_fix_date(fix_date(date(DATE_FORMAT)));
             break;
         case 'Overdue':
             $sh = new SearchHandler($invoices, false);
             $sh->setOrderby('due_date');
             $sh->addConstraint(new Constraint('transaction_type', '=', 'I'));
             if (isset($this->_data['status'])) {
                 $sh->addConstraint(new Constraint('status', '=', $this->_data['status']));
             } else {
                 $sh->addConstraint(new Constraint('status', 'in', "('N', 'Q', 'O')"));
             }
             $sh->addConstraint(new Constraint('due_date', '<=', fix_date(date(DATE_FORMAT))));
             $title .= ' as at ' . un_fix_date(fix_date(date(DATE_FORMAT)));
             break;
         case 'Day Book':
             // fetch the search handler from cache
             $sh = $this->setSearchHandler($invoices, $this->_data['search_id'], true);
             $sh->setLimit(0);
             // get the date values to build the title
             $this->setSearch('sinvoicesSearch', 'useDefault', array());
             $date = $this->search->getValue('invoice_date');
             if (!empty($date) && is_array($date)) {
                 $from_date = $date['from'];
                 $to_date = $date['to'];
             } else {
                 $from_date = '';
                 $to_date = '';
             }
             if (!empty($from_date)) {
                 if (!empty($to_date)) {
                     if ($from_date == $to_date) {
                         $title .= ' for ' . $from_date;
                     } else {
                         $title .= ' from ' . $from_date . ' to ' . $to_date;
                     }
                 } else {
                     $title .= ' from ' . $from_date;
                 }
             } else {
                 if (!empty($to_date)) {
                     $title .= ' to ' . $to_date;
                 }
             }
             if (empty($from_date) && empty($to_date)) {
                 $title .= ' for all invoices';
             }
             $sh->setOrderby('invoice_date');
             break;
     }
     $invoices->load($sh);
     $totals = array('base_net' => 0, 'base_tax' => 0, 'base_gross' => 0);
     foreach ($invoices as $invoice) {
         $totals['base_net'] += $invoice->base_net_value;
         $totals['base_tax'] += $invoice->base_tax_value;
         $totals['base_gross'] += $invoice->base_gross_value;
     }
     $params = DataObjectFactory::Factory('glparams');
     $base_currency = $params->base_currency_symbol();
     foreach ($totals as $key => $value) {
         $totals[$key] = $base_currency . sprintf('%0.2f', $value);
     }
     $extra = array('totals' => $totals, 'title' => $title);
     // generate the xml and add it to the options array
     $options['xmlSource'] = $this->generateXML(array('model' => $invoices, 'extra' => $extra, 'load_relationships' => FALSE));
     // execute the print output function, echo the returned json for jquery
     echo $this->constructOutput($this->_data['print'], $options);
     exit;
 }
 public function clone_invoice()
 {
     $flash = Flash::Instance();
     $errors = array();
     if (!isset($this->_data) || !$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $invoice = $this->_uses[$this->modeltype];
     if (!$invoice->isLoaded()) {
         $flash->addError('Error loading invoice details');
         sendBack();
     }
     $data[$this->modeltype] = array();
     foreach ($invoice->getFields() as $fieldname => $field) {
         switch ($fieldname) {
             case $invoice->idField:
             case 'created':
             case 'createdby':
             case 'lastupdated':
             case 'alteredby':
             case 'invoice_number':
             case 'invoice_date':
             case 'original_due_date':
             case 'auth_date':
             case 'auth_by':
                 break;
             case 'due_date':
                 $data[$this->modeltype][$fieldname] = un_fix_date($invoice->{$fieldname});
                 break;
             case 'status':
                 $data[$this->modeltype][$fieldname] = $invoice->newStatus();
                 break;
             default:
                 $data[$this->modeltype][$fieldname] = $invoice->{$fieldname};
         }
     }
     if (!empty($this->_data['transaction_type'])) {
         $data[$this->modeltype]['transaction_type'] = $this->_data['transaction_type'];
     }
     $line_count = 0;
     foreach ($invoice->lines as $invoiceline) {
         $modelname = get_class($invoiceline);
         foreach ($invoiceline->getFields() as $fieldname => $field) {
             switch ($fieldname) {
                 case $invoiceline->idField:
                 case 'created':
                 case 'createdby':
                 case 'lastupdated':
                 case 'alteredby':
                 case 'delivery_note':
                     break;
                 case 'purchase_order_id':
                 case 'order_line_id':
                     if ($this->_data['transaction_type'] == 'C') {
                         $data[$modelname][$fieldname][$line_count] = $invoiceline->{$fieldname};
                     }
                     break;
                 case 'invoice_id':
                     $data[$modelname][$fieldname][$line_count] = '';
                     break;
                 case 'invoice_line_id':
                     if ($this->_data['transaction_type'] == 'C') {
                         $data[$modelname][$fieldname][$line_count] = $invoiceline->{$invoiceline->idField};
                     }
                     break;
                 case 'productline_id':
                     if (!is_null($invoiceline->productline_id)) {
                         $productline = DataObjectFactory::Factory('POProductLine');
                         $productline->load($invoiceline->productline_id);
                         if (!$productline->isLoaded() || !is_null($productline->end_date) && $productline->end_date < un_fix_date(date(DATE_FORMAT))) {
                             $flash->addWarning('Selected Product is no longer valid on line ' . $invoiceline->line_number);
                             $invoiceline->description .= ' ** Selected Product is no longer valid';
                             $data[$modelname]['description'][$line_count] .= ' ** Selected Product is no longer valid';
                         }
                     }
                 default:
                     $data[$modelname][$fieldname][$line_count] = $invoiceline->{$fieldname};
             }
         }
         $line_count++;
     }
     $result = $invoice->save_model($data);
     if ($result !== FALSE) {
         sendTo($this->name, 'view', $this->_modules, array($invoice->idField => $result['internal_id']));
     }
     sendBack();
 }
Exemple #17
0
 public function printCostSheet($status = 'generate')
 {
     if (isset($this->_data['date']) && !empty($this->_data['stitem_id'])) {
         $date = $this->_data['date'];
     } else {
         $date = fix_date(date(DATE_FORMAT));
     }
     // build options array
     $options = array('type' => array('pdf' => '', 'xml' => ''), 'output' => array('print' => '', 'save' => '', 'email' => '', 'view' => ''), 'filename' => 'CostSheet' . $date, 'report' => 'CostSheet');
     if (strtolower($status) == "dialog") {
         return $options;
     }
     if (isset($this->_data['stitem_id'])) {
         $id = $this->_data['stitem_id'];
     } else {
         $id = '';
     }
     if (isset($this->_data['type'])) {
         $type = $this->_data['type'];
     } else {
         $type = 'latest';
     }
     $stitem = DataObjectFactory::Factory('STItem');
     $stitem->load($id);
     $cc = new ConstraintChain();
     $db = DB::Instance();
     //		$db->Debug();
     $between = "'" . $date . "' BETWEEN " . $db->IfNull('start_date', "'" . $date . "'") . ' AND ' . $db->IfNull('end_date', "'" . $date . "'");
     $cc->add(new Constraint('', '', '(' . $between . ')'));
     $cc->add(new Constraint('stitem_id', '=', $id));
     $mfstructures = self::getStructureCosts($cc, $type);
     $cc->removeLast();
     $child_structures = $stitem->getChildStructures();
     $stitem_ids = array($stitem->id);
     foreach ($child_structures as $child_structure) {
         $stitem_ids[] = $child_structure->ststructure_id;
     }
     $in = 'stitem_id IN (' . implode(',', $stitem_ids) . ')';
     $cc->add(new Constraint('', '', '(' . $in . ')'));
     $mfoperations = self::getOperationCosts($cc, $type);
     $mfoutsideops = self::getOutsideOperationCosts($cc, $type);
     $totals = array($type . '_mat' => 0, $type . '_lab' => 0, $type . '_osc' => 0, $type . '_ohd' => 0, $type . '_cost' => 0);
     foreach ($mfstructures as $mfstructure) {
         foreach ($mfstructure->getFields() as $field) {
             if (isset($totals[$field->name])) {
                 $totals[$field->name] += $field->value;
             }
         }
     }
     foreach ($mfoperations as $mfoperation) {
         foreach ($mfoperation->getFields() as $field) {
             if (isset($totals[$field->name])) {
                 $totals[$field->name] += $field->value;
             }
         }
     }
     foreach ($mfoutsideops as $mfoutsideop) {
         foreach ($mfoutsideop->getFields() as $field) {
             if (isset($totals[$field->name])) {
                 $totals[$field->name] += $field->value;
             }
         }
     }
     $title = 'Cost Sheet';
     // construct the extra array
     $extra['totals'][] = $totals;
     $extra['date'] = $date;
     $extra['type'] = $type;
     $extra['title'] = $title . ' as at ' . un_fix_date($date);
     // prepare the xml options array
     $xml_options = array('model' => array($stitem, $mfstructures, $mfoperations, $mfoutsideops), 'load_relationships' => FALSE, 'extra' => $extra);
     $options['xmlSource'] = $this->generateXML($xml_options);
     echo $this->constructOutput($this->_data['print'], $options);
     exit;
 }
 private function create_standard($header, $errors = array())
 {
     if (isset($this->_data['reverse']) && $this->_data['reverse'] == 'yes') {
         $reversal = true;
     }
     // Create new header from selected header
     $newheader = array();
     foreach ($header->getFields() as $fieldname => $field) {
         $newheader[$fieldname] = $header->{$fieldname};
     }
     unset($newheader['id']);
     unset($newheader['docref']);
     $period = DataObjectFactory::Factory('GLPeriod');
     $period->getCurrentPeriod();
     $newheader['transaction_date'] = un_fix_date($period->enddate);
     $newheader['glperiods_id'] = $period->id;
     if ($reversal) {
         $newheader['comment'] = 'Reversal of Ref:' . $header->docref . ' ' . $newheader['comment'];
         if ($newheader['glperiods_id'] == $header->glperiods_id) {
             $newheader['glperiods_id'] = key($this->getPeriods($newheader['transaction_date']));
         }
     } elseif ($newheader['accruals'] == 't') {
         $newheader['accrual_period_id'] = key($this->getPeriods($newheader['transaction_date']));
     }
     $newheader['type'] = $header->standardJournal();
     // Save the header and transactions
     $result = parent::save($this->modeltype, $newheader, $errors);
     if ($result) {
         // Copy existing header journal transactions to unposted transactions table
         $header->setTransactionsCollection();
         $sh = $this->setSearchHandler($header->transactions);
         $sh->setFields('*');
         // Ignore any reverse accruals when copying posted transactions
         $header->setTransactionsConstraints($sh, TRUE);
         $transactions = $header->transactions->load($sh, null, RETURN_ROWS);
         $docref = $this->saved_model->docref;
         foreach ($transactions as $row) {
             unset($row['id']);
             $row['docref'] = $docref;
             if ($reversal) {
                 $row['value'] = bcmul($row['value'], -1);
             }
             $result = DataObject::Factory($row, $errors, $header->unpostedTransactionFactory());
             if (!$result) {
                 break;
             } else {
                 $newtrans[] = $result;
             }
         }
         if ($result) {
             foreach ($newtrans as $unposted) {
                 if (!$unposted->save()) {
                     $result = FALSE;
                     $errors[] = 'Error creating journal transactions : ' . $db->ErrorMsg();
                     break;
                 }
             }
         }
     }
     if ($result) {
         // now set header to saved model and go to view the new header
         return $this->saved_model;
     }
     return FALSE;
 }
Exemple #19
0
 private function view_related_hours($search_fields = array())
 {
     $errors = array();
     $s_data = array();
     if (isset($this->_data['start_date'])) {
         $s_data['start_time']['from'] = empty($this->_data['start_date']) ? '' : un_fix_date($this->_data['start_date']);
     } else {
         $s_data['start_time']['from'] = date(DATE_FORMAT, strtotime("previous Monday"));
     }
     if (isset($this->_data['end_date'])) {
         $s_data['start_time']['to'] = empty($this->_data['end_date']) ? '' : un_fix_date($this->_data['end_date']);
     } else {
         $s_data['start_time']['to'] = date(DATE_FORMAT, strtotime("next Monday") - 1);
     }
     foreach ($search_fields as $field) {
         if (isset($this->_data[$field])) {
             $s_data[$field] = $this->_data[$field];
         }
     }
     // Set context from calling module
     $this->setSearch('hoursSearch', 'useDefault', $s_data);
     $this->view->set('clickaction', 'edit');
     $hour = DataObjectFactory::Factory('Hour');
     $hour->setDefaultDisplayFields(array('person', 'start_time', 'duration', 'description'));
     parent::index(new HourCollection($hour));
     $this->setTemplateName('hours_index');
 }
 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();
 }
 public function updateEvent()
 {
     $event = $this->_uses['SODespatchEvent'];
     $event->load($this->_data['id']);
     $data = $event->_data;
     // I'm sure there's a better way to format these dates...
     switch ($this->_data['type']) {
         case "drop":
             $data['start_time'] = un_fix_date(date('o-m-d H:i:s', strtotime("+" . $this->_data['day'] . " day", strtotime("+" . $this->_data['minute'] . " minute", strtotime($data['start_time'])))), true);
             $data['end_time'] = un_fix_date(date('o-m-d H:i:s', strtotime("+" . $this->_data['day'] . " day", strtotime("+" . $this->_data['minute'] . " minute", strtotime($data['end_time'])))), true);
             break;
         case "resize":
             $data['start_time'] = un_fix_date($data['start_time'], true);
             $data['end_time'] = un_fix_date(date('o-m-d H:i:s', strtotime("+" . $this->_data['day'] . " day", strtotime("+" . $this->_data['minute'] . " minute", strtotime($data['end_time'])))), true);
             break;
     }
     $errors = array();
     if (parent::save('SODespatchEvent', $data, $errors)) {
         json_reply(array('success' => TRUE));
     } else {
         json_reply(array('success' => FALSE));
     }
 }
 public function getStartEndDate($_project_id = '', $_task_id = '')
 {
     if (!empty($this->_data['project_id'])) {
         $_project_id = $this->_data['project_id'];
     }
     if (!empty($this->_data['task_id'])) {
         $_task_id = $this->_data['task_id'];
     }
     $obj = '';
     if (!empty($_task_id)) {
         $obj = new Task();
         $obj->load($_task_id);
     } elseif (!empty($_project_id)) {
         $obj = new Project();
         $obj->load($_project_id);
     }
     if ($obj instanceof DataObject && $obj->isLoaded()) {
         $start_date = un_fix_date($obj->start_date);
         $end_date = un_fix_date($obj->end_date);
     } else {
         $start_date = $end_date = date(DATE_FORMAT);
     }
     $output['start_date'] = array('data' => $start_date, 'is_array' => is_array($start_date));
     $output['end_date'] = array('data' => $end_date, 'is_array' => is_array($end_date));
     if (isset($this->_data['ajax'])) {
         $this->view->set('data', $output);
         $this->setTemplateName('ajax_multiple');
     } else {
         return $output;
     }
 }
Exemple #23
0
 public static function Factory(SOrder $header, $line_data, &$errors)
 {
     if (empty($line_data['order_id'])) {
         $line_data['order_id'] = $header->id;
     }
     if (empty($line_data['line_number'])) {
         $line_data['line_number'] = $header->getNextLineNumber();
     }
     $line_data['item_description'] = $line_data['description'];
     if ($line_data['productline_id'] == -1) {
         $line_data['productline_id'] = '';
         $line_data['stitem_id'] = '';
     } else {
         $productline = DataObjectFactory::Factory('SOProductline');
         $productline->load($line_data['productline_id']);
         if ($productline->isLoaded()) {
             $productlineheader = $productline->product_detail;
             if (is_null($productlineheader->stitem_id)) {
                 $line_data['item_description'] = $productline->getDescription();
                 $line_data['stitem_id'] = '';
             } else {
                 $line_data['item_description'] = $productlineheader->stitem;
                 $line_data['stitem_id'] = $productlineheader->stitem_id;
             }
             if (empty($line_data['price'])) {
                 $line_data['price'] = $productline->getPrice('', '', $productline->slmaster_id);
             }
             if (empty($line_data['glaccount_id'])) {
                 $line_data['glaccount_id'] = $productline->glaccount_id;
             }
             if (empty($line_data['glcentre_id'])) {
                 $line_data['glcentre_id'] = $productline->glcentre_id;
             }
             if (empty($line_data['stuom_id'])) {
                 $line_data['stuom_id'] = $productlineheader->stuom_id;
             }
             if (empty($line_data['tax_rate_id'])) {
                 $line_data['tax_rate_id'] = $productlineheader->tax_rate_id;
             }
         }
         // Check if glaccount_centre_id exists - can be any value including null
         if (!array_key_exists('glaccount_centre_id', $line_data)) {
             $line_data['glaccount_centre_id'] = GLAccountCentre::getAccountCentreId($line_data['glaccount_id'], $line_data['glcentre_id'], $errors);
         }
         if (empty($line_data['net_value'])) {
             $line_data['net_value'] = bcmul($line_data['price'], $line_data['revised_qty']);
         }
     }
     if ($line_data['revised_qty'] > 0 && $line_data['price'] > 0) {
         if (empty($line_data['id'])) {
             // New Line
             $line_data['order_qty'] = $line_data['os_qty'] = $line_data['revised_qty'];
             $line_data['status'] = 'N';
         } else {
             // Amended Line
             if ($line_data['status'] == 'N') {
                 $line_data['os_qty'] = $line_data['revised_qty'];
             }
         }
     } else {
         $errors[] = 'Zero quantity or net value';
     }
     if (count($errors) > 0) {
         return false;
     }
     if (empty($line_data['description'])) {
         $line_data['description'] = $line_data['item_description'];
     }
     $line_data['line_discount'] = 0;
     $line_data['currency_id'] = $header->currency_id;
     $line_data['rate'] = $header->rate;
     $line_data['twin_currency_id'] = $header->twin_currency_id;
     $line_data['twin_rate'] = $header->twin_rate;
     $line_data['base_net_value'] = bcadd(round(bcdiv($line_data['net_value'], $line_data['rate'], 4), 2), 0);
     $line_data['twin_net_value'] = bcadd(round(bcmul($line_data['base_net_value'], $line_data['twin_rate'], 4), 2), 0);
     if (empty($line_data['due_delivery_date'])) {
         $line_data['due_delivery_date'] = un_fix_date($header->due_date);
     }
     if (empty($line_data['due_despatch_date'])) {
         $line_data['due_despatch_date'] = un_fix_date($header->despatch_date);
     }
     return parent::Factory($line_data, $errors, 'SOrderLine');
 }
Exemple #24
0
 /**
  * Construct a line, resolving enums, foriegn values etc
  *
  * @access public
  * @param mixed $data
  * @param array $table
  * @return array
  */
 public function construct_line($data, $table)
 {
     $rowData = array();
     foreach ($table as $key => $value) {
         if ($key == 'paging' || $value == '{PAGENUM}') {
             $rowData[$key] = $this->currentPage;
         } elseif ($data instanceof DataObject && $data->isField($key)) {
             if ($data->isEnum($key)) {
                 // enumerated fields
                 $field = $data->getField($key);
                 $rowData[$key] = $field->formatted;
             } else {
                 // date, timestamp
                 if (is_object($data->getField($key)) && $data->getField($key)->type == 'date') {
                     $rowData[$key] = is_null($data->{$key}) ? '' : un_fix_date($data->{$key});
                 } elseif (is_object($data->getField($key)) && $data->getField($key)->type == 'timestamp') {
                     $rowData[$key] = is_null($data->{$key}) ? '' : date(DATE_TIME_FORMAT, strtotime($data->{$key}));
                 } elseif (is_object($data->getField($key))) {
                     // $rowData[$key]=$data->$key;
                     // The currency symbol stored in the database is not displaying properly.
                     // The database encoding is UTF8 and when displayed in the pdf document
                     // either &pound; is displayed or £
                     // $rowData[$key]=utf8_decode($data->getField($key)->formatted);
                     // Need this conversion to get the Euro symbol to print in pdf!!!
                     // Also see EGSpdf for setting the iso-8859-15 Euro character position to pdf Euro
                     // If we encode the line FOP cannot output the document -> http://apps.severndelta.co.uk/dokuwiki/doku.php/encoding_characters_in_xml
                     $rowData[$key] = $data->getFormatted($key, FALSE);
                     // is this causeing problems £ --> #iconv('UTF-8', 'iso-8859-15//TRANSLIT', $data->getFormatted($key, false));
                     // $rowData[$key]=$data->getField($key)->value;
                 } else {
                     $rowData[$key] = $data->getField($key);
                 }
             }
         } elseif ($data instanceof DataObject && method_exists($data, $key)) {
             // the field name in $key is a class method in the $data object
             if (isset($value['value'])) {
                 $rowData[$key] = call_user_func(array($data, $key), $value['value']);
             } else {
                 $rowData[$key] = call_user_func(array($data, $key));
             }
         } elseif (is_array($data)) {
             // the data is an array
             if ($data[$key] == '{PAGENUM}') {
                 $rowData[$key] = $this->currentPage;
             } else {
                 $rowData[$key] = $data[$key];
             }
         } else {
             // the data is a constant
             if (isset($value['value']) && $value['value'] == '{PAGENUM}') {
                 $value['value'] = $this->currentPage;
             }
             $rowData[$key] = isset($value['value']) ? $value['value'] : (isset($value['title']) ? $value['title'] : prettify($key));
         }
     }
     return $rowData;
 }
Exemple #25
0
 public function getSettlementTerms()
 {
     $payterms = DataObjectFactory::Factory('PaymentTerm');
     if ($payterms->load($this->payment_term_id)) {
         $terms = $payterms->days == 0 ? $payterms->months . ' months' : $payterms->days . ' days';
         $terms .= $payterms->basis == 'I' ? ' from Invoice.' : ' from Month End.';
         if ($this->settlement_discount > 0) {
             $terms .= chr(10) . 'A discount of ' . $this->settlement_discount . ' ' . $this->currency . ' can be deducted if paid before ';
         } else {
             $terms .= chr(10) . 'Please make payment in full by ';
         }
         $terms .= un_fix_date($this->due_date);
         return $terms;
     } else {
         return '';
     }
 }
Exemple #26
0
 private function getAttachments()
 {
     $attachments = new EntityAttachmentCollection();
     $sh = new SearchHandler($attachments, FALSE);
     $sh->addConstraint(new Constraint('data_model', '=', 'modulecomponent'));
     $sh->addConstraint(new Constraint('entity_id', '=', ModuleComponent::getComponentId($this->_modules['module'], strtolower(get_class($this)))));
     $sh->addConstraint(new Constraint('createdby', '=', EGS_USERNAME));
     $files = $attachments->load($sh, null, RETURN_ROWS);
     $dirobjs = array();
     if (count($files) > 0) {
         foreach ($files as $attachment) {
             $link = '/?' . setParamsString(array('modules' => $this->_modules, 'controller' => 'attachments', 'action' => 'view_file', 'other' => array(file_id => $attachment['file_id'])));
             $details = array('name' => $attachment['file'], 'link' => $link, 'type' => 'attachment', 'delete' => array('modules' => $this->_modules, 'controller' => 'attachments', 'action' => 'delete', 'id' => $attachment['id']), 'size' => sizify($attachment['size']), 'mtime' => un_fix_date($attachment['lastupdated']));
             $dirobjs['file'][] = $details;
         }
     }
     return $dirobjs;
 }
 public function print_packing_slips($status = 'generate')
 {
     // build options array
     $options = array('type' => array('pdf' => ''), 'output' => array('print' => '', 'save' => '', 'email' => '', 'view' => ''), 'report' => 'SO_PackingList', 'xslVars' => $xslVars);
     if (strtolower($status) == "dialog") {
         return $options;
     }
     // we need to merge the original data back with the normal data array
     // should this be done automatically?
     $original_data = $this->decode_original_form_data($this->_data['encoded_query_data']);
     $this->_data = array_merge($this->_data, $original_data);
     if (!$this->checkParams('SOrder')) {
         sendBack();
     }
     $errors = array();
     $messages = array();
     if (isset($this->_data['SOrder']['id'])) {
         $sorder = DataObjectFactory::Factory('SOrder');
         $sorder->load($this->_data['SOrder']['id']);
         if (!$sorder->isLoaded()) {
             $errors[] = 'Cannot find order';
         }
     } else {
         $errors[] = 'No order id';
     }
     $print_count = 0;
     foreach ($this->_data[$this->modeltype] as $id => $action) {
         if (isset($action['print'])) {
             $print_count += 1;
         }
     }
     if ($print_count == 0) {
         $errors[] = 'No packing slips selected for printing';
     }
     if (count($errors) > 0) {
         echo $this->returnResponse(FALSE, array('message' => implode('<br />', $errors)));
         exit;
     }
     foreach ($this->_data[$this->modeltype] as $id => $action) {
         if (isset($action['print'])) {
             $sopackingslip = DataObjectFactory::Factory('SOPackingSlip');
             $sopackingslip->load($id);
             if ($sopackingslip->isLoaded()) {
                 // set a new filename for each document
                 $options['filename'] = 'so_packing_list_' . $id;
                 // set a few variables
                 $order = $sopackingslip->order_detail;
                 // set extra variable
                 $extra = array();
                 // set packing line
                 $contents = array($contents = unserialize(base64_decode($sopackingslip->contents)));
                 // make sure the contents var is a single array
                 if (is_array(reset($contents))) {
                     $contents = reset($contents);
                 }
                 $packinglines = array();
                 foreach ($contents as $description => $qty) {
                     if ($qty > 0) {
                         $packinglines[]['line'][] = array('description' => $description, 'qty' => $qty);
                     }
                 }
                 $extra['packing_lines'] = $packinglines;
                 // set company address
                 $company_address = array('name' => $this->getCompanyName());
                 $company_address += $this->formatAddress($this->getCompanyAddress());
                 $extra['company_address'] = $company_address;
                 // set document details
                 $document_reference = array();
                 $document_reference[]['line'] = array('label' => 'Order Date', 'value' => un_fix_date($order->order_date));
                 $document_reference[]['line'] = array('label' => 'Our Order Number', 'value' => $order->order_number);
                 $document_reference[]['line'] = array('label' => 'Customer Ref', 'value' => $order->ext_reference);
                 $document_reference[]['line'] = array('label' => 'Due Date', 'value' => un_fix_date($order->due_date));
                 $document_reference[]['line'] = array('label' => 'Pack Ref', 'value' => $sopackingslip->name);
                 $extra['document_reference'] = $document_reference;
                 // generate xml
                 $options['xmlSource'] = $this->generateXML(array('model' => $sopackingslip, 'relationship_whitelist' => array('order_detail'), 'extra' => $extra));
                 // generate output
                 $response = json_decode($this->constructOutput($this->_data['print'], $options), TRUE);
                 // check for failure and set errors
                 if ($response['status'] === FALSE) {
                     $errors[] = $this->_data['printaction'] . ' Sales Order ' . $sopackingslip->order_number . ' Packing List ' . $sopackingslip->name . ' Failed';
                 } else {
                     $messages[] = $response['message'];
                 }
             }
         }
     }
     if (count($errors) > 0) {
         echo $this->returnResponse(FALSE, array('message' => implode('<br />', $errors)));
     } else {
         $response['message'] = implode('<br />', $messages);
         echo $this->returnResponse(TRUE, $response);
     }
     exit;
 }
 public function confirm_print_labels()
 {
     $flash = Flash::Instance();
     $errors = array();
     if (!$this->checkParams('POReceivedLine')) {
         $this->dataError();
         sendBack();
     }
     // May want to move this to a separate class (See Manufacturing Works Orders Reports)
     // to allow for custom overload
     $data['printtype'] = 'pdf';
     $data['printaction'] = 'Print';
     $data['printer'] = $this->_data['printer'];
     //		$data['attributes']['orientation-requested'] = 'landscape';
     $data['attributes']['media'] = 'A5';
     $label_types = array('pallet', 'item');
     foreach ($this->_data['POReceivedLine'] as $key => $line) {
         if (isset($line['print'])) {
             $item_type = explode('-', $line['stitem']);
             foreach ($label_types as $label_type) {
                 if ($line[$label_type . '_count'] > 0) {
                     if (isset($line[$label_type . '_labels'])) {
                         $line[$label_type . '_count'] *= $line[$label_type . '_labels'];
                     }
                     for ($i = 0; $i < $line[$label_type . '_count']; $i++) {
                         $extra[]['GRN'] = array('item_type' => $item_type[0], 'item_code' => trim($item_type[1]), 'gr_number' => $line['gr_number'], 'received_qty' => number_format($line[$label_type . '_qty'], $line['qty_decimals']), 'received_date' => un_fix_date($line['received_date']));
                     }
                 }
             }
         }
     }
     // generate the XML, include the extras array too
     $xml = $this->generateXML(array('extra' => $extra));
     // build a basic list of options
     $options = array('report' => 'GRN-labels', 'xmlSource' => $xml);
     $response = json_decode($this->generate_output($data, $options));
     if ($response->status !== true) {
         $flash->addError(get_class($report) . ": " . $response->message);
     } else {
         $flash->addMessage(get_class($report) . " printed successfully");
     }
     sendBack();
     if (count($errors) > 0) {
         $flash->addErrors($errors);
     } else {
         $flash->addMessage('Print Works Order Paperwork Completed');
     }
 }
Exemple #29
0
 protected function makeGLTransactions(&$errors = array())
 {
     $newerrors = array();
     //sort out the header details
     $gl_transactions = array();
     $gl_data = array();
     //the gl docref is the invoice number
     $gl_data['docref'] = $this->invoice_number;
     $gl_data['reference'] = $this->our_reference;
     //dates should be the same
     $gl_data['transaction_date'] = un_fix_date($this->invoice_date);
     //first character of class identifies source
     $gl_data['source'] = substr(strtoupper(get_class($this)), 0, 1);
     //type depends on Invoice or Credit Note
     $gl_data['type'] = $this->transaction_type;
     //the description is one from a number of bits of information
     //(description is compulsory for GL, but the options aren't for SLTransaction and SInvoice)
     $desc = $this->description;
     $ext_ref = $this->ext_reference;
     $sales_order_id = $this->sales_order_id;
     if (!empty($desc)) {
         $header_desc = $desc;
     } elseif (!empty($ext_ref)) {
         $header_desc = $ext_ref;
     } elseif (!empty($sales_order_id)) {
         $header_desc = $sales_order_id;
     } else {
         $header_desc = $this->invoice_number;
     }
     $gl_data['comment'] = $header_desc;
     //another docref
     $gl_data['docref2'] = $sales_order_id;
     // set the period based on invoice date
     $glperiod = GLPeriod::getPeriod($this->invoice_date);
     if (!$glperiod || count($glperiod) == 0) {
         $errors[] = 'No period exists for this date';
         return false;
     }
     $gl_data['glperiods_id'] = $glperiod['id'];
     $gl_data['twin_currency_id'] = $this->twin_currency_id;
     $gl_data['twin_rate'] = $this->twin_rate;
     //there needs to be a tax element
     $gl_data['base_tax_value'] = $this->base_tax_value;
     $gl_data['twin_tax_value'] = $this->twin_tax_value;
     $vat_element = GLTransaction::makeCBTax($gl_data, $newerrors);
     if ($vat_element !== false) {
         $gl_transactions[] = $vat_element;
     } else {
         $errors += $newerrors;
         return false;
     }
     //this is the control element (used to balance the tax and lines)
     $gl_data['base_gross_value'] = $this->base_gross_value;
     $gl_data['twin_gross_value'] = $this->twin_gross_value;
     $gl_params = DataObjectFactory::Factory('GLParams');
     $gl_data['glaccount_id'] = $this->get_ledger_control_account($gl_params, $errors);
     if ($gl_data['glaccount_id'] === FALSE) {
         return FALSE;
     }
     $gl_data['glcentre_id'] = $this->get_balance_sheet_cost_centre($gl_params, $errors);
     if ($gl_data['glcentre_id'] === FALSE) {
         return FALSE;
     }
     $control = GLTransaction::makeCBControl($gl_data, $newerrors);
     if ($control !== false) {
         $gl_transactions[] = $control;
     } else {
         $errors += $newerrors;
         return false;
     }
     // Now do the GL Transactions for each invoice line
     $this->makeGLTransactionLines($gl_data, $gl_transactions, $errors);
     return $gl_transactions;
 }
 public function post($errors = array())
 {
     $db = db::Instance();
     // Check it hasn't been posted!
     if (!$this->isUnposted()) {
         $errors[] = 'Journal has already been posted';
         return FALSE;
     }
     // Check it is a standard journal
     if (!$this->isStandardJournal()) {
         $errors[] = 'Template Journal cannot be posted';
         return FALSE;
     }
     // Get all unposted transcations
     $this->NewTransactions();
     $sh = new SearchHandler($this->transactions, false);
     $sh->addConstraint($this->childConstraint());
     $unposted = $this->transactions->load($sh, null, RETURN_ROWS);
     // Save transactions to GL Transactions
     $db->startTrans();
     foreach ($unposted as $transaction) {
         unset($transaction['id']);
         $transaction['transaction_date'] = un_fix_date($this->transaction_date);
         $transaction['glperiods_id'] = $this->glperiods_id;
         GLTransaction::setTwinCurrency($transaction);
         $gltransaction = GLTransaction::Factory($transaction);
         if (!$gltransaction->save()) {
             $errors[] = 'Error saving journal transaction : ' . $db->ErrorMsg();
         } elseif (!$gltransaction->updateBalance($errors)) {
             $errors[] = 'Error updating GL balance : ' . $db->ErrorMsg();
         }
         if ($this->accrual == 't') {
             $transaction['glperiods_id'] = $this->accrual_period_id;
             $transaction['comment'] = 'Reverse ' . $transaction['comment'];
             $transaction['value'] = bcmul($transaction['value'], -1);
             $gltransaction = GLTransaction::Factory($transaction);
             if (!$gltransaction->save()) {
                 $errors[] = 'Error saving journal transaction : ' . $db->ErrorMsg();
             } elseif (!$gltransaction->updateBalance($errors)) {
                 $errors[] = 'Error updating GL balance : ' . $db->ErrorMsg();
             }
         }
     }
     // Update the header status if no errors so far
     if (empty($errors) && !$this->update($this->{$this->idField}, 'status', $this->postedStatus())) {
         $errors[] = 'Error updating journal header status : ' . $db->ErrorMsg();
     }
     // Delete the unposted transactions if posted OK
     if (count($errors) > 0 || !$this->transactions->delete($sh)) {
         $errors[] = 'Error updating posted journals : ' . $db->ErrorMsg();
         $db->FailTrans();
     }
     return $db->CompleteTrans();
 }