public function fetchAllBhistories($planId,$status)
	{
		$resultSet = $this->getDbTable()->fetchAllBhistories($planId,$status);

		$arrayBhistories = null;
		foreach ($resultSet as $row)
		{
			$bhistory = new Pment_Models_Bhistory();
			$bhistory->setContactId($row->contactId);
			$bhistory->setContactName($row->contactName);
			$bhistory->setEditDate($row->editDate);
			$bhistory->setHiId($row->hiId);
			$bhistory->setStatus($row->status);
			$bhistory->setEditType($row->editType);
			$arrayBhistories[] = $bhistory;
			}
		return $arrayBhistories;
	}
	public function mfinalAction()
	{
		$userId = $this->getUserId();
		$groupId = $this->getGroupId();
		if($groupId != 5) 
		{
			$this->_redirect('/pment/mplan');
			}
		$id = $this->_getParam('id',0);
		
		if($id > 0)
		{
			//display plan info
			$mplans = new Pment_Models_MplanMapper();
			$mplan = new Pment_Models_Mplan();
			$errorMsg = null;
			$mplans->find($id,$mplan);
			$materials = new Pment_Models_MaterialMapper();
			$condition = "planId";
			$arrayMaterials = $materials->fetchAllOrganize($id,$condition);
			//load history of modification
			$bhistories = new Pment_Models_BhistoryMapper();
			$arrayBhistories = $bhistories->fetchAllBhistories($id,1);
			
			//load reviewers info
			$reviewers = new Pment_Models_ReviewerMapper();
			$arrayReviewers = $reviewers->fetchAllNames($id);
			
			if($this->getRequest()->isPost())
			{
				$redirect = true;
				$formData = $this->getRequest()->getPost();
				$array = $materials->mfinalValidator($formData);
				$trigger = $array['trigger'];
				$errorMsg = $array['errorMsg'];
				if($trigger == 0)
				{
					$arrayMtrIds = $materials->fetchArryMtrIds($id);
					foreach($arrayMtrIds as $mtrId)
					{
						$material = new Pment_Models_Material();
						$materials->find($mtrId,$material);
						$material->setVendorName($formData['vendorName_'.$mtrId]);
						$material->setAmountf($formData['amountf_'.$mtrId]);
						$material->setCost($formData['cost_'.$mtrId]);
						$material->setCostTotal($formData['costTotal_'.$mtrId]);
						$materials->save($material);
						}
					$bhistory = new Pment_Models_Bhistory();
					$bhistory->setPlanId($id);
					$bhistory->setStatus(1);
					$userId = $this->getUserId();
					$users = new System_Models_UserMapper();
					$contactId = $users->getContactId($userId);
					$bhistory->setContactId($contactId);
					$bhistory->setEditDate(date('Y-m-d,H:i'));
					$bhistory->setEditType('添加采购信息');
					$bhistories->save($bhistory);
					$message = General_Models_Text::$text_mplan_mfinal_sucess;
					$this->_helper->flashMessenger->addMessage($message);
					$this->_redirect('/pment/mplan/mindex');
					}
				}
			$this->view->errorMsg = $errorMsg;
			$this->view->mplan = $mplan;
			$this->view->arrayReviewers = $arrayReviewers;
			$this->view->id = $id;
			$this->view->modelName = "材料部材料计划信息"; 
			$this->view->arrayBhistories = $arrayBhistories;
			//display material info
			$this->view->arrayMaterials = $arrayMaterials;
			}
			else
			{
				$this->_redirect('/pment/mplan');
				}
		}