public function create()
 {
     $accounts = ChartOfAccount::where('account_type', 1)->lists('name', 'code');
     $types = Config::get('common.transaction_customer_type');
     $years = CommonHelper::get_years();
     return view('transactionRecorders.create', compact('accounts', 'types', 'years'));
 }
예제 #2
0
 public function create()
 {
     $accounts = ChartOfAccount::where('account_type', 1)->where('code', 'like', '2%')->orWhere('code', '32000')->lists('name', 'code');
     $types = Config::get('common.transaction_customer_type');
     $years = CommonHelper::get_years();
     return view('makePayment.create', compact('accounts', 'types', 'years'));
 }
예제 #3
0
 public function edit($id)
 {
     $parents = ChartOfAccount::where('status', 1)->lists('name', 'id');
     $contras = ChartOfAccount::where('status', 1)->lists('name', 'code');
     $chart = ChartOfAccount::findOrFail($id);
     return view('chartOfAccounts.edit', compact('chart', 'parents', 'contras'));
 }
예제 #4
0
 public function store(Request $request)
 {
     $yearClosingStatus = AccountClosing::where(['year' => CommonHelper::get_current_financial_year(), 'type' => 2])->lists('id');
     if (sizeof($yearClosingStatus) == 0) {
         $workspaces = Workspace::where('status', 1)->lists('id');
         $closedWorkspaces = AccountClosing::where(['year' => CommonHelper::get_current_financial_year(), 'type' => 1])->lists('workspace_id');
         if (sizeof($workspaces) == sizeof($closedWorkspaces)) {
             try {
                 DB::transaction(function () use($request) {
                     $heads = ChartOfAccount::where('status', 1)->lists('code');
                     $currentYear = CommonHelper::get_current_financial_year();
                     foreach ($heads as $head) {
                         $headTotal = WorkspaceLedger::where(['account_code' => $head, 'year' => CommonHelper::get_current_financial_year(), 'balance_type' => Config::get('common.balance_type_closing')])->sum('balance');
                         // Closing Balance Set
                         $generalLedger = new GeneralLedger();
                         $generalLedger->year = $currentYear;
                         $generalLedger->account_code = $head;
                         $generalLedger->balance_type = Config::get('common.balance_type_closing');
                         $generalLedger->balance = $headTotal;
                         $generalLedger->created_by = Auth::user()->id;
                         $generalLedger->created_at = time();
                         $generalLedger->save();
                         // Opening Balance Set for Next Financial Year
                         if (substr($head, 0, 1) == 1 || substr($head, 0, 1) == 4 || substr($head, 0, 1) == 6) {
                             $generalLedger = new GeneralLedger();
                             $generalLedger->year = CommonHelper::get_next_financial_year();
                             $generalLedger->account_code = $head;
                             $generalLedger->balance_type = Config::get('common.balance_type_opening');
                             $generalLedger->balance = $headTotal;
                             $generalLedger->created_by = Auth::user()->id;
                             $generalLedger->created_at = time();
                             $generalLedger->save();
                         } else {
                             $generalLedger = new GeneralLedger();
                             $generalLedger->year = CommonHelper::get_next_financial_year();
                             $generalLedger->account_code = $head;
                             $generalLedger->balance_type = Config::get('common.balance_type_opening');
                             $generalLedger->balance = 0;
                             $generalLedger->created_by = Auth::user()->id;
                             $generalLedger->created_at = time();
                             $generalLedger->save();
                         }
                     }
                     // Account Closing table Impact
                     $accountClosing = new AccountClosing();
                     $accountClosing->type = 2;
                     // Year Closing type=2 and Workspace Closing type=1;
                     $accountClosing->year = $currentYear;
                     $accountClosing->save();
                     // Raw Stock Table Impact
                     $rawMaterials = RawStock::where(['year' => CommonHelper::get_current_financial_year(), 'stock_type' => Config::get('common.balance_type_intermediate')])->get();
                     foreach ($rawMaterials as $rawMaterial) {
                         // Current Year Opening Balance
                         $rawStock = new RawStock();
                         $rawStock->year = $currentYear;
                         $rawStock->stock_type = Config::get('common.balance_type_closing');
                         $rawStock->material_id = $rawMaterial->material_id;
                         $rawStock->quantity = $rawMaterial->quantity;
                         $rawStock->created_by = Auth::user()->id;
                         $rawStock->created_at = time();
                         // Next Year Opening Balance
                         $rawStock = new RawStock();
                         $rawStock->year = CommonHelper::get_next_financial_year();
                         $rawStock->stock_type = Config::get('common.balance_type_opening');
                         $rawStock->material_id = $rawMaterial->material_id;
                         $rawStock->quantity = $rawMaterial->quantity;
                         $rawStock->created_by = Auth::user()->id;
                         $rawStock->created_at = time();
                         // Next Year Intermediate Balance
                         $rawStock = new RawStock();
                         $rawStock->year = CommonHelper::get_next_financial_year();
                         $rawStock->stock_type = Config::get('common.balance_type_intermediate');
                         $rawStock->material_id = $rawMaterial->material_id;
                         $rawStock->quantity = $rawMaterial->quantity;
                         $rawStock->created_by = Auth::user()->id;
                         $rawStock->created_at = time();
                     }
                     // Current Year Data Fetch
                     $existingYearDetail = DB::table('financial_years')->where('year', $currentYear)->first();
                     $nextYear = CommonHelper::get_next_financial_year();
                     // Current Year Inactive
                     DB::table('financial_years')->where('year', $currentYear)->update(['status' => 0]);
                     // New Year Insert
                     DB::table('financial_years')->insert(['year' => $nextYear, 'start_date' => strtotime(date("Y-m-d", $existingYearDetail->start_date) . " + 1 year"), 'end_date' => strtotime(date("Y-m-d", $existingYearDetail->end_date) . " + 1 year"), 'created_by' => Auth::user()->id, 'created_at' => time()]);
                 });
             } catch (\Exception $e) {
                 Session()->flash('error_message', 'Year Closing Not Done!');
                 return redirect('year_closing');
             }
             Session()->flash('flash_message', 'Year Closed And New Year Opened Successfully!');
             return redirect('year_closing');
         } else {
             Session()->flash('warning_message', 'Warning: All Workspace Account Not Closed Yet!');
             return redirect('year_closing');
         }
     } else {
         Session()->flash('warning_message', 'Warning: Year Closing Done For This Year!');
         return redirect('year_closing');
     }
 }
예제 #5
0
 public function edit($id)
 {
     $initializations = WorkspaceLedger::where('workspace_id', $id)->get();
     $accounts = ChartOfAccount::where('status', 1)->select('name', 'code')->get();
     return view('initializations.edit', compact('accounts', 'initializations', 'id'));
 }
예제 #6
0
 public function store(Request $request)
 {
     $workspace_id = Auth::user()->workspace_id;
     $closedWorkspace = AccountClosing::where(['year' => CommonHelper::get_current_financial_year(), 'type' => 1, 'workspace_id' => $workspace_id])->lists('workspace_id');
     if (sizeof($closedWorkspace) == 0) {
         try {
             DB::transaction(function () use($request) {
                 $workspace_id = Auth::user()->workspace_id;
                 $levelZeros = ChartOfAccount::where(['parent' => 0, 'status' => 1])->select('id', 'name', 'code')->get();
                 foreach ($levelZeros as $levelZero) {
                     $workspaceData = WorkspaceLedger::where(['workspace_id' => $workspace_id, 'account_code' => $levelZero->code, 'balance_type' => Config::get('common.balance_type_intermediate'), 'year' => CommonHelper::get_current_financial_year()])->first();
                     $balance = isset($workspaceData->balance) ? $workspaceData->balance : 0;
                     $a[] = [$levelZero->id, $levelZero->code, '', $balance];
                 }
                 for ($ci = 0; isset($a[$ci][0]); $ci++) {
                     $nextLevels = ChartOfAccount::where(['parent' => $a[$ci][0], 'status' => 1])->get(['code', 'id']);
                     foreach ($nextLevels as $nextLevel) {
                         $NextLevelWorkspaceData = WorkspaceLedger::where(['workspace_id' => $workspace_id, 'account_code' => $nextLevel->code, 'balance_type' => Config::get('common.balance_type_intermediate'), 'year' => CommonHelper::get_current_financial_year()])->first();
                         $nextLevelBalance = isset($NextLevelWorkspaceData->balance) ? $NextLevelWorkspaceData->balance : 0;
                         $a[] = [$nextLevel->id, $nextLevel->code, $ci, $nextLevelBalance];
                     }
                 }
                 $ci = sizeof($a) - 1;
                 for (; $ci >= 0; $ci--) {
                     if (isset($a[$a[$ci][2]][3])) {
                         $contra = ChartOfAccount::where(['contra_status' => 1, 'id' => $a[$ci][0]])->first();
                         if ($contra) {
                             $a[$a[$ci][2]][3] -= $a[$ci][3];
                         } else {
                             $a[$a[$ci][2]][3] += $a[$ci][3];
                         }
                     }
                     // Closing Balance
                     $workspaceLedger = new WorkspaceLedger();
                     $workspaceLedger->workspace_id = $workspace_id;
                     $workspaceLedger->year = CommonHelper::get_current_financial_year();
                     $workspaceLedger->account_code = $a[$ci][1];
                     $workspaceLedger->balance_type = Config::get('common.balance_type_closing');
                     $workspaceLedger->balance = $a[$ci][3];
                     $workspaceLedger->created_by = Auth::user()->id;
                     $workspaceLedger->created_at = time();
                     $workspaceLedger->save();
                     if (substr($a[$ci][1], 0, 1) == 1 || substr($a[$ci][1], 0, 1) == 4 || substr($a[$ci][1], 0, 1) == 6) {
                         // Initial Balance Next Year
                         $workspaceLedger = new WorkspaceLedger();
                         $workspaceLedger->workspace_id = $workspace_id;
                         $workspaceLedger->year = CommonHelper::get_next_financial_year();
                         $workspaceLedger->account_code = $a[$ci][1];
                         $workspaceLedger->balance_type = Config::get('common.balance_type_opening');
                         $workspaceLedger->balance = $a[$ci][3];
                         $workspaceLedger->created_by = Auth::user()->id;
                         $workspaceLedger->created_at = time();
                         $workspaceLedger->save();
                         // Intermediate Balance Next Year
                         $workspaceLedger = new WorkspaceLedger();
                         $workspaceLedger->workspace_id = $workspace_id;
                         $workspaceLedger->year = CommonHelper::get_next_financial_year();
                         $workspaceLedger->account_code = $a[$ci][1];
                         $workspaceLedger->balance_type = Config::get('common.balance_type_intermediate');
                         $workspaceLedger->balance = $a[$ci][3];
                         $workspaceLedger->created_by = Auth::user()->id;
                         $workspaceLedger->created_at = time();
                         $workspaceLedger->save();
                     } else {
                         // Initial Balance Next Year
                         $workspaceLedger = new WorkspaceLedger();
                         $workspaceLedger->workspace_id = $workspace_id;
                         $workspaceLedger->year = CommonHelper::get_next_financial_year();
                         $workspaceLedger->account_code = $a[$ci][1];
                         $workspaceLedger->balance_type = Config::get('common.balance_type_opening');
                         $workspaceLedger->balance = 0;
                         $workspaceLedger->created_by = Auth::user()->id;
                         $workspaceLedger->created_at = time();
                         $workspaceLedger->save();
                         // Intermediate Balance Next Year
                         $workspaceLedger = new WorkspaceLedger();
                         $workspaceLedger->workspace_id = $workspace_id;
                         $workspaceLedger->year = CommonHelper::get_next_financial_year();
                         $workspaceLedger->account_code = $a[$ci][1];
                         $workspaceLedger->balance_type = Config::get('common.balance_type_intermediate');
                         $workspaceLedger->balance = 0;
                         $workspaceLedger->created_by = Auth::user()->id;
                         $workspaceLedger->created_at = time();
                         $workspaceLedger->save();
                     }
                 }
                 // Workspace Account Close Info
                 $accountClosing = new AccountClosing();
                 $accountClosing->workspace_id = $workspace_id;
                 $accountClosing->year = CommonHelper::get_current_financial_year();
                 $accountClosing->save();
                 // Workspace Stock Closing
                 $existingStocks = Stock::where(['stock_type' => Config::get('common.balance_type_intermediate'), 'workspace_id' => $workspace_id, 'year' => CommonHelper::get_current_financial_year()])->get();
                 if (sizeof($existingStocks) > 0) {
                     foreach ($existingStocks as $existingStock) {
                         // Current Year Closing Balance
                         $stock = new Stock();
                         $stock->year = CommonHelper::get_current_financial_year();
                         $stock->stock_type = Config::get('common.balance_type_closing');
                         $stock->workspace_id = $workspace_id;
                         $stock->product_id = $existingStock->product_id;
                         $stock->quantity = $existingStock->quantity;
                         $stock->created_by = Auth::user()->id;
                         $stock->created_at = time();
                         $stock->save();
                         // Next Year Opening Balance
                         $stock = new Stock();
                         $stock->year = CommonHelper::get_next_financial_year();
                         $stock->stock_type = Config::get('common.balance_type_opening');
                         $stock->workspace_id = $workspace_id;
                         $stock->product_id = $existingStock->product_id;
                         $stock->quantity = $existingStock->quantity;
                         $stock->created_by = Auth::user()->id;
                         $stock->created_at = time();
                         $stock->save();
                         // Next Year Intermediate Balance
                         $stock = new Stock();
                         $stock->year = CommonHelper::get_next_financial_year();
                         $stock->stock_type = Config::get('common.balance_type_intermediate');
                         $stock->workspace_id = $workspace_id;
                         $stock->product_id = $existingStock->product_id;
                         $stock->quantity = $existingStock->quantity;
                         $stock->created_by = Auth::user()->id;
                         $stock->created_at = time();
                         $stock->save();
                     }
                 }
             });
         } catch (\Exception $e) {
             Session()->flash('error_message', 'Workspace Account Closing Not Done!');
             return redirect('workspace_closing');
         }
         Session()->flash('flash_message', 'Workspace Account Closed Successfully!');
         return redirect('workspace_closing');
     } else {
         Session()->flash('warning_message', 'Workspace Account Closed Already For This Year!');
         return redirect('workspace_closing');
     }
 }