Esempio n. 1
0
 public function update($id, InitializationRequest $request)
 {
     try {
         DB::transaction(function () use($request, $id) {
             $currentYear = CommonHelper::get_current_financial_year();
             $balanceInput = $request->input('balance');
             foreach ($balanceInput as $code => $amount) {
                 $WorkspaceLedger = new WorkspaceLedger();
                 $GeneralLedger = new GeneralLedger();
                 $WorkspaceLedger->workspace_id = $id;
                 $WorkspaceLedger->year = $currentYear;
                 $WorkspaceLedger->account_code = $code;
                 $WorkspaceLedger->balance_type = Config::get('common.balance_type_opening');
                 $WorkspaceLedger->balance = $amount;
                 $WorkspaceLedger->created_by = Auth::user()->id;
                 $WorkspaceLedger->created_at = time();
                 $WorkspaceLedger->save();
                 $WorkspaceLedger = new WorkspaceLedger();
                 // Intermediate row insert
                 $WorkspaceLedger->workspace_id = $id;
                 $WorkspaceLedger->year = $currentYear;
                 $WorkspaceLedger->account_code = $code;
                 $WorkspaceLedger->balance_type = Config::get('common.balance_type_intermediate');
                 $WorkspaceLedger->balance = $amount;
                 $WorkspaceLedger->created_by = Auth::user()->id;
                 $WorkspaceLedger->created_at = time();
                 $WorkspaceLedger->save();
                 $existingGeneralData = GeneralLedger::where(['account_code' => $code, 'balance_type' => Config::get('common.balance_type_opening'), 'year' => $currentYear])->first();
                 if ($existingGeneralData) {
                     $existingGeneral = GeneralLedger::firstOrNew(['account_code' => $code, 'balance_type' => Config::get('common.balance_type_opening'), 'year' => $currentYear]);
                     $existingGeneral->year = $currentYear;
                     $existingGeneral->account_code = $code;
                     $existingGeneral->balance_type = Config::get('common.balance_type_opening');
                     $existingGeneral->balance = $existingGeneralData->balance + $amount;
                     $existingGeneral->updated_by = Auth::user()->id;
                     $existingGeneral->updated_at = time();
                     $existingGeneral->update();
                 } else {
                     $GeneralLedger->year = $currentYear;
                     $GeneralLedger->account_code = $code;
                     $GeneralLedger->balance_type = Config::get('common.balance_type_opening');
                     $GeneralLedger->balance = $amount;
                     $GeneralLedger->created_by = Auth::user()->id;
                     $GeneralLedger->created_at = time();
                     $GeneralLedger->save();
                 }
                 //                // General Intermediate Data Insert/ Update
                 //                $GeneralLedger = New GeneralLedger;
                 //                $existingGeneralIntermediateData = GeneralLedger::where(['account_code' => $code, 'balance_type' => Config::get('common.balance_type_intermediate')])->first();
                 //
                 //                if($existingGeneralIntermediateData)
                 //                {
                 //                    $existingGeneralIntermediate = GeneralLedger::firstOrNew(['account_code' => $code, 'balance_type' => Config::get('common.balance_type_intermediate')]);
                 //
                 //                    $existingGeneralIntermediate->year = date('Y');
                 //                    $existingGeneralIntermediate->account_code = $code;
                 //                    $existingGeneralIntermediate->balance_type = Config::get('common.balance_type_intermediate');
                 //                    $existingGeneralIntermediate->balance = $existingGeneralData->balance + $amount;
                 //                    $existingGeneralIntermediate->updated_by = Auth::user()->id;
                 //                    $existingGeneralIntermediate->updated_at = time();
                 //                    $existingGeneralIntermediate->update();
                 //                }
                 //                else
                 //                {
                 //                    $GeneralLedger->year = date('Y');
                 //                    $GeneralLedger->account_code = $code;
                 //                    $GeneralLedger->balance_type = Config::get('common.balance_type_intermediate');
                 //                    $GeneralLedger->balance = $amount;
                 //                    $GeneralLedger->created_by = Auth::user()->id;
                 //                    $GeneralLedger->created_at = time();
                 //                    $GeneralLedger->save();
                 //                }
             }
         });
     } catch (\Exception $e) {
         Session()->flash('error_message', 'Accounts not Initialized!');
         return redirect('initializations');
     }
     Session()->flash('flash_message', 'Accounts Initialized!');
     return redirect('initializations');
 }
Esempio n. 2
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');
     }
 }
Esempio n. 3
0
 public function store(Request $request)
 {
     try {
         DB::transaction(function () use($request) {
             $workspace_id = $request->workspace_id;
             if ($workspace_id > 0) {
                 $currentYear = CommonHelper::get_current_financial_year();
                 $closingStatus = DB::table('account_closings')->where(['year' => $currentYear, 'workspace_id' => $workspace_id])->value('status');
                 $existingYearDetail = DB::table('financial_years')->where('year', $currentYear)->first();
                 if ($closingStatus == 1) {
                     if ($existingYearDetail->end_date > strtotime(date('Y-m-d'))) {
                         // Delete Workspace Closing Balance Data of Current Year
                         WorkspaceLedger::where(['workspace_id' => $workspace_id, 'balance_type' => Config::get('common.balance_type_closing'), 'year' => CommonHelper::get_current_financial_year()])->delete();
                         // Delete Next Year Opening Balance Data
                         WorkspaceLedger::where(['workspace_id' => $workspace_id, 'balance_type' => Config::get('common.balance_type_opening'), 'year' => CommonHelper::get_next_financial_year()])->delete();
                         // Delete Next Year Intermediate Balance Data
                         WorkspaceLedger::where(['workspace_id' => $workspace_id, 'balance_type' => Config::get('common.balance_type_intermediate'), 'year' => CommonHelper::get_next_financial_year()])->delete();
                         //  Delete Stock Table Current Year Closing Balance Data
                         Stock::where(['workspace_id' => $workspace_id, 'stock_type' => Config::get('common.balance_type_closing'), 'year' => CommonHelper::get_current_financial_year()])->delete();
                         // Delete Next Year Opening Balance Data
                         Stock::where(['workspace_id' => $workspace_id, 'stock_type' => Config::get('common.balance_type_opening'), 'year' => CommonHelper::get_next_financial_year()])->delete();
                         // Delete Stock Table Next Year Intermediate Balance Data
                         Stock::where(['workspace_id' => $workspace_id, 'stock_type' => Config::get('common.balance_type_intermediate'), 'year' => CommonHelper::get_next_financial_year()])->delete();
                         // Delete Account Closing Data
                         AccountClosing::where(['workspace_id' => $workspace_id, 'year' => CommonHelper::get_current_financial_year(), 'type' => 1])->delete();
                     } else {
                         Session()->flash('warning_message', 'Alert: Time Over!');
                         throw new \Exception('error');
                     }
                 } else {
                     Session()->flash('warning_message', 'Alert: Workspace Not Closed Yet!');
                     throw new \Exception('error');
                 }
             } else {
                 // Total System is being rolled back to the previous year
                 // Delete General Ledger Current Year Closing Data
                 GeneralLedger::where(['balance_type' => Config::get('common.balance_type_closing'), 'year' => CommonHelper::get_previous_financial_year()])->delete();
                 // Delete General Ledger Next Year Opening Data
                 GeneralLedger::where(['balance_type' => Config::get('common.balance_type_opening'), 'year' => CommonHelper::get_current_financial_year()])->delete();
                 // Delete General Journal Table Current Year Data
                 GeneralJournal::where(['year' => CommonHelper::get_current_financial_year()])->delete();
                 // Delete Account Closing Data
                 AccountClosing::where(['year' => CommonHelper::get_previous_financial_year(), 'type' => 2])->delete();
                 //  Delete Raw Stock Table Previous Year Closing Balance Data
                 RawStock::where(['stock_type' => Config::get('common.balance_type_closing'), 'year' => CommonHelper::get_previous_financial_year()])->delete();
                 //  Delete Raw Stock Table Current Year Opening Balance Data
                 RawStock::where(['stock_type' => Config::get('common.balance_type_opening'), 'year' => CommonHelper::get_current_financial_year()])->delete();
                 //  Delete Raw Stock Table Current Year Intermediate Balance Data
                 RawStock::where(['stock_type' => Config::get('common.balance_type_intermediate'), 'year' => CommonHelper::get_current_financial_year()])->delete();
                 // Workspaces Rollback
                 $workspaces = Workspace::where('status', '=', 1)->get();
                 foreach ($workspaces as $workspace) {
                     $workspace_id = $workspace->id;
                     // Delete Workspace Closing Balance Data of Current Year
                     WorkspaceLedger::where(['workspace_id' => $workspace_id, 'balance_type' => Config::get('common.balance_type_closing'), 'year' => CommonHelper::get_previous_financial_year()])->delete();
                     // Delete Next Year Opening Balance Data
                     WorkspaceLedger::where(['workspace_id' => $workspace_id, 'balance_type' => Config::get('common.balance_type_opening'), 'year' => CommonHelper::get_current_financial_year()])->delete();
                     // Delete Next Year Intermediate Balance Data
                     WorkspaceLedger::where(['workspace_id' => $workspace_id, 'balance_type' => Config::get('common.balance_type_intermediate'), 'year' => CommonHelper::get_current_financial_year()])->delete();
                     //  Delete Stock Table Current Year Closing Balance Data
                     Stock::where(['workspace_id' => $workspace_id, 'stock_type' => Config::get('common.balance_type_closing'), 'year' => CommonHelper::get_previous_financial_year()])->delete();
                     // Delete Next Year Opening Balance Data
                     Stock::where(['workspace_id' => $workspace_id, 'stock_type' => Config::get('common.balance_type_opening'), 'year' => CommonHelper::get_current_financial_year()])->delete();
                     // Delete Stock Table Next Year Intermediate Balance Data
                     Stock::where(['workspace_id' => $workspace_id, 'stock_type' => Config::get('common.balance_type_intermediate'), 'year' => CommonHelper::get_current_financial_year()])->delete();
                     // Delete Account Closing Data
                     AccountClosing::where(['workspace_id' => $workspace_id, 'year' => CommonHelper::get_previous_financial_year(), 'type' => 1])->delete();
                 }
                 // Fiscal Year Table Operations
                 $previous = CommonHelper::get_previous_financial_year();
                 $current = CommonHelper::get_current_financial_year();
                 // Previous Year Activate
                 DB::table('financial_years')->where('year', $previous)->update(['status' => 1]);
                 // Delete Current Financial Year
                 FinancialYear::where(['year' => $current])->delete();
             }
         });
     } catch (\Exception $e) {
         Session()->flash('error_message', 'Rollback not done!');
         return redirect('rollback');
     }
     Session()->flash('flash_message', 'Rollback Successfully done!');
     return redirect('rollback');
 }