public function commitAccountingAction() { $data = Zend_Json::decode($this->_getParam('data')); $project_id = Zend_Filter_Digits::filter($data["project_id"]); //Used to determine if billing items changed, prompted later below. $projectinfo_orig = Application_Model_Projects::GetProjectInfo($project_id); $data["project_id"] = $project_id; ProNav_Utils::WhiteListArray($data, array('project_id', 'bill_type', 'po_amount', 'po_date', 'schedule_estimated_start', 'schedule_estimated_end', 'acct_project_value', 'acct_invoice_type', 'acct_ocip', 'id', 'acct_retainage', 'acct_prevailing_wage', 'acct_tax_exempt', 'acct_cert_of_ins_req', 'acct_performance_bond_req', 'acct_permit_req', 'acct_project_type', 'acct_billed_to_date', 'acct_estimated_cost', 'acct_comment', 'po_number', 'job_no', 'acct_project_manager', 'acct_project_engineer', 'acct_field_staff_leader', 'acct_billing_date', 'acct_billing_address1', 'acct_billing_address2', 'acct_billing_city', 'acct_billing_state', 'acct_billing_zip', 'acct_billing_contact', 'acct_billing_phone', 'acct_billing_notes')); $data = ProNav_Utils::stripTagsAndTrim($data); $data["bill_type"] = is_numeric($data["bill_type"]) ? $data["bill_type"] : -1; $data["po_amount"] = ProNav_Utils::stripFormattedNumbers($data["po_amount"]); $data["po_date"] = ProNav_Utils::toMySQLDate($data["po_date"]); $data["acct_project_value"] = ProNav_Utils::stripFormattedNumbers($data["acct_project_value"]); $data["acct_invoice_type"] = is_numeric($data["acct_invoice_type"]) ? $data["acct_invoice_type"] : -1; $data["acct_prevailing_wage"] = $data["acct_prevailing_wage"] == 1 ? 1 : 0; $data["acct_tax_exempt"] = $data["acct_tax_exempt"] == 1 ? 1 : 0; $data["acct_ocip"] = $data["acct_ocip"] == 1 ? 1 : 0; $data["acct_cert_of_ins_req"] = $data["acct_cert_of_ins_req"] == 1 ? 1 : 0; $data["acct_performance_bond_req"] = $data["acct_performance_bond_req"] == 1 ? 1 : 0; $data["acct_permit_req"] = $data["acct_permit_req"] == 1 ? 1 : 0; $data["acct_project_type"] = is_numeric($data["acct_project_type"]) ? $data["acct_project_type"] : 1; $data["acct_billed_to_date"] = ProNav_Utils::stripFormattedNumbers($data["acct_billed_to_date"]); $data["acct_estimated_cost"] = ProNav_Utils::stripFormattedNumbers($data["acct_estimated_cost"]); $data["acct_project_manager"] = is_numeric($data["acct_project_manager"]) ? $data["acct_project_manager"] : null; $data["acct_project_engineer"] = is_numeric($data["acct_project_engineer"]) ? $data["acct_project_engineer"] : null; $data["acct_field_staff_leader"] = is_numeric($data["acct_field_staff_leader"]) ? $data["acct_field_staff_leader"] : null; $data['acct_billing_date'] = $data['acct_billing_date'] && is_numeric($data['acct_billing_date']) ? $data['acct_billing_date'] : null; $data["acct_billing_state"] = is_numeric($data["acct_billing_state"]) ? $data["acct_billing_state"] : null; $data['schedule_estimated_start'] = ProNav_Utils::toMySQLDate($data['schedule_estimated_start'], false); $data['schedule_estimated_end'] = ProNav_Utils::toMySQLDate($data['schedule_estimated_end'], false); ProNav_Utils::scrubArray($data, true, false); $data["acct_modified_by"] = ProNav_Auth::getUserID(); $data["acct_modified_date"] = new Zend_Db_Expr("NOW()"); $result = Application_Model_Projects::updateProject($data); //The updated project data. $projectinfo = Application_Model_Projects::GetProjectInfo($project_id); $cors = Application_Model_ChangeOrders::getRequestsForProject($project_id, true, true); $executed_cors = array(); foreach ($cors as $cor) { if ($cor->accounting_stage_id == Application_Model_ChangeOrderRequest::ACCT_EXECUTED) { $executed_cors[] = $cor; } } $jOut = array(); if (!$result) { $jOut['status'] = 0; } else { $jOut['status'] = 1; $jOut['accounting'] = $this->view->partial('project/accounting.phtml', array('projectinfo' => $projectinfo)); $jOut['general'] = $this->view->partial('project/partial-general-info.phtml', array('projectinfo' => $projectinfo, 'open_projects' => Application_Model_Projects::OpenProjectsCountAtLocation($projectinfo->done_at_location, $project_id), 'active_projects' => Application_Model_Projects::ActiveProjectsCountAtLocation($projectinfo->done_at_location, $project_id))); $jOut['value'] = $this->view->partial('project/partial-project-value.phtml', array('base_project' => $projectinfo, 'original_contract_value' => $projectinfo->getProjectValue(), 'has_executed_cos' => count($executed_cors), 'executed_cos_value' => Application_Model_ChangeOrders::sumProjectValue($executed_cors), 'total_contract_value' => Application_Model_ChangeOrders::sumProjectValue($executed_cors, $projectinfo))); //Determine if you should prompt the user to update the corp billing info. if (ProNav_Auth::hasPerm(ProNav_Auth::PERM_CORPORATIONS_ADD_EDIT)) { $fields_to_update = $this->getEligibleBillingFieldsForCorpUpdate($data, $projectinfo_orig, $projectinfo); if (count($fields_to_update) > 0) { $jOut['offer_save_billing'] = Zend_Json::encode($fields_to_update); } } } echo Zend_Json_Encoder::encode($jOut); }