Skip to content

Commit

Permalink
Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
rmnpawar committed Oct 10, 2021
1 parent 67405f9 commit 095b722
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CategoryController extends Controller
{

public function __construct()
{
//$this->middleware('auth:api');
Expand Down Expand Up @@ -62,7 +62,7 @@ public function products(Category $category)

public function allConsumables()
{
$categories = Category::select('id')->where('consumable', 1)->get();
$categories = Category::select('id')->where('type', 1)->get();

$plain_array = [];

Expand Down
14 changes: 13 additions & 1 deletion app/Http/Controllers/ConsumableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\ConsumableRequest;
use App\Service\ConsumableService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ConsumableController extends Controller
{
Expand All @@ -14,6 +15,17 @@ public function index()
return response()->json(Consumable::with('product')->get(), 200);
}

public function consumable_summary()
{
$summary = Consumable::join('products', 'products.id', '=', 'products_id')
->join('sub_categories', 'sub_categories.id', '=', 'products.sub_category_id')
->select('products.sub_category_id', 'sub_categories.name', DB::raw('SUM(balance) as balance'))
->groupBy('products.sub_category_id')
->get();

return response()->json($summary, 200);
}

public function store(Request $request)
{
$consumable = Consumable::create($request->all());
Expand Down Expand Up @@ -46,7 +58,7 @@ public function issueHistory(Request $request)
$query->where('section_id', $request->get('section_id'));
}

$issues = $query->where('status',3)->get()->map->format();
$issues = $query->where('status', 3)->get()->map->format();

return $issues;

Expand Down
16 changes: 13 additions & 3 deletions app/Http/Controllers/ProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function update(Request $request, Products $product)
$product->update($request->all());

return response()->json($product, 201);

}

public function destroy(Products $product)
Expand All @@ -42,8 +41,19 @@ public function destroy(Products $product)

public function consumables()
{
$consumables = Products::where(function($query) {

$consumables = Products::where(function ($query) {
})->get();
}

public function attach(Request $request, $id)
{

$product = Products::findOrFail($id);

$consumables = $request->post('consumables');

$product->consumables()->sync($consumables);

return response()->json(['successfull', 200]);
}
}
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
Route::delete('/{product}', 'ProductsController@destroy');

Route::get('/consumables', 'ProductsController@consumables');
Route::post('/consumables/{products_id}', 'ProductsController@attach');
});


Expand Down Expand Up @@ -111,6 +112,7 @@
Route::group(['prefix' => '/consumables'], function() {
Route::get('/', 'ConsumableController@index');
Route::post('/', 'ConsumableController@store');
Route::get('/summary', 'ConsumableController@consumable_summary');
Route::get('/history', 'ConsumableController@issueHistory');
Route::get('/for_id/{id}', 'ConsumableController@availableConsumables');
});
Expand Down

0 comments on commit 095b722

Please sign in to comment.