public function summary_report()
 {
     $users = array();
     if (isModuleAdmin()) {
         $u = DataObjectFactory::Factory('User');
         $users = $u->getAll();
     }
     $this->view->set('users', $users);
     if (isset($this->_data['filter'])) {
         $cc = new ConstraintChain();
         if (!empty($this->_data['from_date'])) {
             $cc->add(new Constraint('enddate', '>', fix_date($this->_data['from_date'])));
         }
         if (!empty($this->_data['to_date'])) {
             $cc->add(new Constraint('enddate', '<', fix_date($this->_data['to_date'])));
         }
         if (!isModuleAdmin()) {
             $cc->add(new Constraint('assigned', '=' . EGS_USERNAME));
         } elseif (!empty($this->_data['assigned'])) {
             $cc->add(new Constraint('assigned', '=', $this->_data['assigned']));
         }
         $opp_sh = new SearchHandler(new OpportunityCollection($this->_templateobject), false);
         $opp_sh->addConstraintChain($cc);
         $opp_sh->extract();
         $os = DataObjectFactory::Factory('Opportunitystatus');
         $os->addSearchHandler('opportunities', $opp_sh);
         $statuses = new OpportunitystatusCollection($os);
         $sh = new SearchHandler($statuses, false);
         $sh->extract();
         $statuses->load($sh);
         $this->view->set('statuses', $statuses);
         $this->view->set('report_headings', array('name', 'company', 'person', 'enddate', 'type', 'cost', 'assigned'));
         $this->view->set('cc', $cc);
     }
 }
Example #2
0
 function revalue($data, &$errors = array())
 {
     if (empty($data['transaction_date'])) {
         $data['transaction_date'] = date(DATE_FORMAT);
     }
     $glperiod = GLPeriod::getPeriod(fix_date($data['transaction_date']));
     if (!$glperiod || count($glperiod) == 0) {
         $errors[] = 'No period exists for this date';
         return false;
     }
     $data['value'] = bcsub($this->glbalance(), $data['new_balance']);
     $data['glperiods_id'] = $glperiod['id'];
     $data['source'] = 'C';
     $data['type'] = 'V';
     $data['glaccount_id'] = $this->currency_detail->writeoff_glaccount_id;
     $data['glcentre_id'] = $this->currency_detail->glcentre_id;
     GLTransaction::setTwinCurrency($data);
     $gl_trans[] = GLTransaction::Factory($data, $errors);
     $data['value'] = bcmul($data['value'], -1);
     $data['glaccount_id'] = $this->glaccount_id;
     $data['glcentre_id'] = $this->glcentre_id;
     GLTransaction::setTwinCurrency($data);
     $gl_trans[] = GLTransaction::Factory($data, $errors);
     $db = DB::Instance();
     $db->StartTrans();
     if (count($errors) == 0 && GLTransaction::saveTransactions($gl_trans, $errors)) {
         return $db->CompleteTrans();
     }
     $errors[] = 'Failed to save GL Transaction';
     $db->FailTrans();
     $db->CompleteTrans();
     return false;
 }
 public function index()
 {
     $this->view->set('clickaction', 'view');
     $s_data = array();
     // Set context from calling module
     if (isset($this->_data['slmaster_id'])) {
         $s_data['slmaster_id'] = $this->_data['slmaster_id'];
     }
     if (isset($this->_data['status'])) {
         $s_data['status'] = $this->_data['status'];
     }
     $this->setSearch('sltransactionsSearch', 'useDefault', $s_data);
     $transaction_date = $this->search->getValue('transaction_date');
     if (isset($transaction_date['from'])) {
         $from_date = fix_date($transaction_date['from']);
     } else {
         $from_date = '';
     }
     if (isset($transaction_date['to'])) {
         $to_date = fix_date($transaction_date['to']);
     } else {
         $to_date = '';
     }
     parent::index(new SLTransactionCollection($this->_templateobject));
     $this->view->set('search', $s_data);
 }
Example #4
0
 public function save()
 {
     $flash = Flash::Instance();
     $errors = array();
     $data = $this->_data[$this->modeltype];
     $obj = '';
     if (!empty($data['task_id'])) {
         $obj = new Task();
         $obj->load($data['task_id']);
     } elseif (!empty($data['project_id'])) {
         $obj = new Project();
         $obj->load($data['project_id']);
     }
     if ($obj instanceof DataObject && $obj->isLoaded()) {
         if (fix_date($data['start_date']) < $obj->start_date) {
             $errors['start_date'] = 'Start date before ' . get_class($obj) . ' start date';
         }
         if (fix_date($data['end_date']) > $obj->end_date) {
             $errors['end_date'] = 'End date after ' . get_class($obj) . ' end date';
         }
     }
     if (!empty($data['person_id']) && $data['quantity'] > 1) {
         $errors['person_id'] = 'Quantity must be 1 for a person';
     }
     if (count($errors) == 0 && parent::save($this->modeltype, '', $errors)) {
         sendBack();
     } else {
         $flash->addErrors($errors);
         $this->refresh();
     }
 }
Example #5
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;
 }
Example #6
0
 function copyStructure($data, &$errors)
 {
     $mfstructures = new MFStructureCollection(DataObjectFactory::Factory('MFStructure'));
     $cc1 = new ConstraintChain();
     $cc1->add(new Constraint('stitem_id', '=', $data->stitem_id));
     $cc1->add(new Constraint('start_date', '<=', fix_date(date(DATE_FORMAT))));
     $cc2 = new ConstraintChain();
     $cc2->add(new Constraint('end_date', '>=', fix_date(date(DATE_FORMAT))));
     $cc2->add(new Constraint('end_date', 'is', 'NULL'), 'OR');
     $sh = new SearchHandler($mfstructures, false);
     $sh->addConstraintChain($cc1);
     $sh->addConstraintChain($cc2);
     $mfstructures->load($sh);
     $wo_structure = array();
     $wo_structures = array();
     $copyfields = array('line_no', 'qty', 'uom_id', 'remarks', 'waste_pc', 'ststructure_id');
     foreach ($mfstructures as $input) {
         $wo_structure['work_order_id'] = $data->id;
         foreach ($copyfields as $field) {
             $wo_structure[$field] = $input->{$field};
         }
         $wo_structures[$input->line_no] = DataObject::Factory($wo_structure, $errors, 'MFWOStructure');
     }
     return $wo_structures;
 }
Example #7
0
 public static function Factory($data, &$errors = array(), $do_name = null)
 {
     if (empty($data['calendar_week'])) {
         $data['calendar_week'] = date('W', strtotime(fix_date($data['period_start_date'], DATE_TIME_FORMAT, $errors)));
     }
     return parent::Factory($data, $errors, $do_name);
 }
Example #8
0
 public static function makeHeader($data, $do, &$errors)
 {
     if (strtotime(fix_date($data['order_date'])) > strtotime(fix_date(date(DATE_FORMAT)))) {
         $errors[] = 'Order Date cannot be in the future';
         return false;
     }
     if (!isset($data['id']) || $data['id'] == '') {
         //			$generator = new OrderNumberHandler();
         $generator = new UniqueNumberHandler(false, $data['type'] != 'T');
         $data['order_number'] = $generator->handle(DataObjectFactory::Factory($do));
         $data['status'] = 'N';
         $user = getCurrentUser();
         $data['raised_by'] = $user->username;
     }
     //determine the base currency
     $currency = DataObjectFactory::Factory('Currency');
     $currency->load($data['currency_id']);
     $data['rate'] = $currency->rate;
     //determine the twin currency
     $glparams = DataObjectFactory::Factory('GLParams');
     $twin_currency = DataObjectFactory::Factory('Currency');
     $twin_currency->load($glparams->base_currency());
     $data['twin_rate'] = $twin_currency->rate;
     $data['twin_currency_id'] = $twin_currency->id;
     return DataObject::Factory($data, $errors, $do);
 }
Example #9
0
 public function loadPeriod($date)
 {
     // Loads the period in which the supplied date falls
     $subquery = "(SELECT min(enddate) \r\n\t\t\t\t       FROM gl_periods z\r\n\t\t\t\t      WHERE z.enddate >= '" . fix_date($date) . "' AND z.usercompanyid = " . EGS_COMPANY_ID . ")";
     $cc = new ConstraintChain();
     $cc->add(new Constraint('enddate', '=', $subquery));
     return $this->loadBy($cc);
 }
Example #10
0
 function getCurrent($cc = null)
 {
     if (!$cc instanceof ConstraintChain) {
         $cc = new ConstraintChain();
     }
     $cc1 = new ConstraintChain();
     $cc1->add(new Constraint('end_date', 'is', 'NULL'));
     $cc1->add(new Constraint('end_date', '>', fix_date(date(DATE_FORMAT))), 'OR');
     $cc->add($cc1);
 }
Example #11
0
 function populate()
 {
     $pp = new PeriodicPaymentCollection();
     $pl = new PageList('overdue_periodic_payments');
     $sh = new SearchHandler($pp, false);
     $sh->addConstraint(new Constraint('status', '=', "('A')"));
     $sh->addConstraint(new Constraint('next_due_date', '<=', fix_date(date(DATE_FORMAT))));
     $this->setSearchLimit($sh);
     $sh->setOrderBy('next_due_date');
     $pp->load($sh);
     $this->contents = $pp;
 }
Example #12
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;
     }
 }
Example #13
0
 public function get_week_dates(&$errors = array())
 {
     if (!$this->isLoaded()) {
         $this->loadBy('usercompanyid', EGS_COMPANY_ID);
     }
     if (!$this->isLoaded()) {
         $errors[] = 'Cannot find HR Parameters';
         return FALSE;
     }
     $dates['week_start_date'] = fix_date(date(DATE_FORMAT, strtotime('last ' . $this->week_start_day))) . ' ' . $this->week_start_time . ':00';
     $dates['week_end_date'] = fix_date(date(DATE_FORMAT, strtotime($dates['week_start_date'] . ' + 7day'))) . ' ' . $this->week_start_time . ':00';
     return $dates;
 }
 function populate()
 {
     $pl = new PageList('companies_added_today');
     $companies_do = new CompanyCollection(new Company());
     $sh = new SearchHandler($companies_do, false);
     $sh->extract();
     $sh->addConstraint(new Constraint('is_lead', '=', 'false'));
     $sh->addConstraint(new Constraint('created', '>', fix_date(date(DATE_FORMAT))));
     $sh->setLimit(10);
     $companies_do->load($sh);
     $pl->addFromCollection($companies_do, array('module' => 'contacts', 'controller' => 'companys', 'action' => 'view'), array('id'), 'company', 'name');
     $this->contents = $pl->getPages()->toArray();
 }
Example #15
0
 function populate()
 {
     $orders = new POrderLineCollection();
     $orders->setParams();
     $sh = new SearchHandler($orders, false);
     $sh->addConstraint(new Constraint('status', 'in', "('A','P')"));
     $sh->addConstraint(new Constraint('order_status', '!=', "X"));
     $sh->addConstraint(new Constraint('due_delivery_date', '<', fix_date(date(DATE_FORMAT))));
     $this->setSearchLimit($sh);
     $sh->setOrderBy(array('due_delivery_date', 'id'));
     $orders->load($sh);
     $this->contents = $orders;
 }
Example #16
0
 public function getItems()
 {
     $mfoperation = DataObjectFactory::Factory('MFOperation');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('mfcentre_id', '=', $this->mf_centre_id));
     $cc->add(new Constraint('obsolete_date', 'is', 'NULL'));
     $cc1 = new ConstraintChain();
     $cc1->add(new Constraint('end_date', '>', fix_date(date(DATE_FORMAT))));
     $cc1->add(new Constraint('end_date', 'is', 'NULL'), 'OR');
     $cc->add($cc1);
     $mfoperation->idField = 'stitem_id';
     $mfoperation->identifierField = 'stitem';
     $mfoperation->orderby = 'stitem';
     return $mfoperation->getAll($cc, TRUE, TRUE);
 }
Example #17
0
 static function Factory($data, &$errors, $do_name = __CLASS__)
 {
     $do = DataObjectFactory::Factory($do_name);
     $db = DB::Instance();
     if (empty($data['docref'])) {
         $data['docref'] = $db->GenID('gl_transactions_docref_seq');
     }
     $glperiod = GLPeriod::getPeriod(fix_date($data['transaction_date']));
     if (!$glperiod || count($glperiod) == 0) {
         $errors[] = 'No period exists for this date';
     }
     $data['glperiods_id'] = $glperiod['id'];
     $data['status'] = $do->newStatus();
     return parent::Factory($data, $errors, $do);
 }
 function populate()
 {
     $pl = new PageList('top_sales_orders');
     $today = fix_date(date(DATE_FORMAT));
     $weekend = fix_date(date(DATE_FORMAT, strtotime("next Monday", strtotime($today)) - 1));
     $startdate = fix_date('01/' . date('m/Y'));
     $monthend = fix_date(date(DATE_FORMAT, strtotime("+1 months", strtotime($startdate)) - 1));
     $nextmonth = fix_date(date(DATE_FORMAT, strtotime("+2 months", strtotime($startdate)) - 1));
     $orderline = DataObjectFactory::Factory('SOrderLine');
     $db =& DB::Instance();
     // Get overdue orders
     $cc = new ConstraintChain();
     $cc->add(new Constraint('type', '=', $this->params['type']));
     $cc->add(new Constraint('status', 'in', "('N', 'R', 'S')"));
     $cc->add(new Constraint('due_despatch_date', '<', $db->qstr($today)));
     $customersales['Overdue'] = $orderline->getSum('base_net_value', $cc, 'so_linesoverview');
     // Get orders due today
     $cc = new ConstraintChain();
     $cc->add(new Constraint('type', '=', $this->params['type']));
     $cc->add(new Constraint('status', 'in', "('N', 'R', 'S')"));
     $cc->add(new Constraint('due_despatch_date', '=', $db->qstr($today)));
     $customersales['Today'] = $orderline->getSum('base_net_value', $cc, 'so_linesoverview');
     // Get orders due this week
     $cc = new ConstraintChain();
     $cc->add(new Constraint('type', '=', $this->params['type']));
     $cc->add(new Constraint('status', 'in', "('N', 'R', 'S')"));
     $cc->add(new Constraint('due_despatch_date', '>', $db->qstr($today)));
     $cc->add(new Constraint('due_despatch_date', '<=', $db->qstr($weekend)));
     $customersales['This Week'] = $orderline->getSum('base_net_value', $cc, 'so_linesoverview');
     // Get orders due this month
     $cc = new ConstraintChain();
     $cc->add(new Constraint('type', '=', $this->params['type']));
     $cc->add(new Constraint('status', 'in', "('N', 'R', 'S')"));
     $cc->add(new Constraint('due_despatch_date', '>', $db->qstr($weekend)));
     $cc->add(new Constraint('due_despatch_date', '<=', $db->qstr($monthend)));
     $customersales['This Month'] = $orderline->getSum('base_net_value', $cc, 'so_linesoverview');
     // Get orders due next month
     $cc = new ConstraintChain();
     $cc->add(new Constraint('type', '=', $this->params['type']));
     $cc->add(new Constraint('status', 'in', "('N', 'R', 'S')"));
     $cc->add(new Constraint('due_despatch_date', '>', $db->qstr($monthend)));
     $cc->add(new Constraint('due_despatch_date', '<=', $db->qstr($nextmonth)));
     $customersales['Next Month'] = $orderline->getSum('base_net_value', $cc, 'so_linesoverview');
     $this->title = 'Title';
     $this->contents['main'] = $customersales;
     $this->contents['type'] = $this->params['type'];
 }
Example #19
0
 public function checkStartDate($_employee_id, $_start_date, $_end_date = '')
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('employee_id', '=', $_employee_id));
     $db = DB::Instance();
     $cc1 = new ConstraintChain();
     $cc1->add(new Constraint('start_date', 'between', $db->qstr(fix_date($_start_date)) . ' and ' . $db->qstr(empty($_end_date) ? fix_date(date(DATE_FORMAT)) : fix_date($_end_date))));
     $cc2 = new ConstraintChain();
     $cc2->add(new Constraint('start_date', '<', fix_date($_start_date)));
     $cc3 = new ConstraintChain();
     $cc3->add(new Constraint('end_date', '>=', fix_date($_start_date)));
     $cc3->add(new Constraint('end_date', 'is', 'NULL'), 'OR');
     $cc2->add($cc3);
     $cc1->add($cc2, 'OR');
     $cc->add($cc1);
     return $this->getMax('end_date', $cc);
 }
Example #20
0
 function populate()
 {
     $invoices = new PInvoiceCollection();
     $invoices->setParams();
     $sh = new SearchHandler($invoices, false);
     $sh->addConstraint(new Constraint('status', '=', 'O'));
     $sh->addConstraint(new Constraint('due_date', '<=', fix_date(date(DATE_FORMAT))));
     $this->setSearchLimit($sh);
     $sh->setOrderBy('due_date');
     $invoices->load($sh);
     $this->contents = $invoices;
     // set vars
     $this->vars['type_label'] = 'Supplier';
     $this->vars['type_field'] = 'supplier';
     $this->vars['module'] = 'purchase_invoicing';
     $this->vars['controller'] = 'pinvoices';
 }
Example #21
0
 public static function Factory($data, &$errors)
 {
     $hash = $data['cb_account_id'];
     $hash .= $data['currency_id'];
     $hash .= $data['payment_type_id'];
     $hash .= $data['reference'];
     $hash .= fix_date($data['payment_date']);
     $hash .= $data['number_transactions'];
     $hash .= $data['payment_total'];
     $progressbar = new progressBar('create_security_key');
     $callback = function ($pl_data, $key) use(&$hash, &$errors) {
         $hash .= $pl_data['plmaster_id'];
         $hash .= bcadd($pl_data['net_value'], 0);
     };
     $progressbar->process($data['PLTransaction'], $callback);
     $data['hash_key'] = self::generateHashcode($hash);
     return parent::Factory($data, $errors, 'PLPayment');
 }
Example #22
0
 public function getCurrent($_employee_id, $_payment_type_id, $_start_date, $_end_date = '')
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('employee_id', '=', $_employee_id));
     $cc->add(new Constraint('payment_type_id', '=', $_payment_type_id));
     $db = DB::Instance();
     $cc1 = new ConstraintChain();
     $cc1->add(new Constraint('start_date', 'between', $db->qstr(fix_date($_start_date)) . ' and ' . $db->qstr(empty($_end_date) ? fix_date(date(DATE_FORMAT)) : fix_date($_end_date))));
     $cc2 = new ConstraintChain();
     $cc2->add(new Constraint('start_date', '<', fix_date($_start_date)));
     $cc3 = new ConstraintChain();
     $cc3->add(new Constraint('end_date', '>=', fix_date($_start_date)));
     $cc3->add(new Constraint('end_date', 'is', 'NULL'), 'OR');
     $cc2->add($cc3);
     $cc1->add($cc2, 'OR');
     $cc->add($cc1);
     $this->loadBy($cc);
 }
Example #23
0
 /**
  * @param void
  * @return ConstraintChain
  *
  * Returns a constraintchain containing OR'd constraints for each status checked on the form
  */
 public function toConstraint()
 {
     $cc = false;
     if (!is_array($this->value)) {
         $this->value = array($this->value);
     }
     $cc = new ConstraintChain();
     $codes = $this->value_set ? $this->value : array_flip($this->default);
     $db = DB::Instance();
     $date = fix_date(date(DATE_FORMAT));
     foreach ($codes as $code => $on) {
         if ($code != '') {
             switch ($code) {
                 case 'Raised by me':
                     $cc->add(new Constraint('raised_by', '=', getCurrentUser()->username));
                     break;
                 case 'Other Orders':
                     $cc->add(new Constraint('raised_by', '!=', getCurrentUser()->username), 'OR');
                     break;
                 case 'Authorised by me':
                     $c = new ConstraintChain();
                     $c->add(new Constraint('authorised_by', '=', getCurrentUser()->username));
                     $c->add(new Constraint('date_authorised', 'is not', 'NULL'));
                     $cc->add($c, 'OR');
                     break;
                 case 'Awaiting Authorisation':
                     $awaitingauth = new POAwaitingAuthCollection(new POAwaitingAuth());
                     $authlist = $awaitingauth->getOrderList(getCurrentUser()->username);
                     if (empty($authlist)) {
                         $authlist = '-1';
                     }
                     $c = new ConstraintChain();
                     $c->add(new Constraint('type', '=', 'R'));
                     $c->add(new Constraint('authorised_by', 'is', 'NULL'));
                     $c->add(new Constraint('raised_by', '!=', getCurrentUser()->username));
                     $c->add(new Constraint('id', 'in', '(' . $authlist . ')'));
                     $cc->add($c, 'OR');
                     break;
             }
         }
     }
     return $cc;
 }
Example #24
0
 /**
  * Check the next holiday period start date.
  * 
  * @param	string	the employee id
  * @return	int 	the next holiday period start date
  *
  */
 public function getNextStartDate($_employee_id = '', &$errors = array())
 {
     $employee = DataObjectFactory::Factory('Employee');
     if (empty($_employee_id) && $this->isLoaded()) {
         $_employee_id = $this->employee_id;
     }
     $employee->load($_employee_id);
     if (!$employee->isLoaded()) {
         $errors[] = 'Cannot find employee details';
         return '';
     }
     $cc = new ConstraintChain();
     $cc->add(new Constraint('employee_id', '=', $_employee_id));
     $latest_end_date = $this->getMax('end_date', $cc);
     if (!empty($latest_end_date)) {
         return fix_date(date(DATE_FORMAT, strtotime($latest_end_date . ' +1 day')));
     }
     return $employee->start_date;
 }
Example #25
0
 public function transferStock()
 {
     $flash = Flash::Instance();
     $errors = array();
     $db = DB::Instance();
     $db->StartTrans();
     $whtransfer = new WHTransfer();
     if (isset($this->_data['id'])) {
         $whtransfer->load($this->_data['id']);
     } else {
         $errors[] = 'Select a Transfer Number';
     }
     if ($whtransfer) {
         if ($whtransfer->transfer() && count($errors) == 0) {
             foreach ($whtransfer->transfer_lines as $lines) {
                 $lines->moveStock($whtransfer, $errors);
                 if (count($errors) > 0) {
                     $errors[] = 'Failed to move stock';
                     break;
                 }
             }
             if ($whtransfer->update($whtransfer->id, 'actual_transfer_date', fix_date(date(DATE_FORMAT)))) {
                 $flash->addMessage('Transfer has been completed');
             } else {
                 $errors[] = 'Failed to transfer stock';
             }
         } else {
             $errors[] = 'Failed to transfer stock';
         }
     } else {
         $errors[] = 'Failed to find Transfer details';
     }
     if (count($errors) > 0) {
         $flash->addErrors($errors);
         $db->FailTrans();
         sendTo('WHTransferlines', 'view', $this->_modules, array('id' => $whtransfer->id));
     } else {
         $db->CompleteTrans();
         sendTo($this->name, 'printaction', $this->_modules, array('printaction' => 'printTransferNote', 'filename' => 'WHT' . $whtransfer->transfer_number, 'id' => $whtransfer->id));
     }
     sendTo($this->name, 'selectwhtransfers', $this->_modules);
 }
Example #26
0
 /**
  *  Build the invoice header, as if from a submitted form
  *
  */
 public static function makeHeader($data, $do, &$errors)
 {
     if (!isset($data['id']) || $data['id'] == '') {
         $generator = new UniqueNumberHandler(false, $data['transaction_type'] != 'T');
         $data['invoice_number'] = $generator->handle(DataObjectFactory::Factory($do));
         $data['status'] = 'N';
     }
     //determine the base currency
     $currency = DataObjectFactory::Factory('Currency');
     $currency->load($data['currency_id']);
     $data['rate'] = $currency->rate;
     //determine the twin currency
     $glparams = DataObjectFactory::Factory('GLParams');
     $twin_currency = DataObjectFactory::Factory('Currency');
     $twin_currency->load($glparams->twin_currency());
     $data['twin_rate'] = $twin_currency->rate;
     $data['twin_currency_id'] = $twin_currency->id;
     $terms = DataObjectFactory::Factory('PaymentTerm');
     $terms->load($data['payment_term_id']);
     $today = date(DATE_FORMAT);
     if (empty($data['invoice_date'])) {
         $data['invoice_date'] = $today;
     }
     if ($data['transaction_type'] == 'I') {
         $data['due_date'] = calc_due_date($data['invoice_date'], $terms->basis, $terms->days, $terms->months);
     } else {
         if (fix_date($data['due_date']) < fix_date($today)) {
             $data['due_date'] = $today;
         }
     }
     $data['original_due_date'] = $data['due_date'];
     //		build the lines - header totals are built from the lines
     //		so initialise the values to zero
     $sums = array('net_value', 'tax_value', 'gross_value');
     $prefixes = array('', 'twin_', 'base_');
     foreach ($prefixes as $prefix) {
         foreach ($sums as $sum) {
             $data[$prefix . $sum] = '0.00';
         }
     }
     return DataObject::Factory($data, $errors, $do);
 }
 function getServiceHistory()
 {
     $enddate = fix_date('01/' . date('m/Y'));
     $startdate = fix_date(date(DATE_FORMAT, strtotime("-12 months", strtotime($enddate))));
     $enddate = fix_date(date(DATE_FORMAT));
     $this->_tablename = 'customer_service_summary';
     $sh = new SearchHandler($this, FALSE);
     $sh->addConstraint(new Constraint('despatch_date', 'between', "'" . $startdate . "' and '" . $enddate . "'"));
     $sh->setFields(array('year_month', 'sum(ontime) as ontime', 'sum(infull) as infull', 'sum(otif) as otif', 'sum(count) as count'));
     $sh->setGroupBy("year_month");
     $sh->setOrderBy("year_month");
     $this->load($sh);
     for ($i = 0; $i < 13; $i++) {
         $date = date('Y/m', strtotime("+" . $i . " months", strtotime($startdate)));
         $this->customerorders['previous'][$date]['ontime'] = 0;
         $this->customerorders['previous'][$date]['infull'] = 0;
         $this->customerorders['previous'][$date]['ontime_infull'] = 0;
         $this->customerorders['previous'][$date]['count'] = 0;
     }
     foreach ($this as $despatch) {
         if (isset($this->customerorders['previous'][$despatch->id])) {
             $this->customerorders['previous'][$despatch->id]['ontime'] = $despatch->ontime;
             $this->customerorders['previous'][$despatch->id]['infull'] = $despatch->infull;
             $this->customerorders['previous'][$despatch->id]['ontime_infull'] = $despatch->otif;
             $this->customerorders['previous'][$despatch->id]['count'] = $despatch->count;
         }
     }
     foreach ($this->customerorders['previous'] as $date => $month) {
         if ($month['count'] == 0) {
             $this->customerorders['previous'][$date]['ontime%'] = 0;
             $this->customerorders['previous'][$date]['infull%'] = 0;
             $this->customerorders['previous'][$date]['ontime_infull%'] = 0;
         } else {
             $this->customerorders['previous'][$date]['ontime%'] = $month['ontime'] * 100 / $month['count'];
             $this->customerorders['previous'][$date]['infull%'] = $month['infull'] * 100 / $month['count'];
             $this->customerorders['previous'][$date]['ontime_infull%'] = $month['ontime_infull'] * 100 / $month['count'];
         }
     }
     return $this->customerorders;
 }
 function getReceivedSum($months)
 {
     $startdate = fix_date('01/' . date('m/Y'));
     $startdate = strtotime($startdate);
     $startdate = fix_date(date(DATE_FORMAT, strtotime("-3 months", $startdate)));
     $sh = new SearchHandler($this, false);
     $sh->addConstraint(new Constraint('received_date', '>=', $startdate));
     $this->load($sh);
     $receivedSum = array();
     foreach ($this as $received) {
         $period = date('M Y', strtotime($received->received_date));
         if (isset($receivedSum[$period])) {
             $receivedSum[$period] += $received->net_value;
         } else {
             $receivedSum[$period] = $received->net_value;
         }
     }
     foreach ($receivedSum as $key => $value) {
         $receivedSum[$key] = sprintf('%0.2f', $value);
     }
     return $receivedSum;
 }
Example #29
0
 function populate()
 {
     $orderline = DataObjectFactory::Factory('SOrderLine');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('status', 'in', "('N', 'S', 'R', 'P')"));
     $cc->add(new Constraint('due_despatch_date', '<', fix_date(date(DATE_FORMAT))));
     $order_total = $orderline->getSum('base_net_value', $cc);
     $orders = new SOrderLineCollection($orderline);
     $orders->setParams();
     $sh = new SearchHandler($orders, FALSE);
     $fields = array('order_id', 'order_number', 'customer', 'order_date', 'due_despatch_date');
     $sh->setGroupBy($fields);
     $sh->setOrderBy(array('due_despatch_date', 'order_number', 'customer'));
     $fields[] = 'sum(base_net_value) as base_net_value';
     $sh->setFields($fields);
     $sh->addConstraintChain($cc);
     $this->setSearchLimit($sh);
     $orders->load($sh);
     $orders->collection_date_label = 'due_despatch_date';
     $orders->collection_total_label = 'Total (Base Net Value) Order Lines Overdue';
     $orders->collection_total = $order_total;
     $this->contents = $orders;
 }
 public function make_refund()
 {
     if (!$this->loadData()) {
         $this->dataError('Unable to load transaction');
         sendBack();
     }
     $transaction = $this->_uses[$this->modeltype];
     $transaction->transaction_date = fix_date(date(DATE_FORMAT));
     if ($transaction->net_value < 0) {
         $transaction->net_value = bcmul($transaction->net_value, -1);
         $transaction->tax_value = bcmul($transaction->tax_value, -1);
         $transaction->gross_value = bcmul($transaction->gross_value, -1);
     }
     $this->view->set('page_title', 'Make Cash Book ' . $transaction->getFormatted('type') . ' Refund');
     $transaction->type = 'R' . $transaction->type;
     $transaction->description = 'Refund for ref: ' . $transaction->reference;
     $gltransaction = DataObjectFactory::Factory('GLTransaction');
     $gltransaction->loadBy('docref', $transaction->reference);
     $gltransaction->orderby = $gltransaction->idField;
     $this->_data['glaccount_id'] = $gltransaction->glaccount_id;
     $this->payments();
     $this->view->set('glaccount_id', $gltransaction->glaccount_id);
     $this->view->set('glcentre_id', $gltransaction->glcentre_id);
 }