protected function setOrdering($processid)
 {
     $i = 1;
     $positions = $this->getPositions($processid);
     foreach ($positions as $position) {
         if ($position->ordering != $i) {
             if (!isset($positionsDb)) {
                 $positionsDb = new Processes_Model_DbTable_Processpos();
             }
             $positionsDb->sortPosition($position->id, $i);
         }
         ++$i;
     }
 }
 public function generateprocessAction()
 {
     $id = $this->_getParam('id', 0);
     $salesorderDb = new Sales_Model_DbTable_Salesorder();
     $salesorder = $salesorderDb->getSalesorder($id);
     $data = array();
     $form = new Processes_Form_Process();
     $elements = $form->getElements();
     foreach ($elements as $key => $value) {
         if (isset($salesorder[$key])) {
             $data[$key] = $salesorder[$key];
         }
     }
     $data['subtotal'] = $salesorder['subtotal'];
     $data['taxes'] = $salesorder['taxes'];
     $data['total'] = $salesorder['total'];
     $data['customerid'] = $salesorder['contactid'];
     $data['deliverystatus'] = 'deliveryIsWaiting';
     $data['supplierorderstatus'] = 'supplierNotOrdered';
     $data['paymentstatus'] = 'waitingForPayment';
     $data['state'] = 100;
     $data['completed'] = 0;
     $data['cancelled'] = 0;
     $data["created"] = $this->_date;
     $data["createdby"] = $this->_user['id'];
     $data["modified"] = "0000-00-00";
     $data["modifiedby"] = 0;
     unset($data["id"]);
     $process = new Processes_Model_DbTable_Process();
     $processID = $process->addProcess($data);
     $positions = $this->getPositions($id);
     $processposDb = new Processes_Model_DbTable_Processpos();
     foreach ($positions as $position) {
         $positionData = array();
         $positionForm = new Processes_Form_Processpos();
         $positionElements = $positionForm->getElements();
         foreach ($positionElements as $key => $value) {
             if (isset($position->{$key})) {
                 $positionData[$key] = $position->{$key};
             }
         }
         $positionData['processid'] = $processID;
         $positionData['taxrate'] = $position->taxrate;
         $positionData['deliverystatus'] = 'deliveryIsWaiting';
         $positionData['supplierorderstatus'] = 'supplierNotOrdered';
         $positionData["created"] = $this->_date;
         $positionData["createdby"] = $this->_user['id'];
         $positionData["modified"] = "0000-00-00";
         $positionData["modifiedby"] = 0;
         unset($positionData['id']);
         $processposDb->addPosition($positionData);
     }
     $this->_flashMessenger->addMessage('MESSAGES_PROCESS_SUCCESFULLY_GENERATED');
     $this->_helper->redirector->gotoSimple('index', 'process', 'processes');
 }
Exemple #3
0
 protected function getPositions($processIDs)
 {
     $positions = array();
     if (!empty($processIDs)) {
         $positionsDb = new Processes_Model_DbTable_Processpos();
         $positionsObject = $positionsDb->fetchAll($positionsDb->select()->where('processid IN (?)', $processIDs)->order('ordering'));
         foreach ($positionsObject as $position) {
             if (!isset($previous[$position->processid])) {
                 $previous[$position->processid] = array();
                 $previous[$position->processid]['ordering'] = 0;
                 $previous[$position->processid]['quantity'] = 1;
                 $previous[$position->processid]['deliverystatus'] = '';
                 $previous[$position->processid]['deliverydate'] = '0000-00-00';
                 $previous[$position->processid]['supplierorderstatus'] = '';
             }
             if ($previous[$position->processid]['ordering'] && $previous[$position->processid]['deliverystatus'] == $position->deliverystatus && $previous[$position->processid]['deliverydate'] == $position->deliverydate && $previous[$position->processid]['supplierorderstatus'] == $position->supplierorderstatus) {
                 $positions[$position->processid][$position->ordering] = $positions[$position->processid][$previous[$position->processid]['ordering']];
                 $positions[$position->processid][$position->ordering]['quantity'] = $previous[$position->processid]['quantity'] + 1;
                 unset($positions[$position->processid][$previous[$position->processid]['ordering']]);
                 $previous[$position->processid]['ordering'] = $position->ordering ? $position->ordering : 0;
                 $previous[$position->processid]['quantity'] = $positions[$position->processid][$position->ordering]['quantity'];
                 $previous[$position->processid]['deliverystatus'] = $position->deliverystatus ? $position->deliverystatus : '';
                 $previous[$position->processid]['deliverydate'] = $position->deliverydate ? $position->deliverydate : '0000-00-00';
                 $previous[$position->processid]['supplierorderstatus'] = $position->supplierorderstatus ? $position->supplierorderstatus : '';
             } else {
                 $positions[$position->processid][$position->ordering]['deliverystatus'] = $position->deliverystatus;
                 if ($position->deliverydate != '0000-00-00') {
                     $positions[$position->processid][$position->ordering]['deliverydate'] = $position->deliverydate;
                 }
                 if ($position->itemtype == 'deliveryItem') {
                     $positions[$position->processid][$position->ordering]['supplierorderstatus'] = $position->supplierorderstatus;
                 }
                 $previous[$position->processid] = array();
                 $previous[$position->processid]['ordering'] = $position->ordering ? $position->ordering : 0;
                 $previous[$position->processid]['quantity'] = 1;
                 $previous[$position->processid]['deliverystatus'] = $position->deliverystatus ? $position->deliverystatus : '';
                 $previous[$position->processid]['deliverydate'] = $position->deliverydate ? $position->deliverydate : '0000-00-00';
                 $previous[$position->processid]['supplierorderstatus'] = $position->supplierorderstatus ? $position->supplierorderstatus : '';
             }
         }
     }
     return $positions;
 }