restaurant changes
This commit is contained in:
0
Modules/PurchaseEntry/app/Http/Controllers/.gitkeep
Normal file
0
Modules/PurchaseEntry/app/Http/Controllers/.gitkeep
Normal file
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PurchaseEntry\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Admin\Repositories\FieldInterface;
|
||||
use Modules\Supplier\Repositories\SupplierInterface;
|
||||
use Modules\Ingredient\Repositories\IngredientCategoryInterface;
|
||||
use Modules\Ingredient\Repositories\IngredientInterface;
|
||||
use Modules\Ingredient\Repositories\UnitInterface;
|
||||
use Modules\PurchaseEntry\Models\PurchaseEntry;
|
||||
use Modules\PurchaseEntry\Repositories\PurchaseEntryInterface;
|
||||
use Modules\Stock\Repositories\StockInterface;
|
||||
|
||||
class PurchaseEntryController extends Controller
|
||||
{
|
||||
|
||||
private $ingredientRepository;
|
||||
private $supplierRepository;
|
||||
private $purchaseEntryRepository;
|
||||
private $ingredientCategoryRepository;
|
||||
private $stockRepository;
|
||||
private $unitRepository;
|
||||
private $fieldRepository;
|
||||
|
||||
public function __construct( IngredientInterface $ingredientRepository,
|
||||
SupplierInterface $supplierRepository,
|
||||
PurchaseEntryInterface $purchaseEntryRepository,
|
||||
IngredientCategoryInterface $ingredientCategoryRepository,
|
||||
StockInterface $stockRepository,
|
||||
FieldInterface $fieldRepository,
|
||||
UnitInterface $unitRepository)
|
||||
{
|
||||
$this->ingredientRepository = $ingredientRepository;
|
||||
$this->unitRepository = $unitRepository;
|
||||
$this->supplierRepository = $supplierRepository;
|
||||
$this->purchaseEntryRepository = $purchaseEntryRepository;
|
||||
$this->ingredientCategoryRepository = $ingredientCategoryRepository;
|
||||
$this->stockRepository = $stockRepository;
|
||||
$this->fieldRepository = $fieldRepository;
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$filters = $request->all();
|
||||
$data['title'] = 'Purchase Entries';
|
||||
$data['stockList'] = $this->stockRepository->pluck();
|
||||
$data['ingredientList'] = $this->ingredientRepository->pluck();
|
||||
$data['ingredientCategoryList'] = $this->ingredientCategoryRepository->pluck();
|
||||
$data['purchaseEntries'] = $this->purchaseEntryRepository->findAll($filters);
|
||||
return view('purchaseEntry::purchaseEntry.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'New Purchase Entry';
|
||||
$data['stockList'] = $this->stockRepository->pluck();
|
||||
$data['unitList'] = $this->unitRepository->pluck();
|
||||
$data['ingredientList'] = $this->ingredientRepository->pluck();
|
||||
$data['ingredientCategoryList'] = $this->ingredientCategoryRepository->pluck();
|
||||
$data['supplierList'] = $this->supplierRepository->pluck();
|
||||
$data['sizes'] = $this->fieldRepository->getDropdownByAlias('size');
|
||||
$data['paymentModes'] = $this->fieldRepository->getDropdownByAlias('payment-mode');
|
||||
$data['editable'] = false;
|
||||
|
||||
return view('purchaseEntry::purchaseEntry.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->purchaseEntryRepository->create($request);
|
||||
|
||||
return redirect()->route('purchaseEntry.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('purchaseEntry::purchaseEntry.show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['supplierList'] = $this->supplierRepository->pluck();
|
||||
$data['ingredientCategoryList'] = $this->ingredientCategoryRepository->pluck();
|
||||
$data['stockList'] = $this->stockRepository->pluck();
|
||||
$data['unitList'] = $this->unitRepository->pluck();
|
||||
$data['ingredientList'] = $this->ingredientRepository->pluck();
|
||||
$data['sizes'] = $this->fieldRepository->getDropdownByAlias('size');
|
||||
$data['paymentModes'] = $this->fieldRepository->getDropdownByAlias('payment-mode');
|
||||
$data['order'] = PurchaseEntry::with('orderDetails')->find($id);
|
||||
$data['id'] = $id;
|
||||
$data['editable'] = true;
|
||||
$data['title'] = "Edit Purchase Entry";
|
||||
return view('purchaseEntry::purchaseEntry.edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$this->purchaseEntryRepository->update($id,$request);
|
||||
return redirect()->route('purchaseEntry.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
return $this->purchaseEntryRepository->delete($id);
|
||||
}
|
||||
|
||||
public function clonePurchaseIngredient(Request $request)
|
||||
{
|
||||
$data = [];
|
||||
$numInc = $request->numberInc;
|
||||
$script = true;
|
||||
$ingredientList= $this->ingredientRepository->pluck('id');
|
||||
$stockList= $this->stockRepository->pluck('id');
|
||||
$ingredientCategoryList= $this->ingredientCategoryRepository->pluck('id');
|
||||
$sizes = $this->fieldRepository->getDropdownByAlias('size');
|
||||
$paymentModes = $this->fieldRepository->getDropdownByAlias('payment-mode');
|
||||
|
||||
return response()->json([
|
||||
'view' => view('purchaseEntry::purchaseEntry.clone-product', compact('data', 'numInc', 'script', 'ingredientList', 'ingredientCategoryList', 'stockList', 'sizes', 'paymentModes'))->render(),
|
||||
]);
|
||||
}
|
||||
public function clonePurchaseProduct(Request $request)
|
||||
{
|
||||
$data = [];
|
||||
$numInc = $request->numberInc;
|
||||
$script = true;
|
||||
$ingredientList= $this->ingredientRepository->pluck('id');
|
||||
$stockList= $this->stockRepository->pluck('id');
|
||||
$unitList = $this->unitRepository->pluck('id');
|
||||
$ingredientCategoryList= $this->ingredientCategoryRepository->pluck('id');
|
||||
$sizes = $this->fieldRepository->getDropdownByAlias('size');
|
||||
$paymentModes = $this->fieldRepository->getDropdownByAlias('payment-mode');
|
||||
|
||||
return response()->json([
|
||||
'view' => view('purchaseEntry::purchaseEntry.clone-ingredient', compact('data', 'numInc', 'script', 'ingredientList', 'ingredientCategoryList', 'stockList', 'unitList', 'sizes', 'paymentModes'))->render(),
|
||||
]);
|
||||
}
|
||||
}
|
0
Modules/PurchaseEntry/app/Http/Requests/.gitkeep
Normal file
0
Modules/PurchaseEntry/app/Http/Requests/.gitkeep
Normal file
0
Modules/PurchaseEntry/app/Models/.gitkeep
Normal file
0
Modules/PurchaseEntry/app/Models/.gitkeep
Normal file
42
Modules/PurchaseEntry/app/Models/PurchaseEntry.php
Normal file
42
Modules/PurchaseEntry/app/Models/PurchaseEntry.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PurchaseEntry\Models;
|
||||
|
||||
use App\Traits\StatusTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Modules\Customer\Models\Customer;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Modules\PurchaseEntry\Models\PurchaseEntryDetail;
|
||||
use Modules\Supplier\Models\Supplier;
|
||||
|
||||
class PurchaseEntry extends Model
|
||||
{
|
||||
USE StatusTrait;
|
||||
|
||||
protected $table = 'tbl_purchaseentries';
|
||||
protected $fillable = [
|
||||
'supplier_id',
|
||||
'purchase_date',
|
||||
'payment',
|
||||
'paymentmode_id',
|
||||
'paymentref',
|
||||
'total_amt',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
protected $appends = ['status_name'];
|
||||
|
||||
|
||||
public function purchaseEntryDetails():HasMany{
|
||||
return $this->hasMany(PurchaseEntryDetail::class,'purchaseentry_id');
|
||||
}
|
||||
|
||||
public function supplier():BelongsTo{
|
||||
return $this->belongsTo(Supplier::class);
|
||||
}
|
||||
|
||||
public static function getFillableField(){
|
||||
return (new self())->fillable;
|
||||
}
|
||||
}
|
39
Modules/PurchaseEntry/app/Models/PurchaseEntryDetail.php
Normal file
39
Modules/PurchaseEntry/app/Models/PurchaseEntryDetail.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PurchaseEntry\Models;
|
||||
|
||||
use App\Traits\StatusTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Modules\PurchaseEntry\Models\PurchaseEntry;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Modules\Supplier\Models\Supplier;
|
||||
|
||||
|
||||
class PurchaseEntryDetail extends Model
|
||||
{
|
||||
USE StatusTrait;
|
||||
|
||||
protected $table = 'tbl_purchaseentrydetails';
|
||||
protected $fillable = [
|
||||
'purchaseentry_id',
|
||||
'product_id',
|
||||
'category_id',
|
||||
'stock_id',
|
||||
'size_id',
|
||||
'unit',
|
||||
'price',
|
||||
'rate',
|
||||
'quantity',
|
||||
'amount',
|
||||
'desc',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
protected $appends = ['status_name'];
|
||||
|
||||
|
||||
public function order(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PurchaseEntry::class);
|
||||
}
|
||||
}
|
0
Modules/PurchaseEntry/app/Observers/.gitkeep
Normal file
0
Modules/PurchaseEntry/app/Observers/.gitkeep
Normal file
0
Modules/PurchaseEntry/app/Providers/.gitkeep
Normal file
0
Modules/PurchaseEntry/app/Providers/.gitkeep
Normal file
32
Modules/PurchaseEntry/app/Providers/EventServiceProvider.php
Normal file
32
Modules/PurchaseEntry/app/Providers/EventServiceProvider.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PurchaseEntry\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event handler mappings for the application.
|
||||
*
|
||||
* @var array<string, array<int, string>>
|
||||
*/
|
||||
protected $listen = [];
|
||||
|
||||
/**
|
||||
* Indicates if events should be discovered.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $shouldDiscoverEvents = true;
|
||||
|
||||
/**
|
||||
* Configure the proper event listeners for email verification.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureEmailVerification(): void
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PurchaseEntry\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Ingredient\Repositories\IngredientCategoryInterface;
|
||||
use Modules\Ingredient\Repositories\IngredientCategoryRepository;
|
||||
use Modules\Ingredient\Repositories\IngredientInterface;
|
||||
use Modules\Ingredient\Repositories\IngredientRepository;
|
||||
use Modules\Ingredient\Repositories\UnitInterface;
|
||||
use Modules\Ingredient\Repositories\UnitRepository;
|
||||
use Modules\PurchaseEntry\Repositories\PurchaseEntryInterface;
|
||||
use Modules\PurchaseEntry\Repositories\PurchaseEntryRepository;
|
||||
|
||||
class PurchaseEntryServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'PurchaseEntry';
|
||||
|
||||
protected string $moduleNameLower = 'purchaseEntry';
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerCommands();
|
||||
$this->registerCommandSchedules();
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(EventServiceProvider::class);
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->app->bind(PurchaseEntryInterface::class, PurchaseEntryRepository::class);
|
||||
$this->app->bind(IngredientInterface::class, IngredientRepository::class);
|
||||
$this->app->bind(UnitInterface::class, UnitRepository::class);
|
||||
$this->app->bind(IngredientCategoryInterface::class, IngredientCategoryRepository::class);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands in the format of Command::class
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
// $this->commands([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register command Schedules.
|
||||
*/
|
||||
protected function registerCommandSchedules(): void
|
||||
{
|
||||
// $this->app->booted(function () {
|
||||
// $schedule = $this->app->make(Schedule::class);
|
||||
// $schedule->command('inspire')->hourly();
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*/
|
||||
public function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom($langPath);
|
||||
} else {
|
||||
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
|
||||
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*/
|
||||
public function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
|
||||
$sourcePath = module_path($this->moduleName, 'resources/views');
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']);
|
||||
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
|
||||
|
||||
$componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
|
||||
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (config('view.paths') as $path) {
|
||||
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
|
||||
$paths[] = $path.'/modules/'.$this->moduleNameLower;
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
49
Modules/PurchaseEntry/app/Providers/RouteServiceProvider.php
Normal file
49
Modules/PurchaseEntry/app/Providers/RouteServiceProvider.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PurchaseEntry\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*/
|
||||
public function map(): void
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*/
|
||||
protected function mapWebRoutes(): void
|
||||
{
|
||||
Route::middleware('web')->group(module_path('PurchaseEntry', '/routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('PurchaseEntry', '/routes/api.php'));
|
||||
}
|
||||
}
|
0
Modules/PurchaseEntry/app/Repositories/.gitkeep
Normal file
0
Modules/PurchaseEntry/app/Repositories/.gitkeep
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PurchaseEntry\Repositories;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
interface PurchaseEntryInterface
|
||||
{
|
||||
public function findAll($filters);
|
||||
public function getPurchaseEntryById($PurchaseEntryId);
|
||||
public function getPurchaseEntryByEmail($email);
|
||||
public function delete($PurchaseEntryId);
|
||||
public function create(Request $request);
|
||||
public function update($PurchaseEntryId, Request $request);
|
||||
public function pluck();
|
||||
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PurchaseEntry\Repositories;
|
||||
|
||||
use Flasher\Laravel\Http\Request;
|
||||
use Modules\PurchaseEntry\Models\PurchaseEntry;
|
||||
use Modules\PurchaseEntry\Models\PurchaseEntryDetail;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PurchaseEntryRepository implements PurchaseEntryInterface
|
||||
{
|
||||
// public function findAll()
|
||||
// {
|
||||
// return PurchaseEntry::when(true, function ($query) {
|
||||
// })->paginate(20);
|
||||
// }
|
||||
public function findAll($filters = [], $limit = null, $offset = null)
|
||||
{
|
||||
return PurchaseEntry::when($filters, function ($query) use ($filters) {
|
||||
|
||||
if (isset($filters["ingredient_category_id"])) {
|
||||
$query->whereHas('purchaseEntryDetails', function ( $query) use ($filters) {
|
||||
$query->where('ingredient_category_id', '=', $filters["ingredient_category_id"]);
|
||||
});
|
||||
}
|
||||
if (isset($filters["ingredient_id"])) {
|
||||
$query->whereHas('purchaseEntryDetails', function ( $query) use ($filters) {
|
||||
$query->where('ingredient_id', '=', $filters["ingredient_id"]);
|
||||
});
|
||||
}
|
||||
// if (isset($filters["stock_id"])) {
|
||||
// $query->whereHas('purchaseEntryDetails', function ( $query) use ($filters) {
|
||||
// $query->where('stock_id', '=', $filters["stock_id"]);
|
||||
// });
|
||||
// }
|
||||
|
||||
if (isset($filters["date"])) {
|
||||
$explodeDate = explode("to", $filters['date']);
|
||||
$query->whereBetween("purchase_date", [$explodeDate[0], preg_replace('/\s+/', '', $explodeDate[1])]);
|
||||
}
|
||||
|
||||
})->get();
|
||||
}
|
||||
|
||||
public function getPurchaseEntryById($PurchaseEntryId)
|
||||
{
|
||||
return PurchaseEntry::findOrFail($PurchaseEntryId);
|
||||
}
|
||||
|
||||
public function getPurchaseEntryByEmail($email)
|
||||
{
|
||||
return PurchaseEntry::where('email', $email)->first();
|
||||
}
|
||||
|
||||
public function delete($PurchaseEntryId)
|
||||
{
|
||||
DB::transaction(function() use ($PurchaseEntryId) {
|
||||
PurchaseEntryDetail::where('purchaseentry_id', $PurchaseEntryId)->delete();
|
||||
|
||||
PurchaseEntry::destroy($PurchaseEntryId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function create($request)
|
||||
{
|
||||
$purchaseEntryDetails = $request->except(PurchaseEntry::getFillableField());
|
||||
|
||||
$purchaseEntry = $request->only(PurchaseEntry::getFillableField());
|
||||
$purchaseEntryData = PurchaseEntry::create($purchaseEntry);
|
||||
|
||||
$request->merge(['purchaseentry_id' => $purchaseEntryData->id]);
|
||||
|
||||
foreach ($purchaseEntryDetails['ingredient_id'] as $key => $ingredientId) {
|
||||
// dd($request->input('purchaseentry_id'));
|
||||
$data = [
|
||||
'purchaseentry_id' => $request->input('purchaseentry_id'),
|
||||
'ingredient_id' => $purchaseEntryDetails['ingredient_id'][$key],
|
||||
'ingredient_category_id' => $purchaseEntryDetails['ingredient_category_id'][$key],
|
||||
// 'stock_id' => $purchaseEntryDetails['stock_id'][$key],
|
||||
// 'size_id' => $purchaseEntryDetails['size_id'][$key],
|
||||
'rate' => $purchaseEntryDetails['price'][$key],
|
||||
'unit_id' => $purchaseEntryDetails['unit_id'][$key],
|
||||
'quantity' => $purchaseEntryDetails['qty'][$key],
|
||||
'amount' => $purchaseEntryDetails['amt'][$key],
|
||||
'desc' => $purchaseEntryDetails['desc'][$key],
|
||||
];
|
||||
PurchaseEntryDetail::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function update($PurchaseEntryId, $request)
|
||||
{
|
||||
$fillableFields = PurchaseEntry::getFillableField();
|
||||
$purchaseEntryData = $request->only($fillableFields);
|
||||
|
||||
$purchaseEntry = PurchaseEntry::find($PurchaseEntryId);
|
||||
$purchaseEntry->update($purchaseEntryData);
|
||||
|
||||
|
||||
$additionalExcludes = ['_method', '_token'];
|
||||
$excludeFields = array_merge($fillableFields, $additionalExcludes);
|
||||
|
||||
$data = $request->except($excludeFields);
|
||||
|
||||
$updatedCombinations = [];
|
||||
|
||||
if (isset($data['product_id'])) {
|
||||
foreach ($data['product_id'] as $key => $productId) {
|
||||
$obj = [
|
||||
'purchaseentry_id' => $PurchaseEntryId,
|
||||
'product_id' => $productId,
|
||||
'unit' => $data['unit'][$key],
|
||||
'rate' => $data['rate'][$key],
|
||||
'quantity' => $data['qty'][$key],
|
||||
'amount' => $data['amt'][$key],
|
||||
'desc' => $data['desc'][$key],
|
||||
];
|
||||
|
||||
$combinationKey = "{$PurchaseEntryId}_{$productId}_{$data['unit'][$key]}";
|
||||
|
||||
$purchaseEntryDetail = $purchaseEntry->purchaseEntryDetails()->where('product_id', $productId)->where('unit', $data['unit'][$key])->first();
|
||||
if ($purchaseEntryDetail) {
|
||||
$purchaseEntryDetail->update($obj);
|
||||
} else {
|
||||
PurchaseEntryDetail::create($obj);
|
||||
}
|
||||
|
||||
$updatedCombinations[] = $combinationKey;
|
||||
}
|
||||
}
|
||||
|
||||
$purchaseEntry->purchaseEntryDetails()->each(function ($purchaseEntryDetail) use ($updatedCombinations) {
|
||||
$combinationKey = "{$purchaseEntryDetail->purchaseEntry_id}_{$purchaseEntryDetail->product_id}_{$purchaseEntryDetail->unit}";
|
||||
if (!in_array($combinationKey, $updatedCombinations)) {
|
||||
$purchaseEntryDetail->delete();
|
||||
}
|
||||
});
|
||||
|
||||
return $purchaseEntry;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function pluck()
|
||||
{
|
||||
return PurchaseEntry::pluck('name', 'id');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user