本文整理汇总了PHP中Illuminate\Database\DatabaseManager::transaction方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseManager::transaction方法的具体用法?PHP DatabaseManager::transaction怎么用?PHP DatabaseManager::transaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager::transaction方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create a new topic
*
* @param array $details Details about the topic.
*
* @return mixed
*/
public function create(array $details = [])
{
$details = array_merge(['title' => '', 'forum_id' => 0, 'user_id' => $this->guard->user()->id, 'username' => null, 'first_post_id' => 0, 'last_post_id' => 0, 'views' => 0, 'num_posts' => 0, 'content' => ''], $details);
$details['slug'] = $this->createSlugForTitle($details['title']);
if ($details['user_id'] > 0) {
$details['username'] = User::find($details['user_id'])->name;
// TODO: Use User Repository!
} else {
$details['user_id'] = null;
if ($details['username'] == trans('general.guest')) {
$details['username'] = null;
}
}
$topic = null;
$this->dbManager->transaction(function () use($details, &$topic) {
$topic = $this->topicModel->create(['title' => $details['title'], 'slug' => $details['slug'], 'forum_id' => $details['forum_id'], 'user_id' => $details['user_id'], 'username' => $details['username']]);
$firstPost = $this->postRepository->addPostToTopic($topic, ['content' => $details['content'], 'username' => $details['username']]);
$topic->update(['first_post_id' => $firstPost->id, 'last_post_id' => $firstPost->id, 'num_posts' => 1]);
});
$topic->forum->increment('num_topics');
if ($topic->user_id > 0) {
$topic->author->increment('num_topics');
}
return $topic;
}
示例2: remove
/**
* Remove the poll
*
* @param Poll $poll
*
* @return bool
*/
public function remove(Poll $poll)
{
$this->dbManager->transaction(function () use(&$poll) {
$this->pollVoteRepository->removeAllByPoll($poll);
$poll->delete();
});
if ($poll) {
return false;
} else {
return true;
}
}
示例3: create
/**
* {@inheritdoc}
*/
public function create(array $details)
{
$conversation = null;
$this->dbManager->transaction(function () use($details, &$conversation) {
$conversation = $this->conversationModel->create(['title' => $details['title']]);
$this->conversationMessageRepository->addMessageToConversation($conversation, ['author_id' => $this->guard->user()->id, 'message' => $details['message']], false);
// First add the author of this message - if he answered it he also read the conversation
$conversation->participants()->attach($this->guard->user()->id, ['last_read' => new \DateTime()]);
// And now add all other participants
$this->addParticipants($conversation, $details['participants']);
});
return $conversation;
}
示例4: delete
/**
* Delete existing ... (soft delete)
*
* @param array $input
* An array as follows: array($id0, $id1,…);
*
* @return JSON encoded string
* A string as follows:
* In case of success: {"success" : form.defaultSuccessDeleteMessage}
*/
public function delete(array $input)
{
$count = 0;
$this->DB->transaction(function () use($input, &$count) {
$loggedUserId = $this->AuthenticationManager->getLoggedUserId();
$organizationId = $this->AuthenticationManager->getCurrentUserOrganization('id');
foreach ($input['id'] as $key => $id) {
$count++;
$VoucherType = $this->VoucherType->byId($id);
$Journal = $this->Journal->create(array('journalized_id' => $id, 'journalized_type' => $this->VoucherType->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::voucher-type-management.deletedJournal', array('name' => $VoucherType->name))), $Journal);
$this->VoucherType->delete(array($id));
}
});
if ($count == 1) {
return json_encode(array('success' => $this->Lang->get('form.defaultSuccessDeleteMessage')));
} else {
return json_encode(array('success' => $this->Lang->get('form.defaultSuccessDeleteMessage1')));
}
}
示例5: delete
/**
* Delete an existing account (soft delete)
*
* @param array $input
* An array as follows: array(id => $id);
*
* @return JSON encoded string
* A string as follows:
* In case of success: {"success" : form.defaultSuccessDeleteMessage}
*/
public function delete(array $input)
{
$info = false;
$this->DB->transaction(function () use($input, &$info) {
$loggedUserId = $this->AuthenticationManager->getLoggedUserId();
$organizationId = $this->AuthenticationManager->getCurrentUserOrganization('id');
$ids = $this->getAccountChildrenIds($input['id']);
array_push($ids, $input['id']);
if ($this->JournalEntry->byAccountIds($ids)->count() > 0) {
$info = $this->Lang->get('decima-accounting::account-management.accountValidationMessage');
return;
}
$this->Account->byIds($ids)->each(function ($Account) use($loggedUserId, $organizationId) {
$Journal = $this->Journal->create(array('journalized_id' => $Account->id, 'journalized_type' => $this->Account->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::account-management.accountDeletedAccount', array('account' => $Account->key . ' ' . $Account->name)), $Journal));
});
$this->Account->delete($ids);
});
if (!$info) {
return json_encode(array('success' => $this->Lang->get('form.defaultSuccessDeleteMessage')));
} else {
return json_encode(array('info' => $info));
}
}
示例6: wrap
/**
* Wrap inside a closure
*
* @param callable $job
*/
public function wrap(closure $job)
{
return $this->db->transaction($job);
}
示例7: createClosingBalanceVoucher
/**
* Create closing balance voucher
*
* @param array $input
* An array as follows: array('fiscal_year_id'=>$id, 'date'=> $date, 'period_id' => periodId, 'voucher_type_id' => $voucherTypeId, 'remark' => $remark, 'cost_center_id' => $costCenterId, 'account_id' => $accountId );
*
* @return JSON encoded string
* A string as follows:
* In case of success: {"success" : form.defaultSuccessSaveMessage}
*/
public function createClosingBalanceVoucher(array $input)
{
$loggedUserId = $this->AuthenticationManager->getLoggedUserId();
$organizationId = $this->AuthenticationManager->getCurrentUserOrganizationId();
$input = eloquent_array_filter_for_insert($input);
$input = array_add($input, 'organization_id', $organizationId);
$this->DB->transaction(function () use($input, $loggedUserId, $organizationId, &$resultClosing, &$resultOpening) {
$resultClosing = json_decode($this->JournalManagerService->saveJournalVoucher(array('notransaction' => '', 'status' => 'B', 'date' => $input['date_closing'], 'remark' => $input['remark_closing'], 'period_id' => $input['period_id_closing'], 'voucher_type_id' => $input['voucher_type_id_closing'])), true);
$resultOpening = json_decode($this->JournalManagerService->saveJournalVoucher(array('notransaction' => '', 'status' => 'B', 'date' => $input['date_opening'], 'remark' => $input['remark_opening'], 'period_id' => $input['period_id_opening'], 'voucher_type_id' => $input['voucher_type_id_opening'])), true);
$entries = $this->JournalEntry->getJournalEntriesGroupedByPlBsCategoryByOrganizationAndByFiscalYear(array('D', 'E'), $organizationId, $input['fiscal_year_id']);
$voucherClosingEntries = array();
$voucherOpeningEntries = array();
foreach ($entries as $Entry) {
//$Entry->balance_type
//Deudor,Receivable:D and Acreedor,Payable: A
if ($Entry->balance_type == 'D') {
$credit = round($Entry->debit - $Entry->credit, 2);
$debit = 0;
} else {
$debit = round($Entry->credit - $Entry->debit, 2);
$credit = 0;
}
if ($debit != 0 || $credit != 0) {
array_push($voucherClosingEntries, array('debit' => $debit, 'credit' => $credit, 'cost_center_id' => $Entry->cost_center_id, 'account_id' => $Entry->account_id, 'journal_voucher_id' => $resultClosing['id']));
array_push($voucherOpeningEntries, array('debit' => $credit, 'credit' => $debit, 'cost_center_id' => $Entry->cost_center_id, 'account_id' => $Entry->account_id, 'journal_voucher_id' => $resultOpening['id']));
}
}
$this->JournalEntry->massCreate($voucherClosingEntries);
$this->JournalEntry->massCreate($voucherOpeningEntries);
$Journal = $this->Journal->create(array('journalized_id' => $input['fiscal_year_id'], 'journalized_type' => $this->FiscalYear->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::close-fiscal-year.closingBalanceAddedJournal', array('number' => $resultClosing['number'], 'period' => $input['period_label_closing'])), $Journal));
$this->JournalManagerService->updateJournalVoucherStatus($resultClosing['id']);
$Journal = $this->Journal->create(array('journalized_id' => $input['fiscal_year_id_opening'], 'journalized_type' => $this->FiscalYear->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::close-fiscal-year.openingBalanceAddedJournal', array('number' => $resultOpening['number'], 'period' => $input['period_label_opening'])), $Journal));
$this->JournalManagerService->updateJournalVoucherStatus($resultOpening['id']);
});
return json_encode(array('success' => $this->Lang->get('decima-accounting::close-fiscal-year.closingBalanceAddedJournal', array('number' => $resultClosing['number'], 'period' => $input['period_label_closing'])) . '<br>' . $this->Lang->get('decima-accounting::close-fiscal-year.closingBalanceAddedJournal', array('number' => $resultOpening['number'], 'period' => $input['period_label_opening']))));
}
示例8: updateAccountingSettings
/**
* Update accounting setting
*
* @param array $input
* An array as follows: array('courses'=> array($id0, $id1,…), 'costCenters'=> array($key0, $key1,…));
*
* @return JSON encoded string
* A string as follows:
* {
* totalEmployees: $totalEmployees
* payrollEmployees: $payrollEmployees
* serviceEmployees: $serviceEmployees
* }
*/
public function updateAccountingSettings(array $input = array())
{
$organizationId = $this->AuthenticationManager->getCurrentUserOrganization('id');
$loggedUserId = $this->AuthenticationManager->getLoggedUserId();
$Setting = $this->Setting->byOrganization($organizationId)->first();
$this->DB->transaction(function () use($Setting, $input, $organizationId, $loggedUserId) {
$SettingJournal = $this->Journal->create(array('journalized_id' => $Setting->id, 'journalized_type' => $this->Setting->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
if (empty($Setting->is_configured)) {
$organizationAccountsType = array();
$this->SystemAccountType->all()->each(function ($AccountType) use($organizationId, &$organizationAccountsType, $loggedUserId) {
$accountType = $AccountType->toArray();
$accountType = array_add($accountType, 'organization_id', $organizationId);
$accountType['name'] = $this->Lang->has($accountType['lang_key']) ? $this->Lang->get($accountType['lang_key']) : $accountType['name'];
unset($accountType['id'], $accountType['created_at'], $accountType['updated_at'], $accountType['deleted_at']);
$AccountType = $this->AccountType->create($accountType);
$organizationAccountsType = array_add($organizationAccountsType, $AccountType->key, $AccountType->id);
$Journal = $this->Journal->create(array('journalized_id' => $AccountType->id, 'journalized_type' => $this->AccountType->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.accountTypeAddedJournal', array('type' => $this->Lang->has($AccountType->lang_key) ? $this->Lang->get($AccountType->lang_key) : $AccountType->name))), $Journal);
});
$this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.accountTypeSettingAddedJournal')), $SettingJournal);
$this->SystemVoucherType->all()->each(function ($VoucherType) use($organizationId, $loggedUserId) {
$voucherType = $VoucherType->toArray();
$voucherType = array_add($voucherType, 'organization_id', $organizationId);
$voucherType['name'] = $this->Lang->has($voucherType['lang_key']) ? $this->Lang->get($voucherType['lang_key']) : $voucherType['name'];
unset($voucherType['id'], $voucherType['created_at'], $voucherType['updated_at'], $voucherType['deleted_at']);
$VoucherType = $this->VoucherType->create($voucherType);
$Journal = $this->Journal->create(array('journalized_id' => $VoucherType->id, 'journalized_type' => $this->VoucherType->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.voucherTypeAddedJournal', array('type' => $this->Lang->has($VoucherType->lang_key) ? $this->Lang->get($VoucherType->lang_key) : $VoucherType->name))), $Journal);
});
$this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.voucherTypeSettingAddedJournal')), $SettingJournal);
$firstDayYear = date($input['year'] . '-01-01');
$lastDayYear = date($input['year'] . '-12-31');
$FiscalYear = $this->FiscalYear->create(array('year' => $input['year'], 'start_date' => $firstDayYear, 'end_date' => $lastDayYear, 'organization_id' => $organizationId));
$Journal = $this->Journal->create(array('journalized_id' => $FiscalYear->id, 'journalized_type' => $this->FiscalYear->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.fiscalYearAddedJournal', array('year' => $input['year']))), $Journal);
$this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.fiscalYearAddedJournal', array('year' => $input['year']))), $SettingJournal);
if ($input['create_opening_period'] == '1') {
$Period = $this->Period->create(array('month' => 0, 'start_date' => $firstDayYear, 'end_date' => $firstDayYear, 'fiscal_year_id' => $FiscalYear->id, 'organization_id' => $organizationId));
$Journal = $this->Journal->create(array('journalized_id' => $Period->id, 'journalized_type' => $this->Period->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.periodAddedJournal', array('period' => 0))), $Journal);
}
for ($i = 1; $i <= 12; $i++) {
$Date = new \DateTime($input['year'] . '-' . $i . '-01');
$firstDay = $Date->format('Y-m-d');
$Date->modify('last day of this month');
$lastDay = $Date->format('Y-m-d');
$Period = $this->Period->create(array('month' => $i, 'start_date' => $firstDay, 'end_date' => $lastDay, 'fiscal_year_id' => $FiscalYear->id, 'organization_id' => $organizationId));
$Journal = $this->Journal->create(array('journalized_id' => $Period->id, 'journalized_type' => $this->Period->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.periodAddedJournal', array('period' => $i))), $Journal);
}
if ($input['create_closing_period'] == '1') {
$Period = $this->Period->create(array('month' => 13, 'start_date' => $lastDayYear, 'end_date' => $lastDayYear, 'fiscal_year_id' => $FiscalYear->id, 'organization_id' => $organizationId));
$Journal = $this->Journal->create(array('journalized_id' => $Period->id, 'journalized_type' => $this->Period->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.periodAddedJournal', array('period' => 13))), $Journal);
}
$this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.periodAddedSettingJournal')), $SettingJournal);
$CostCenter = $this->CostCenter->create(array('name' => $this->AuthenticationManager->getCurrentUserOrganizationName(), 'key' => $this->Config->get('accounting-general.default_organization_cc_key'), 'is_group' => true, 'organization_id' => $organizationId));
$Journal = $this->Journal->create(array('journalized_id' => $CostCenter->id, 'journalized_type' => $this->CostCenter->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.costCenterAddedJournal', array('costCenter' => $CostCenter->key . ' ' . $CostCenter->name))), $Journal);
$CostCenter = $this->CostCenter->create(array('name' => $this->Lang->get('decima-accounting::cost-center.main'), 'key' => $this->Config->get('accounting-general.default_main_cc_key'), 'is_group' => false, 'parent_cc_id' => $CostCenter->id, 'organization_id' => $organizationId));
$Journal = $this->Journal->create(array('journalized_id' => $CostCenter->id, 'journalized_type' => $this->CostCenter->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.costCenterAddedJournal', array('costCenter' => $CostCenter->key . ' ' . $CostCenter->name))), $Journal);
$this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.costCenterAddedSettingJournal')), $SettingJournal);
$organizationAccounts = array();
$this->SystemAccount->accountsByAccountChartsTypes($input['account_chart_type_id'])->each(function ($SystemAccount) use($organizationId, $organizationAccountsType, &$organizationAccounts, &$systemAccountsCounter, $loggedUserId) {
$account = $SystemAccount->toArray();
$account = array_add($account, 'organization_id', $organizationId);
$account = array_add($account, 'account_type_id', $organizationAccountsType[$account['account_type_key']]);
if (!empty($account['parent_key'])) {
$account = array_add($account, 'parent_account_id', $organizationAccounts[$account['parent_key']]);
}
unset($account['id'], $account['parent_key'], $account['account_type_key'], $account['account_chart_type_id'], $account['created_at'], $account['updated_at'], $account['deleted_at']);
$OrganizationAccount = $this->Account->create($account);
$Journal = $this->Journal->create(array('journalized_id' => $OrganizationAccount->id, 'journalized_type' => $this->Account->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.accountAddedJournal', array('account' => $OrganizationAccount->key . ' ' . $OrganizationAccount->name))), $Journal);
$organizationAccounts[$OrganizationAccount->key] = $OrganizationAccount->id;
});
if (!empty($organizationAccounts)) {
$AccountChartType = $this->AccountChartType->byId($input['account_chart_type_id']);
$this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.accountAddedSettingJournal', array('catalog' => $AccountChartType->name))), $SettingJournal);
}
$input['id'] = $Setting->id;
$input['initial_year'] = $input['year'];
$input['is_configured'] = true;
unset($input['_token'], $input['year']);
$this->Setting->update($input);
//.........这里部分代码省略.........
示例9: closePeriod
/**
* Close an existing period
*
* @param array $input
* An array as follows: array(id => $id);
*
* @return JSON encoded string
* A string as follows:
* In case of success: {"success" : form.defaultSuccessOperationMessage}
*/
public function closePeriod(array $input)
{
$canBeClosed = true;
$this->DB->transaction(function () use($input, &$canBeClosed) {
$loggedUserId = $this->AuthenticationManager->getLoggedUserId();
$organizationId = $this->AuthenticationManager->getCurrentUserOrganization('id');
if ($this->JournalVoucher->getByOrganizationByPeriodAndByStatus($organizationId, array($input['id']), 'A')->count() > 0) {
$canBeClosed = false;
return;
}
$Period = $this->Period->byId($input['id']);
$Journal = $this->Journal->create(array('journalized_id' => $input['id'], 'journalized_type' => $this->Period->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
// $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get('decima-accounting::journal-management.status'), 'field_lang_key' => 'decima-accounting::journal-management.status', 'old_value' => $this->Lang->get('decima-accounting::period-management.opened'), 'new_value' => $this->Lang->get('decima-accounting::period-management.closed')), $Journal);
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::period-management.periodClosedJournal', array('period' => $this->Lang->get('decima-accounting::period-management.' . $Period->month))), $Journal));
$this->Period->update(array('is_closed' => true), $Period);
});
if (!$canBeClosed) {
return json_encode(array('success' => false, 'info' => $this->Lang->get('decima-accounting::period-management.voucherException')));
}
return json_encode(array('success' => $this->Lang->get('form.defaultSuccessOperationMessage')));
}
示例10: deleteJournalEntry
/**
* Delete an existing journal entry (soft delete)
*
* @param array $input
* An array as follows: array($id0, $id1,…);
*
* @return JSON encoded string
* A string as follows:
* In case of success: {"success" : form.defaultSuccessDeleteMessage}
*/
public function deleteJournalEntry(array $input)
{
$count = 0;
$periodIsClosed = false;
$this->DB->transaction(function () use($input, &$count, &$status, &$periodIsClosed, &$Period) {
$loggedUserId = $this->AuthenticationManager->getLoggedUserId();
$organizationId = $this->AuthenticationManager->getCurrentUserOrganization('id');
foreach ($input['id'] as $key => $id) {
$count++;
$JournalEntry = $this->JournalEntry->byId($id);
if ($count == 1) {
$JournalVoucher = $this->JournalVoucher->byId($JournalEntry->journal_voucher_id);
$Period = $this->Period->byId($JournalVoucher->period_id);
if ($Period->is_closed) {
$periodIsClosed = true;
return;
}
$JournalVoucher = $this->JournalVoucher->byId($JournalEntry->journal_voucher_id);
$Journal = $this->Journal->create(array('journalized_id' => $JournalEntry->journal_voucher_id, 'journalized_type' => $this->JournalVoucher->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
}
$this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::journal-management.journalEntryDeletedJournal', array('number' => $JournalVoucher->number)), $Journal));
$this->JournalEntry->delete($input['id']);
}
$status = $this->updateJournalVoucherStatus($JournalVoucher->id, $Journal, $JournalVoucher);
});
if ($periodIsClosed) {
return json_encode(array('success' => false, 'info' => $this->Lang->get('decima-accounting::journal-management.closedPeriodValidationMessage2', array('period' => $this->Lang->get('decima-accounting::period-management.' . $Period->month)))));
}
return json_encode(array('success' => $this->Lang->get('form.defaultSuccessDeleteMessage'), 'status' => $status, 'statusLabel' => $this->Lang->get('decima-accounting::journal-management.' . $status)));
}