예제 #1
0
 public function _new()
 {
     $flash = Flash::Instance();
     parent::_new();
     // Get the Order Line Object - if loaded, this is an edit
     $porderline = $this->_uses[$this->modeltype];
     if (!$porderline->isLoaded()) {
         if (empty($this->_data['order_id'])) {
             $flash->addError('No Purchase Order supplied');
             sendBack();
         }
         $porderline->order_id = $this->_data['order_id'];
         $porderline->status = $porderline->newStatus();
     }
     $porder = DataObjectFactory::Factory('POrder');
     $porder->load($porderline->order_id);
     $_plmaster_id = $porder->plmaster_id;
     if (isset($this->_data[$this->modeltype])) {
         // We've had an error so refresh the page
         $_plmaster_id = $this->_data['POrder']['plmaster_id'];
         $porderline->line_number = $this->_data[$this->modeltype]['line_number'];
         $_product_search = $this->_data[$this->modeltype]['product_search'];
         if (!empty($this->_data[$this->modeltype]['productline_id'])) {
             $_productline_id = $this->_data[$this->modeltype]['productline_id'];
         } else {
             $_productline_id = '';
         }
         $_glaccount_id = $this->_data[$this->modeltype]['glaccount_id'];
     } elseif ($porderline->isLoaded()) {
         //			$_product_search=$porderline->description;
         $_productline_id = $porderline->productline_id;
         $_glaccount_id = $porderline->glaccount_id;
     } else {
         $_product_search = 'None';
         $porderline->due_despatch_date = $porder->despatch_date;
         $porderline->due_delivery_date = $porder->due_date;
     }
     if ($porderline->lineAwaitingDelivery()) {
         $porderlines = new POrderLineCollection();
         $porderlines->getAuthSummary($porder->id);
         if (EGS_USERNAME == $porder->checkAuthLimits($porderlines)) {
             $this->view->set('amend_qty', true);
         }
     }
     $display_fields = $porderline->getDisplayFields();
     if (empty($_productline_id) && isset($display_fields['product_search'])) {
         if ($_product_search == 'None') {
             $productline_options = array('' => 'None');
         } else {
             $productline_options = $this->getProductLines($_plmaster_id, $_product_search);
         }
     } else {
         $productline_options = $this->getProductLines($_plmaster_id);
     }
     if (empty($_productline_id)) {
         $_productline_id = key($productline_options);
     }
     $this->view->set('display_fields', $display_fields);
     $this->view->set('product_search', $_product_search);
     $this->view->set('productline_options', $productline_options);
     $data = $this->getProductLineData($_productline_id);
     $this->view->set('stuom_options', $data['stuom_id']);
     $this->view->set('glaccount_options', $data['glaccount_id']);
     if (empty($_glaccount_id)) {
         $_glaccount_id = key($data['glaccount_id']);
     }
     $this->view->set('glcentre_options', $this->getCentre($_glaccount_id, $_productline_id));
     $this->view->set('taxrate_options', $data['tax_rate_id']);
     $this->view->set('porder', $porder);
 }
예제 #2
0
파일: POrder.php 프로젝트: uzerpllp/uzerp
 public function save(&$errors = array())
 {
     // use_sorder_delivery == true makes no sense if a sales order link is not selected
     if (!$this->sales_order_id) {
         $this->use_sorder_delivery = 'f';
     }
     $linestatuses = $this->getLineStatuses();
     $linestatus = $linestatuses['count'];
     if (($this->someLinesReceived($linestatus) || $this->someLinesInvoiced($linestatus)) && !$this->allLinesReceivedOrInvoiced($linestatus)) {
         $this->status = $this->partReceivedStatus();
     } elseif ($this->allLinesCancelled($linestatus)) {
         $this->status = $this->cancelStatus();
     } elseif ($this->allLinesReceived($linestatus) || $this->allLinesReceivedOrInvoiced($linestatus) && !$this->allLinesInvoiced($linestatus)) {
         $this->status = $this->receivedStatus();
     } elseif ($this->allLinesInvoiced($linestatus)) {
         $this->status = $this->invoiceStatus();
     } elseif ($this->allLinesAwaitingDelivery($linestatus) && $this->status != $this->acknowledgedStatus()) {
         $this->status = $this->orderSentStatus();
     } elseif ($this->allLinesNew($linestatus)) {
         $this->status = $this->newStatus();
     }
     $prev_net_value = $this->base_net_value;
     $po_line = DataObjectFactory::Factory('POrderLine');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('order_id', '=', $this->id));
     $cc->add(new Constraint('status', '!=', $po_line->cancelStatus()));
     $totals = $po_line->getSumFields(array('net_value', 'twin_net_value', 'base_net_value'), $cc, 'po_lines');
     unset($totals['numrows']);
     // set the correct totals back to the order header
     foreach ($totals as $field => $value) {
         $this->{$field} = bcadd($value, 0);
     }
     // Check the authorisation limits on the order
     if ($this->type != 'T' && $prev_net_value != $this->base_net_value) {
         $porderlines_summary = new POrderLineCollection($po_line);
         $porderlines_summary->getAuthSummary($this->id);
         $this->authorised_by = $this->checkAuthLimits($porderlines_summary);
         if (!is_null($this->authorised_by) && EGS_USERNAME == $this->authorised_by && $this->base_net_value > 0 && $porderlines_summary->count() > 0) {
             $this->type = 'O';
             $this->date_authorised = date(DATE_FORMAT);
         } elseif ($this->type == 'O') {
             $this->type = 'R';
             $this->authorised_by = $this->date_authorised = null;
             $awaitingauth = new POAwaitingAuthCollection();
             $awaitingauth->loadBy(null, $this->id);
             $awaitingauth->deleteAll();
             $result = $this->saveAuthList($porderlines_summary, $errors);
         }
     }
     $db = DB::Instance();
     $db->StartTrans();
     $result = parent::save();
     if (!$result) {
         $errors[] = 'Error saving order header : ' . $db->errorMsg();
         $db->FailTrans();
     }
     $db->CompleteTrans();
     return $result;
 }