Beispiel #1
0
 public function hasCurrentActivity()
 {
     $db = DB::Instance();
     // Check that no orders/invoices have been raised
     $model = DataObjectFactory::Factory('SOrder');
     $collection = new SOrderCollection($model);
     $sh = new SearchHandler($collection, FALSE);
     $sh->addConstraint(new Constraint('slmaster_id', '=', $this->id));
     $sh->addConstraint(new Constraint('status', 'NOT IN', '(' . $db->qstr($model->cancelStatus()) . ', ' . $db->qstr($model->invoiceStatus()) . ')'));
     if (count($collection->load($sh, null, RETURN_ROWS)) > 0) {
         return TRUE;
     }
     $model = DataObjectFactory::Factory('SInvoice');
     $collection = new SInvoiceCollection($model);
     $sh = new SearchHandler($collection, FALSE);
     $sh->addConstraint(new Constraint('slmaster_id', '=', $this->id));
     $sh->addConstraint(new Constraint('status', '!=', $model->paidStatus()));
     if (count($collection->load($sh, null, RETURN_ROWS)) > 0) {
         return TRUE;
     }
     $model = DataObjectFactory::Factory('SLTransaction');
     $collection = new SLTransactionCollection($model);
     $sh = new SearchHandler($collection, FALSE);
     $sh->addConstraint(new Constraint('slmaster_id', '=', $this->id));
     $sh->addConstraint(new Constraint('status', '!=', $model->paid()));
     if (count($collection->load($sh, null, RETURN_ROWS)) > 0) {
         return TRUE;
     }
     return FALSE;
 }
 public function viewByOrders()
 {
     $cc = new ConstraintChain();
     if (isset($this->_data['id'])) {
         $id = $this->_data['id'];
         $cc->add(new Constraint('stitem_id', '=', $id));
     } elseif (isset($this->_data['order_id'])) {
         $order_id = $this->_data['order_id'];
         $cc->add(new Constraint('order_id', '=', $order_id));
     } else {
         $cc->add(new Constraint('type', '=', 'O'));
     }
     $cc->add(new Constraint('status', '=', 'R'));
     $order = new SOrderCollection();
     $order->orderby = array('delivery_note', 'order_number', 'line_number');
     $order->direction = array('ASC', 'ASC', 'ASC');
     $orders = $order->getItemOrders($cc);
     // Create an array of items ordered
     $stitems = array();
     foreach ($orders as $row) {
         $stitems[$row->stitem_id]['in_stock'] = 0;
         if (!isset($stitems[$row->stitem_id]['despatch_action'][$row->despatch_action])) {
             $transferrules = new WHTransferruleCollection(DataObjectFactory::Factory('WHTransferrule'));
             $locations = $transferrules->getFromLocations($row->despatch_action);
             if (count($locations) > 0 and $row->stitem_id) {
                 // Should never be zero or somethingis very wrong!
                 $cc = new ConstraintChain();
                 $cc->add(new Constraint('stitem_id', '=', $row->stitem_id));
                 $cc->add(new Constraint('whlocation_id', 'in', '(' . implode(',', array_keys($locations)) . ')'));
                 $stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] = STBalance::getBalances($cc);
             } else {
                 $stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] = 0;
                 // Flag it as a non-stock item
                 $stitems[$row->stitem_id]['non-stock'] = true;
             }
         }
     }
     // And check orders for stock availability
     // Items not available cannot be despatched!
     $items = array();
     foreach ($orders as $key => $row) {
         // Exclude any order lines that cannot be fulfilled
         // or have already been despatched
         $stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] -= $row->required;
         $sorder = DataObjectFactory::Factory('SOrder');
         $sorder->load($row->order_id);
         $items[$row->order_number]['order_number'] = $row->order_number;
         $items[$row->order_number]['order_id'] = $row->order_id;
         $items[$row->order_number]['customer'] = $row->customer;
         $items[$row->order_number]['del_address'] = $sorder->del_address->address;
         if ($stitems[$row->stitem_id]['non-stock']) {
             $items[$row->order_number]['line_number'][$row->line_number]['despatch'] = true;
         } elseif ($stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] >= 0) {
             $items[$row->order_number]['line_number'][$row->line_number]['despatch'] = true;
         } else {
             $items[$row->order_number]['line_number'][$row->line_number]['despatch'] = false;
         }
         $items[$row->order_number]['line_number'][$row->line_number]['despatch_action'] = $row->despatch_action;
         $items[$row->order_number]['due_despatch_date'] = $row->due_despatch_date;
         $items[$row->order_number]['line_number'][$row->line_number]['stitem'] = $row->stitem;
         $items[$row->order_number]['line_number'][$row->line_number]['item_description'] = $row->item_description;
         $items[$row->order_number]['line_number'][$row->line_number]['delivery_note'] = $row->delivery_note;
         $items[$row->order_number]['line_number'][$row->line_number]['required'] = $row->required;
         $items[$row->order_number]['line_number'][$row->line_number]['stuom'] = $row->stuom;
         $items[$row->order_number]['line_number'][$row->line_number]['id'] = $row->id;
     }
     $this->view->set('orders', $items);
     $sidebar = new SidebarController($this->view);
     $actions = array();
     $actions['viewnotes'] = array('link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'index')), 'tag' => 'view despatch notes');
     $sidebar->addList('Actions', $actions);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $this->view->set('page_title', $this->getPageName('Despatch', 'View Order Lines for'));
 }
 public function view_orders()
 {
     if (isset($this->_data['Search']['productline_header_id'])) {
         $this->_data['id'] = $this->_data['Search']['productline_header_id'];
     }
     if (!isset($this->_data['id'])) {
         $this->DataError();
         sendBack();
     }
     $s_data = array();
     // Set context from calling module
     $s_data['productline_header_id'] = $this->_data['id'];
     $this->setSearch('productlinesSearch', 'customerOrders', $s_data);
     $this->view();
     // Now load the required data
     $orders = new SOrderCollection();
     $orders->setViewName('so_product_orders');
     $sh = $this->setSearchHandler($orders);
     parent::index($orders, $sh);
     $this->view->set('clickcontroller', 'sorders');
     $this->view->set('clickaction', 'view');
     $this->view->set('related_collection', $orders);
     $this->setTemplateName('view_related');
 }
Beispiel #4
0
 public function printOrderList($status = 'generate')
 {
     // this function is very extensive, and thus we'll remove the max_execution_time
     set_time_limit(0);
     // build options array
     $options = array('type' => array('pdf' => '', 'xml' => ''), 'output' => array('print' => '', 'save' => '', 'email' => '', 'view' => ''), 'filename' => 'SOrderList' . fix_date(date(DATE_FORMAT)), 'report' => 'SalesOrderList');
     if (strtolower($status) == "dialog") {
         return $options;
     }
     // load the model
     $orders = new SOrderCollection($this->_templateobject);
     $sh = new SearchHandler($orders, false);
     $sh->addConstraint(new Constraint('status', '=', $this->_templateobject->newStatus()));
     $orders->load($sh);
     // build extra array
     $extra = array('title' => prettify($title) . ' Sales Orders as at ' . un_fix_date(fix_date(date(DATE_FORMAT))), 'showlines' => true);
     // generate the xml and add it to the options array
     $options['xmlSource'] = $this->generateXML(array('model' => $orders, 'extra' => $extra, 'relationship_whitelist' => array('lines')));
     // execute the print output function, echo the returned json for jquery
     echo $this->constructOutput($this->_data['print'], $options);
     exit;
 }