From 41815b9af62b40997505f8a5bbb0299a403e6d32 Mon Sep 17 00:00:00 2001 From: srivastava-jyoti Date: Tue, 17 Sep 2024 13:23:13 +0530 Subject: [PATCH 01/16] crecated table --- ...ate_library_book_location_copies_table.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 database/migrations/2024_09_17_125527_create_library_book_location_copies_table.php diff --git a/database/migrations/2024_09_17_125527_create_library_book_location_copies_table.php b/database/migrations/2024_09_17_125527_create_library_book_location_copies_table.php new file mode 100644 index 0000000000..ed76116d08 --- /dev/null +++ b/database/migrations/2024_09_17_125527_create_library_book_location_copies_table.php @@ -0,0 +1,39 @@ +id(); + $table->unsignedInteger('book_id'); + $table->unsignedBigInteger('office_location_id'); + $table->integer('number_of_copies'); + $table->timestamps(); + }); + + Schema::table('library_book_location', function (Blueprint $table) { + $table->foreign('book_id')->references('id')->on('library_books'); + $table->foreign('office_location_id')->references('id')->on('office_locations'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('library_book_location'); + } +} From 30f061c8ba9a028df1a345b009a6f50c8645400b Mon Sep 17 00:00:00 2001 From: srivastava-jyoti Date: Tue, 17 Sep 2024 13:51:42 +0530 Subject: [PATCH 02/16] created model --- .../Operations/Entities/OfficeLocation.php | 6 +++++ app/Models/KnowledgeCafe/Library/Book.php | 6 +++++ .../KnowledgeCafe/Library/BookLocation.php | 26 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 app/Models/KnowledgeCafe/Library/BookLocation.php diff --git a/Modules/Operations/Entities/OfficeLocation.php b/Modules/Operations/Entities/OfficeLocation.php index 52ee7b704b..10a625847d 100644 --- a/Modules/Operations/Entities/OfficeLocation.php +++ b/Modules/Operations/Entities/OfficeLocation.php @@ -2,6 +2,7 @@ namespace Modules\Operations\Entities; +use App\Models\KnowledgeCafe\Library\BookLocation; use Illuminate\Database\Eloquent\Model; use Modules\User\Entities\User; @@ -13,4 +14,9 @@ public function centreHead() { return $this->belongsTo(User::class, 'centre_head_id'); } + + public function locationOfBook() + { + return $this->hasMany(BookLocation::class, 'office_loaction_id'); + } } diff --git a/app/Models/KnowledgeCafe/Library/Book.php b/app/Models/KnowledgeCafe/Library/Book.php index 6fc510e7d2..85181bcc24 100644 --- a/app/Models/KnowledgeCafe/Library/Book.php +++ b/app/Models/KnowledgeCafe/Library/Book.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Modules\User\Entities\User; +use App\Models\KnowledgeCafe\Library\BookLocation; class Book extends Model { @@ -174,4 +175,9 @@ public function bookAMonths() { return $this->hasMany(BookAMonth::class, 'library_book_id'); } + + public function bookLocations() + { + return $this->hasMany(BookLocation::class, 'book_id'); + } } diff --git a/app/Models/KnowledgeCafe/Library/BookLocation.php b/app/Models/KnowledgeCafe/Library/BookLocation.php new file mode 100644 index 0000000000..3ee47579f5 --- /dev/null +++ b/app/Models/KnowledgeCafe/Library/BookLocation.php @@ -0,0 +1,26 @@ +hasOne(Book::class, 'id', 'book_id'); + } + + public function location() + { + return $this->hasOne(OfficeLocation::class, 'id', 'office_loaction_id'); + } +} \ No newline at end of file From 5fba0814526e2fc7e97bed0c2e8c517900d0386d Mon Sep 17 00:00:00 2001 From: srivastava-jyoti Date: Sat, 21 Sep 2024 13:47:23 +0530 Subject: [PATCH 03/16] wip --- .../KnowledgeCafe/Library/BookController.php | 31 +++++++++++++++++-- resources/js/app.js | 3 ++ .../library/books/info.blade.php | 20 +++++++++--- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/KnowledgeCafe/Library/BookController.php b/app/Http/Controllers/KnowledgeCafe/Library/BookController.php index 7760eb619d..536baa091b 100644 --- a/app/Http/Controllers/KnowledgeCafe/Library/BookController.php +++ b/app/Http/Controllers/KnowledgeCafe/Library/BookController.php @@ -7,6 +7,8 @@ use App\Models\KnowledgeCafe\Library\Book; use App\Models\KnowledgeCafe\Library\BookAMonth; use App\Models\KnowledgeCafe\Library\BookCategory; +use App\Models\KnowledgeCafe\Library\BookLocation; +use Modules\Operations\Entities\OfficeLocation; use App\Services\BookServices; use Carbon\Carbon; use Illuminate\Http\Request; @@ -59,9 +61,19 @@ public function index(Request $request) */ public function create() { - return view('knowledgecafe.library.books.create'); + $officeLocations = OfficeLocation::all(); + $officeLocationsData = $officeLocations->map(function ($officeLocation) { + return [ + 'center_id' => $officeLocation->id, + 'centre_name' => $officeLocation->centre_name, + ]; + }); + return view('knowledgecafe.library.books.create', [ + 'officeLocations' => $officeLocationsData, + ]); } + /** * Store a newly created resource in storage. * @@ -72,7 +84,6 @@ public function store(BookRequest $request) $validatedData = $request->validated(); $ISBN = $validatedData['isbn'] ?? null; Book::firstOrCreate(['isbn' => $ISBN], $validatedData); - return response()->json(['error' => false]); } @@ -342,4 +353,20 @@ public function bookAMonthIndex() 'booksBorrowedCount' => $booksBorrowedCount, ]); } + + public function storeBookLocationWise() + { + $locationCopiesData = [ + 1 => "7", + 2 => "8" + ]; + + foreach ($locationCopiesData as $locationId => $copies) { + BookLocation::create([ + 'book_id' => 1, + 'office_location_id' => $locationId, + 'number_of_copies' => $copies + ]); + } + } } diff --git a/resources/js/app.js b/resources/js/app.js index a7fb6212b1..89a670443c 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -748,6 +748,8 @@ if (document.getElementById("show_and_save_book")) { addMethod: "from_isbn", showInfo: false, book: {}, + copies: {}, + // officeLocations: @json($officeLocations), number_of_copies: 1, routes: { index: document.getElementById("show_book").dataset.indexRoute || "", @@ -806,6 +808,7 @@ if (document.getElementById("show_and_save_book")) { }, saveBookToRecords: function() { + console.log(this.copies, "officeLocations"); if (!this.book) { alert("Error in saving records"); } diff --git a/resources/views/knowledgecafe/library/books/info.blade.php b/resources/views/knowledgecafe/library/books/info.blade.php index 20ab849f1c..22a7f032a1 100644 --- a/resources/views/knowledgecafe/library/books/info.blade.php +++ b/resources/views/knowledgecafe/library/books/info.blade.php @@ -4,7 +4,7 @@ @{{ book.title }}
-
+
@@ -42,13 +42,23 @@
-
- -
+ @if($officeLocations) + @foreach ($officeLocations as $officeLocation) +
+ {{ $officeLocation['centre_name'] }} + + +
+ @endforeach + @endif
-
+
From 1ccf77dea572ac7e371db364f70f343f4c20cc33 Mon Sep 17 00:00:00 2001 From: srivastava-jyoti Date: Sat, 21 Sep 2024 17:31:03 +0530 Subject: [PATCH 04/16] wip --- Modules/Operations/Entities/OfficeLocation.php | 2 +- .../KnowledgeCafe/Library/BookController.php | 4 ++-- app/Models/KnowledgeCafe/Library/BookLocation.php | 2 +- .../views/knowledgecafe/library/books/index.blade.php | 11 ++++++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Modules/Operations/Entities/OfficeLocation.php b/Modules/Operations/Entities/OfficeLocation.php index 10a625847d..501999b40d 100644 --- a/Modules/Operations/Entities/OfficeLocation.php +++ b/Modules/Operations/Entities/OfficeLocation.php @@ -17,6 +17,6 @@ public function centreHead() public function locationOfBook() { - return $this->hasMany(BookLocation::class, 'office_loaction_id'); + return $this->hasMany(BookLocation::class, 'office_location_id'); } } diff --git a/app/Http/Controllers/KnowledgeCafe/Library/BookController.php b/app/Http/Controllers/KnowledgeCafe/Library/BookController.php index 536baa091b..c47040af87 100644 --- a/app/Http/Controllers/KnowledgeCafe/Library/BookController.php +++ b/app/Http/Controllers/KnowledgeCafe/Library/BookController.php @@ -31,7 +31,7 @@ public function index(Request $request) $searchCategory = $request->category_name ?? false; $searchString = request()->has('search') ? request()->input('search') : false; $categories = BookCategory::orderBy('name')->get(); - + $bookLocations = BookLocation::withTrashed()->with('location')->get(); switch (request()) { case request()->has('wishlist'): $books = auth()->user()->booksInWishlist; @@ -51,7 +51,7 @@ public function index(Request $request) $wishlistedBooksCount = auth()->user()->booksInWishlist->count(); $booksBorrowedCount = auth()->user()->booksBorrower->count(); - return view('knowledgecafe.library.books.index', compact('books', 'loggedInUser', 'categories', 'wishlistedBooksCount', 'booksBorrowedCount')); + return view('knowledgecafe.library.books.index', compact('books', 'loggedInUser', 'categories', 'wishlistedBooksCount', 'booksBorrowedCount', 'bookLocations')); } /** diff --git a/app/Models/KnowledgeCafe/Library/BookLocation.php b/app/Models/KnowledgeCafe/Library/BookLocation.php index 3ee47579f5..01425c254a 100644 --- a/app/Models/KnowledgeCafe/Library/BookLocation.php +++ b/app/Models/KnowledgeCafe/Library/BookLocation.php @@ -21,6 +21,6 @@ public function book() public function location() { - return $this->hasOne(OfficeLocation::class, 'id', 'office_loaction_id'); + return $this->hasOne(OfficeLocation::class, 'id', 'office_location_id'); } } \ No newline at end of file diff --git a/resources/views/knowledgecafe/library/books/index.blade.php b/resources/views/knowledgecafe/library/books/index.blade.php index cf52da129d..0007a7ccd3 100644 --- a/resources/views/knowledgecafe/library/books/index.blade.php +++ b/resources/views/knowledgecafe/library/books/index.blade.php @@ -5,7 +5,7 @@ Loading...
-
+
@include('status', ['errors' => $errors->all()])
@@ -101,6 +101,15 @@
+
+ @foreach ($bookLocations as $bookLocation) +
+ @if($bookLocation->number_of_copies!==0 ) + {{($bookLocation->location->centre_name)}}: {{$bookLocation->number_of_copies}} + @endif +
+ @endforeach +

Read by

From d7d5d7db0ba4b485a72dc24bfea09c813ca81a31 Mon Sep 17 00:00:00 2001 From: srivastava-jyoti Date: Wed, 2 Oct 2024 14:24:35 +0530 Subject: [PATCH 05/16] added copies --- .../KnowledgeCafe/Library/BookController.php | 19 ++++++++++--------- .../KnowledgeCafe/Library/BookRequest.php | 1 + resources/js/app.js | 4 +--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/KnowledgeCafe/Library/BookController.php b/app/Http/Controllers/KnowledgeCafe/Library/BookController.php index c47040af87..f61b2d80bb 100644 --- a/app/Http/Controllers/KnowledgeCafe/Library/BookController.php +++ b/app/Http/Controllers/KnowledgeCafe/Library/BookController.php @@ -83,8 +83,13 @@ public function store(BookRequest $request) { $validatedData = $request->validated(); $ISBN = $validatedData['isbn'] ?? null; - Book::firstOrCreate(['isbn' => $ISBN], $validatedData); - return response()->json(['error' => false]); + $copiesLocation = $validatedData['copies']; + $book = Book::firstOrCreate(['isbn' => $ISBN], $validatedData); + $this->storeBookLocationWise($book->id, $copiesLocation); + return response()->json([ + 'error' => false, + 'book_id' => $book->id + ]); } /** @@ -354,16 +359,12 @@ public function bookAMonthIndex() ]); } - public function storeBookLocationWise() + public function storeBookLocationWise($bookId, $copiesLocation) { - $locationCopiesData = [ - 1 => "7", - 2 => "8" - ]; - + $locationCopiesData = $copiesLocation; foreach ($locationCopiesData as $locationId => $copies) { BookLocation::create([ - 'book_id' => 1, + 'book_id' => $bookId, 'office_location_id' => $locationId, 'number_of_copies' => $copies ]); diff --git a/app/Http/Requests/KnowledgeCafe/Library/BookRequest.php b/app/Http/Requests/KnowledgeCafe/Library/BookRequest.php index 9a619bb066..7c203ef3d2 100644 --- a/app/Http/Requests/KnowledgeCafe/Library/BookRequest.php +++ b/app/Http/Requests/KnowledgeCafe/Library/BookRequest.php @@ -34,6 +34,7 @@ public function rules() 'self_link' => 'nullable|string', 'number_of_copies' => 'nullable|integer|gte:1', 'on_kindle' => 'nullable', + 'copies' => 'nullable', ]; } } diff --git a/resources/js/app.js b/resources/js/app.js index 89a670443c..b36eb005ff 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -749,8 +749,6 @@ if (document.getElementById("show_and_save_book")) { showInfo: false, book: {}, copies: {}, - // officeLocations: @json($officeLocations), - number_of_copies: 1, routes: { index: document.getElementById("show_book").dataset.indexRoute || "", fetch: document.getElementById("book_form").dataset.actionRoute || "", @@ -808,7 +806,6 @@ if (document.getElementById("show_and_save_book")) { }, saveBookToRecords: function() { - console.log(this.copies, "officeLocations"); if (!this.book) { alert("Error in saving records"); } @@ -817,6 +814,7 @@ if (document.getElementById("show_and_save_book")) { this.book["on_kindle"] = document.getElementById("on_kindle").checked ? 1 : 0; + this.book.copies = this.copies; axios.post(this.routes.store, this.book).then((response) => { this.buttons.disableSaveButton = false; From dfdd162b402ec55996456ad2f260233d95ff3716 Mon Sep 17 00:00:00 2001 From: srivastava-jyoti Date: Wed, 2 Oct 2024 15:33:37 +0530 Subject: [PATCH 06/16] wip --- resources/views/knowledgecafe/library/books/index.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/knowledgecafe/library/books/index.blade.php b/resources/views/knowledgecafe/library/books/index.blade.php index 0007a7ccd3..32de3f102f 100644 --- a/resources/views/knowledgecafe/library/books/index.blade.php +++ b/resources/views/knowledgecafe/library/books/index.blade.php @@ -57,7 +57,7 @@ @endif
-
+
From 33db6cf76cf39880155c502ed6affacb18dc334c Mon Sep 17 00:00:00 2001 From: srivastava-jyoti Date: Thu, 3 Oct 2024 18:02:36 +0530 Subject: [PATCH 07/16] wip --- .../KnowledgeCafe/Library/BookController.php | 24 ++++++++++++------- .../library/books/index.blade.php | 13 +++++++++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/KnowledgeCafe/Library/BookController.php b/app/Http/Controllers/KnowledgeCafe/Library/BookController.php index f61b2d80bb..9d62d3f84b 100644 --- a/app/Http/Controllers/KnowledgeCafe/Library/BookController.php +++ b/app/Http/Controllers/KnowledgeCafe/Library/BookController.php @@ -50,8 +50,9 @@ public function index(Request $request) $books->load('borrowers'); $wishlistedBooksCount = auth()->user()->booksInWishlist->count(); $booksBorrowedCount = auth()->user()->booksBorrower->count(); + $officeLocations = $this->officeLocationData(); - return view('knowledgecafe.library.books.index', compact('books', 'loggedInUser', 'categories', 'wishlistedBooksCount', 'booksBorrowedCount', 'bookLocations')); + return view('knowledgecafe.library.books.index', compact('books', 'loggedInUser', 'categories', 'wishlistedBooksCount', 'booksBorrowedCount', 'bookLocations', 'officeLocations')); } /** @@ -61,15 +62,8 @@ public function index(Request $request) */ public function create() { - $officeLocations = OfficeLocation::all(); - $officeLocationsData = $officeLocations->map(function ($officeLocation) { - return [ - 'center_id' => $officeLocation->id, - 'centre_name' => $officeLocation->centre_name, - ]; - }); return view('knowledgecafe.library.books.create', [ - 'officeLocations' => $officeLocationsData, + 'officeLocations' => $this->officeLocationData(), ]); } @@ -370,4 +364,16 @@ public function storeBookLocationWise($bookId, $copiesLocation) ]); } } + + public function officeLocationData() + { + $officeLocations = OfficeLocation::all(); + $officeLocationsData = $officeLocations->map(function ($officeLocation) { + return [ + 'center_id' => $officeLocation->id, + 'centre_name' => $officeLocation->centre_name, + ]; + }); + return $officeLocationsData; + } } diff --git a/resources/views/knowledgecafe/library/books/index.blade.php b/resources/views/knowledgecafe/library/books/index.blade.php index 32de3f102f..6128b41549 100644 --- a/resources/views/knowledgecafe/library/books/index.blade.php +++ b/resources/views/knowledgecafe/library/books/index.blade.php @@ -93,7 +93,18 @@
- + {{-- --}} + - {{-- --}} - --}} - - {{--
@endif -
+
@@ -68,7 +68,8 @@

On Kindle

-

@{{ book.number_of_copies }}

+

@{{ getTotalCopies(book.id) }}

+
@can('library_books.delete')
@@ -162,4 +163,4 @@
@include('knowledgecafe.library.books.update-category-modal')
-@endsection \ No newline at end of file +@endsection From 946411ad4da0249a1c991f895aa12e5fbf97ecb4 Mon Sep 17 00:00:00 2001 From: srivastava-jyoti Date: Wed, 9 Oct 2024 12:43:02 +0530 Subject: [PATCH 11/16] added copies --- resources/js/app.js | 4 ++++ .../knowledgecafe/library/books/index.blade.php | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/resources/js/app.js b/resources/js/app.js index adf7d7e22e..969fa49315 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -971,6 +971,10 @@ if (document.getElementById("books_listing")) { allCategoryInputs.forEach( (checkbox) => (this.categoryInputs[checkbox.value] = checkbox) ); + let locationsData = document.getElementById("books_table").dataset.locationData; + if (locationsData) { + this.copies = JSON.parse(locationsData); + } }, }); } diff --git a/resources/views/knowledgecafe/library/books/index.blade.php b/resources/views/knowledgecafe/library/books/index.blade.php index a06abe429a..5f87190103 100644 --- a/resources/views/knowledgecafe/library/books/index.blade.php +++ b/resources/views/knowledgecafe/library/books/index.blade.php @@ -55,7 +55,7 @@
@endif -
+
@@ -164,3 +164,16 @@ @include('knowledgecafe.library.books.update-category-modal')
@endsection + + From b6718877088e67c9c4fe49309efed7e5f1827b1d Mon Sep 17 00:00:00 2001 From: srivastava-jyoti Date: Wed, 9 Oct 2024 13:39:17 +0530 Subject: [PATCH 12/16] wip --- .../views/knowledgecafe/library/books/index.blade.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/views/knowledgecafe/library/books/index.blade.php b/resources/views/knowledgecafe/library/books/index.blade.php index 5f87190103..6693285ad5 100644 --- a/resources/views/knowledgecafe/library/books/index.blade.php +++ b/resources/views/knowledgecafe/library/books/index.blade.php @@ -55,9 +55,10 @@
@endif -
+
-
+
{{-- --}} -