public function createHostedScalrAccountCostCenter(Scalr_Account $account, Scalr_Account_User $user = null)
{
if (!$user instanceof Scalr_Account_User) {
$user = $account->getOwner();
}
//New Cost Center should be created in account share mode
$cc = new CostCentreEntity();
$cc->ccId = \Scalr::GenerateUID();
$cc->accountId = $account->id;
$cc->createdByEmail = $user->getEmail();
$cc->name = "Cost Center " . $account->name . " (" . $account->id . ")";
$cc->createdById = $user->id;
$cc->save();
$cc->saveProperty(CostCentrePropertyEntity::NAME_BILLING_CODE, "CC-" . $account->name);
$cc->saveProperty(CostCentrePropertyEntity::NAME_DESCRIPTION, "This Cost Center was added automatically.");
$cc->saveProperty(CostCentrePropertyEntity::NAME_LEAD_EMAIL, $user->getEmail());
$cc->saveProperty(CostCentrePropertyEntity::NAME_LOCKED, false);
//A new Project which corresponds to Cost Center (in account share mode as well)
$project = new ProjectEntity();
$project->projectId = \Scalr::GenerateUID();
$project->ccId = $cc->ccId;
$project->name = "Project " . $account->name . " (" . $account->id . ")";
$project->accountId = $account->id;
$project->createdByEmail = $user->getEmail();
$project->shared = ProjectEntity::SHARED_WITHIN_ACCOUNT;
$project->createdById = $user->id;
$project->save();
$project->saveProperty(ProjectPropertyEntity::NAME_BILLING_CODE, "PR-" . $account->name);
$project->saveProperty(ProjectPropertyEntity::NAME_DESCRIPTION, "This Project was added automatically.");
$project->saveProperty(ProjectPropertyEntity::NAME_LEAD_EMAIL, $user->getEmail());
if (\Scalr::getContainer()->analytics->enabled) {
\Scalr::getContainer()->analytics->tags->syncValue($account->id, TagEntity::TAG_ID_COST_CENTRE, $cc->ccId, $cc->name);
\Scalr::getContainer()->analytics->tags->syncValue($account->id, TagEntity::TAG_ID_PROJECT, $project->projectId, $project->name);
}
return $cc;
}