Exemplo n.º 1
0
 public function generatepurchaseorderAction()
 {
     $id = $this->_getParam('id', 0);
     $quoteDb = new Sales_Model_DbTable_Quote();
     $data = $quoteDb->getQuote($id);
     unset($data['id'], $data['quoteid'], $data['quotedate']);
     $data['purchaseorderdate'] = '0000-00-00';
     $data['billingname1'] = '';
     $data['billingname2'] = '';
     $data['billingdepartment'] = '';
     $data['billingstreet'] = '';
     $data['billingpostcode'] = '';
     $data['billingcity'] = '';
     $data['billingcountry'] = '';
     if (!$data['shippingname1']) {
         $data['shippingname1'] = $data['billingname1'];
         $data['shippingname2'] = $data['billingname2'];
         $data['shippingdepartment'] = $data['billingdepartment'];
         $data['shippingstreet'] = $data['billingstreet'];
         $data['shippingpostcode'] = $data['billingpostcode'];
         $data['shippingcity'] = $data['billingcity'];
         $data['shippingcountry'] = $data['billingcountry'];
         $data['shippingphone'] = '';
     }
     $data['state'] = 100;
     $data['created'] = $this->_date;
     $data['createdby'] = $this->_user['id'];
     $data['modified'] = '0000-00-00';
     $data['modifiedby'] = 0;
     $data['clientid'] = $this->_user['clientid'];
     $purchaseorder = new Purchases_Model_DbTable_Purchaseorder();
     $purchaseorderid = $purchaseorder->addPurchaseorder($data);
     $positions = $this->getPositions($id);
     $positionsPurchaseorderDb = new Purchases_Model_DbTable_Purchaseorderpos();
     foreach ($positions as $position) {
         $dataPosition = $position->toArray();
         $dataPosition['purchaseorderid'] = $purchaseorderid;
         $dataPosition['created'] = $this->_date;
         $dataPosition['createdby'] = $this->_user['id'];
         $dataPosition['modified'] = '0000-00-00';
         $dataPosition['modifiedby'] = 0;
         unset($dataPosition['id'], $dataPosition['quoteid']);
         $positionsPurchaseorderDb->addPosition($dataPosition);
     }
     //Add document relation
     $documentrelationDb = new Application_Model_DbTable_Documentrelation();
     $documentrelationDb->addDocumentrelation($data['contactid'], $purchaseorderid, "purchases", "purchaseorder", $this->_date, $this->_user['id']);
     $this->_flashMessenger->addMessage('MESSAGES_PURCHASE_ORDER_SUCCESFULLY_GENERATED');
     $this->_helper->redirector->gotoSimple('edit', 'purchaseorder', 'purchases', array('id' => $purchaseorderid));
 }