name file |
size |
edit |
permission |
action |
.env | 2733 KB | December 22 2024 06:20:07 | 0644 |
|
404.html | 58370 KB | November 20 2024 15:32:22 | 0644 |
|
502.html | 58368 KB | November 20 2024 15:32:22 | 0644 |
|
Modules | - | December 11 2024 21:02:56 | 0755 |
|
README.md | 4158 KB | February 14 2023 12:31:56 | 0644 |
|
app | - | December 11 2024 17:57:48 | 0755 |
|
artisan | 1686 KB | February 14 2023 12:31:56 | 0644 |
|
bootstrap | - | December 11 2024 20:23:36 | 0755 |
|
composer.json | 3761 KB | December 11 2024 22:15:00 | 0644 |
|
composer.lock | 512048 KB | December 11 2024 22:13:28 | 0644 |
|
config | - | June 15 2025 02:09:36 | 0755 |
|
database | - | December 05 2024 20:18:12 | 0755 |
|
dfsdf dfds fd fds findex.html | 1420 KB | November 20 2024 15:32:24 | 0644 |
|
error_log | 15227159 KB | July 18 2025 16:55:40 | 0644 |
|
firoz | - | December 23 2024 13:24:46 | 0755 |
|
index.php | 1667 KB | December 14 2024 05:20:36 | 0644 |
|
lang | - | December 11 2024 21:02:48 | 0755 |
|
modules_statuses.json | 472 KB | November 20 2024 15:32:24 | 0644 |
|
mpos | - | March 31 2025 02:36:31 | 0755 |
|
package.json | 226 KB | February 14 2023 12:31:56 | 0644 |
|
phpunit.xml | 1146 KB | February 14 2023 12:31:56 | 0644 |
|
public | - | March 31 2025 02:36:31 | 0755 |
|
resources | - | December 11 2024 21:10:22 | 0755 |
|
routes | - | June 15 2025 02:09:31 | 0755 |
|
storage | - | December 11 2024 21:12:44 | 0755 |
|
tests | - | December 05 2024 20:18:12 | 0755 |
|
vendor | - | December 11 2024 22:13:30 | 0755 |
|
vite.config.js | 263 KB | February 14 2023 12:31:56 | 0644 |
|
@format_currency($min_purchase_price) @if($max_purchase_price != $min_purchase_price && $type == "variable") - @format_currency($max_purchase_price)@endif
'
)
->addColumn(
'selling_price',
'@format_currency($min_price) @if($max_price != $min_price && $type == "variable") - @format_currency($max_price)@endif
'
)
->filterColumn('products.sku', function ($query, $keyword) {
$query->whereHas('variations', function ($q) use ($keyword) {
$q->where('sub_sku', 'like', "%{$keyword}%");
})
->orWhere('products.sku', 'like', "%{$keyword}%");
})
->setRowAttr([
'data-href' => function ($row) {
if (auth()->user()->can('product.view')) {
return action([\App\Http\Controllers\ProductController::class, 'view'], [$row->id]);
} else {
return '';
}
}, ])
->rawColumns(['action', 'image', 'mass_delete', 'product', 'selling_price', 'purchase_price', 'category', 'current_stock'])
->make(true);
}
$rack_enabled = (request()->session()->get('business.enable_racks') || request()->session()->get('business.enable_row') || request()->session()->get('business.enable_position'));
$categories = Category::forDropdown($business_id, 'product');
$brands = Brands::forDropdown($business_id);
$units = Unit::forDropdown($business_id);
$tax_dropdown = TaxRate::forBusinessDropdown($business_id, false);
$taxes = $tax_dropdown['tax_rates'];
$business_locations = BusinessLocation::forDropdown($business_id);
$business_locations->prepend(__('lang_v1.none'), 'none');
if ($this->moduleUtil->isModuleInstalled('Manufacturing') && (auth()->user()->can('superadmin') || $this->moduleUtil->hasThePermissionInSubscription($business_id, 'manufacturing_module'))) {
$show_manufacturing_data = true;
} else {
$show_manufacturing_data = false;
}
//list product screen filter from module
$pos_module_data = $this->moduleUtil->getModuleData('get_filters_for_list_product_screen');
$is_admin = $this->productUtil->is_admin(auth()->user());
return view('product.index')
->with(compact(
'rack_enabled',
'categories',
'brands',
'units',
'taxes',
'business_locations',
'show_manufacturing_data',
'pos_module_data',
'is_woocommerce',
'is_admin'
));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
if (! auth()->user()->can('product.create')) {
abort(403, 'Unauthorized action.');
}
$business_id = request()->session()->get('user.business_id');
//Check if subscribed or not, then check for products quota
if (! $this->moduleUtil->isSubscribed($business_id)) {
return $this->moduleUtil->expiredResponse();
} elseif (! $this->moduleUtil->isQuotaAvailable('products', $business_id)) {
return $this->moduleUtil->quotaExpiredResponse('products', $business_id, action([\App\Http\Controllers\ProductController::class, 'index']));
}
$categories = Category::forDropdown($business_id, 'product');
$brands = Brands::forDropdown($business_id);
$units = Unit::forDropdown($business_id, true);
$tax_dropdown = TaxRate::forBusinessDropdown($business_id, true, true);
$taxes = $tax_dropdown['tax_rates'];
$tax_attributes = $tax_dropdown['attributes'];
$barcode_types = $this->barcode_types;
$barcode_default = $this->productUtil->barcode_default();
$default_profit_percent = request()->session()->get('business.default_profit_percent');
//Get all business locations
$business_locations = BusinessLocation::forDropdown($business_id);
//Duplicate product
$duplicate_product = null;
$rack_details = null;
$sub_categories = [];
if (! empty(request()->input('d'))) {
$duplicate_product = Product::where('business_id', $business_id)->find(request()->input('d'));
$duplicate_product->name .= ' (copy)';
if (! empty($duplicate_product->category_id)) {
$sub_categories = Category::where('business_id', $business_id)
->where('parent_id', $duplicate_product->category_id)
->pluck('name', 'id')
->toArray();
}
//Rack details
if (! empty($duplicate_product->id)) {
$rack_details = $this->productUtil->getRackDetails($business_id, $duplicate_product->id);
}
}
$selling_price_group_count = SellingPriceGroup::countSellingPriceGroups($business_id);
$module_form_parts = $this->moduleUtil->getModuleData('product_form_part');
$product_types = $this->product_types();
$common_settings = session()->get('business.common_settings');
$warranties = Warranty::forDropdown($business_id);
//product screen view from module
$pos_module_data = $this->moduleUtil->getModuleData('get_product_screen_top_view');
return view('product.create')
->with(compact('categories', 'brands', 'units', 'taxes', 'barcode_types', 'default_profit_percent', 'tax_attributes', 'barcode_default', 'business_locations', 'duplicate_product', 'sub_categories', 'rack_details', 'selling_price_group_count', 'module_form_parts', 'product_types', 'common_settings', 'warranties', 'pos_module_data'));
}
private function product_types()
{
//Product types also includes modifier.
return ['single' => __('lang_v1.single'),
'variable' => __('lang_v1.variable'),
'combo' => __('lang_v1.combo'),
];
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
if (! auth()->user()->can('product.create')) {
abort(403, 'Unauthorized action.');
}
try {
$business_id = $request->session()->get('user.business_id');
$form_fields = ['name', 'brand_id', 'unit_id', 'category_id', 'tax', 'type', 'barcode_type', 'sku', 'alert_quantity', 'tax_type', 'weight', 'product_description', 'sub_unit_ids', 'preparation_time_in_minutes', 'product_custom_field1', 'product_custom_field2', 'product_custom_field3', 'product_custom_field4', 'product_custom_field5', 'product_custom_field6', 'product_custom_field7', 'product_custom_field8', 'product_custom_field9', 'product_custom_field10', 'product_custom_field11', 'product_custom_field12', 'product_custom_field13', 'product_custom_field14', 'product_custom_field15', 'product_custom_field16', 'product_custom_field17', 'product_custom_field18', 'product_custom_field19', 'product_custom_field20',];
$module_form_fields = $this->moduleUtil->getModuleFormField('product_form_fields');
if (! empty($module_form_fields)) {
$form_fields = array_merge($form_fields, $module_form_fields);
}
$product_details = $request->only($form_fields);
$product_details['business_id'] = $business_id;
$product_details['created_by'] = $request->session()->get('user.id');
$product_details['enable_stock'] = (! empty($request->input('enable_stock')) && $request->input('enable_stock') == 1) ? 1 : 0;
$product_details['not_for_selling'] = (! empty($request->input('not_for_selling')) && $request->input('not_for_selling') == 1) ? 1 : 0;
if (! empty($request->input('sub_category_id'))) {
$product_details['sub_category_id'] = $request->input('sub_category_id');
}
if (! empty($request->input('secondary_unit_id'))) {
$product_details['secondary_unit_id'] = $request->input('secondary_unit_id');
}
if (empty($product_details['sku'])) {
$product_details['sku'] = ' ';
}
if (! empty($product_details['alert_quantity'])) {
$product_details['alert_quantity'] = $this->productUtil->num_uf($product_details['alert_quantity']);
}
$expiry_enabled = $request->session()->get('business.enable_product_expiry');
if (! empty($request->input('expiry_period_type')) && ! empty($request->input('expiry_period')) && ! empty($expiry_enabled) && ($product_details['enable_stock'] == 1)) {
$product_details['expiry_period_type'] = $request->input('expiry_period_type');
$product_details['expiry_period'] = $this->productUtil->num_uf($request->input('expiry_period'));
}
if (! empty($request->input('enable_sr_no')) && $request->input('enable_sr_no') == 1) {
$product_details['enable_sr_no'] = 1;
}
//upload document
$product_details['image'] = $this->productUtil->uploadFile($request, 'image', config('constants.product_img_path'), 'image');
// if (!empty($request->image)) {
// $file = $request->file('image');
// $imageName = time() . '_' . rawurlencode($file->getClientOriginalName());
// $file->move(public_path('uploads/img'), $imageName);
// }
$common_settings = session()->get('business.common_settings');
$product_details['warranty_id'] = ! empty($request->input('warranty_id')) ? $request->input('warranty_id') : null;
DB::beginTransaction();
$product = Product::create($product_details);
event(new ProductsCreatedOrModified($product_details, 'added'));
if (empty(trim($request->input('sku')))) {
$sku = $this->productUtil->generateProductSku($product->id);
$product->sku = $sku;
$product->save();
}
//Add product locations
$product_locations = $request->input('product_locations');
if (! empty($product_locations)) {
$product->product_locations()->sync($product_locations);
}
if ($product->type == 'single') {
$this->productUtil->createSingleProductVariation($product->id, $product->sku, $request->input('single_dpp'), $request->input('single_dpp_inc_tax'), $request->input('profit_percent'), $request->input('single_dsp'), $request->input('single_dsp_inc_tax'));
} elseif ($product->type == 'variable') {
if (! empty($request->input('product_variation'))) {
$input_variations = $request->input('product_variation');
$this->productUtil->createVariableProductVariations($product->id, $input_variations, $request->input('sku_type'));
}
} elseif ($product->type == 'combo') {
//Create combo_variations array by combining variation_id and quantity.
$combo_variations = [];
if (! empty($request->input('composition_variation_id'))) {
$composition_variation_id = $request->input('composition_variation_id');
$quantity = $request->input('quantity');
$unit = $request->input('unit');
foreach ($composition_variation_id as $key => $value) {
$combo_variations[] = [
'variation_id' => $value,
'quantity' => $this->productUtil->num_uf($quantity[$key]),
'unit_id' => $unit[$key],
];
}
}
$this->productUtil->createSingleProductVariation($product->id, $product->sku, $request->input('item_level_purchase_price_total'), $request->input('purchase_price_inc_tax'), $request->input('profit_percent'), $request->input('selling_price'), $request->input('selling_price_inc_tax'), $combo_variations);
}
//Add product racks details.
$product_racks = $request->get('product_racks', null);
if (! empty($product_racks)) {
$this->productUtil->addRackDetails($business_id, $product->id, $product_racks);
}
//Set Module fields
if (! empty($request->input('has_module_data'))) {
$this->moduleUtil->getModuleData('after_product_saved', ['product' => $product, 'request' => $request]);
}
Media::uploadMedia($product->business_id, $product, $request, 'product_brochure', true);
DB::commit();
$output = ['success' => 1,
'msg' => __('product.product_added_success'),
];
} catch (\Exception $e) {
DB::rollBack();
\Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage());
$output = ['success' => 0,
'msg' => __('messages.something_went_wrong'),
];
return redirect('products')->with('status', $output);
}
if ($request->input('submit_type') == 'submit_n_add_opening_stock') {
return redirect()->action([\App\Http\Controllers\OpeningStockController::class, 'add'],
['product_id' => $product->id]
);
} elseif ($request->input('submit_type') == 'submit_n_add_selling_prices') {
return redirect()->action([\App\Http\Controllers\ProductController::class, 'addSellingPrices'],
[$product->id]
);
} elseif ($request->input('submit_type') == 'save_n_add_another') {
return redirect()->action([\App\Http\Controllers\ProductController::class, 'create']
)->with('status', $output);
}
// if (!empty($request->image)) {
// $file = $request->file('image');
// $imageName = time() . '_' . rawurlencode($file->getClientOriginalName());
// $file->move(public_path('uploads/img'), $imageName);
// }
return redirect('products')->with('status', $output);
}
/**
* Display the specified resource.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function show($id)
{
if (! auth()->user()->can('product.view')) {
abort(403, 'Unauthorized action.');
}
$business_id = request()->session()->get('user.business_id');
$details = $this->productUtil->getRackDetails($business_id, $id, true);
return view('product.show')->with(compact('details'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
if (! auth()->user()->can('product.update')) {
abort(403, 'Unauthorized action.');
}
$business_id = request()->session()->get('user.business_id');
$categories = Category::forDropdown($business_id, 'product');
$brands = Brands::forDropdown($business_id);
$tax_dropdown = TaxRate::forBusinessDropdown($business_id, true, true);
$taxes = $tax_dropdown['tax_rates'];
$tax_attributes = $tax_dropdown['attributes'];
$barcode_types = $this->barcode_types;
$product = Product::where('business_id', $business_id)
->with(['product_locations'])
->where('id', $id)
->firstOrFail();
//Sub-category
$sub_categories = [];
$sub_categories = Category::where('business_id', $business_id)
->where('parent_id', $product->category_id)
->pluck('name', 'id')
->toArray();
$sub_categories = ['' => 'None'] + $sub_categories;
$default_profit_percent = request()->session()->get('business.default_profit_percent');
//Get units.
$units = Unit::forDropdown($business_id, true);
$sub_units = $this->productUtil->getSubUnits($business_id, $product->unit_id, true);
//Get all business locations
$business_locations = BusinessLocation::forDropdown($business_id);
//Rack details
$rack_details = $this->productUtil->getRackDetails($business_id, $id);
$selling_price_group_count = SellingPriceGroup::countSellingPriceGroups($business_id);
$module_form_parts = $this->moduleUtil->getModuleData('product_form_part');
$product_types = $this->product_types();
$common_settings = session()->get('business.common_settings');
$warranties = Warranty::forDropdown($business_id);
//product screen view from module
$pos_module_data = $this->moduleUtil->getModuleData('get_product_screen_top_view');
$alert_quantity = ! is_null($product->alert_quantity) ? $this->productUtil->num_f($product->alert_quantity, false, null, true) : null;
return view('product.edit')
->with(compact('categories', 'brands', 'units', 'sub_units', 'taxes', 'tax_attributes', 'barcode_types', 'product', 'sub_categories', 'default_profit_percent', 'business_locations', 'rack_details', 'selling_price_group_count', 'module_form_parts', 'product_types', 'common_settings', 'warranties', 'pos_module_data', 'alert_quantity'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
if (! auth()->user()->can('product.update')) {
abort(403, 'Unauthorized action.');
}
try {
$business_id = $request->session()->get('user.business_id');
$product_details = $request->only(['name', 'brand_id', 'unit_id', 'category_id', 'tax', 'barcode_type', 'sku', 'alert_quantity', 'tax_type', 'weight', 'product_description', 'sub_unit_ids', 'preparation_time_in_minutes', 'product_custom_field1', 'product_custom_field2', 'product_custom_field3', 'product_custom_field4', 'product_custom_field5', 'product_custom_field6', 'product_custom_field7', 'product_custom_field8', 'product_custom_field9', 'product_custom_field10', 'product_custom_field11', 'product_custom_field12', 'product_custom_field13', 'product_custom_field14', 'product_custom_field15', 'product_custom_field16', 'product_custom_field17', 'product_custom_field18', 'product_custom_field19', 'product_custom_field20',]);
DB::beginTransaction();
$product = Product::where('business_id', $business_id)
->where('id', $id)
->with(['product_variations'])
->first();
$module_form_fields = $this->moduleUtil->getModuleFormField('product_form_fields');
if (! empty($module_form_fields)) {
foreach ($module_form_fields as $column) {
$product->$column = $request->input($column);
}
}
$product->name = $product_details['name'];
$product->brand_id = $product_details['brand_id'];
$product->unit_id = $product_details['unit_id'];
$product->category_id = $product_details['category_id'];
$product->tax = $product_details['tax'];
$product->barcode_type = $product_details['barcode_type'];
$product->sku = $product_details['sku'];
$product->alert_quantity = ! empty($product_details['alert_quantity']) ? $this->productUtil->num_uf($product_details['alert_quantity']) : $product_details['alert_quantity'];
$product->tax_type = $product_details['tax_type'];
$product->weight = $product_details['weight'];
$product->product_custom_field1 = $product_details['product_custom_field1'] ?? '';
$product->product_custom_field2 = $product_details['product_custom_field2'] ?? '';
$product->product_custom_field3 = $product_details['product_custom_field3'] ?? '';
$product->product_custom_field4 = $product_details['product_custom_field4'] ?? '';
$product->product_custom_field5 = $product_details['product_custom_field5'] ?? '';
$product->product_custom_field6 = $product_details['product_custom_field6'] ?? '';
$product->product_custom_field7 = $product_details['product_custom_field7'] ?? '';
$product->product_custom_field8 = $product_details['product_custom_field8'] ?? '';
$product->product_custom_field9 = $product_details['product_custom_field9'] ?? '';
$product->product_custom_field10 = $product_details['product_custom_field10'] ?? '';
$product->product_custom_field11 = $product_details['product_custom_field11'] ?? '';
$product->product_custom_field12 = $product_details['product_custom_field12'] ?? '';
$product->product_custom_field13 = $product_details['product_custom_field13'] ?? '';
$product->product_custom_field14 = $product_details['product_custom_field14'] ?? '';
$product->product_custom_field15 = $product_details['product_custom_field15'] ?? '';
$product->product_custom_field16 = $product_details['product_custom_field16'] ?? '';
$product->product_custom_field17 = $product_details['product_custom_field17'] ?? '';
$product->product_custom_field18 = $product_details['product_custom_field18'] ?? '';
$product->product_custom_field19 = $product_details['product_custom_field19'] ?? '';
$product->product_custom_field20 = $product_details['product_custom_field20'] ?? '';
$product->product_description = $product_details['product_description'];
$product->sub_unit_ids = ! empty($product_details['sub_unit_ids']) ? $product_details['sub_unit_ids'] : null;
$product->preparation_time_in_minutes = $product_details['preparation_time_in_minutes'];
$product->warranty_id = ! empty($request->input('warranty_id')) ? $request->input('warranty_id') : null;
$product->secondary_unit_id = ! empty($request->input('secondary_unit_id')) ? $request->input('secondary_unit_id') : null;
if (! empty($request->input('enable_stock')) && $request->input('enable_stock') == 1) {
$product->enable_stock = 1;
} else {
$product->enable_stock = 0;
}
$product->not_for_selling = (! empty($request->input('not_for_selling')) && $request->input('not_for_selling') == 1) ? 1 : 0;
if (! empty($request->input('sub_category_id'))) {
$product->sub_category_id = $request->input('sub_category_id');
} else {
$product->sub_category_id = null;
}
$expiry_enabled = $request->session()->get('business.enable_product_expiry');
if (! empty($expiry_enabled)) {
if (! empty($request->input('expiry_period_type')) && ! empty($request->input('expiry_period')) && ($product->enable_stock == 1)) {
$product->expiry_period_type = $request->input('expiry_period_type');
$product->expiry_period = $this->productUtil->num_uf($request->input('expiry_period'));
} else {
$product->expiry_period_type = null;
$product->expiry_period = null;
}
}
if (! empty($request->input('enable_sr_no')) && $request->input('enable_sr_no') == 1) {
$product->enable_sr_no = 1;
} else {
$product->enable_sr_no = 0;
}
//upload document
$file_name = $this->productUtil->uploadFile($request, 'image', config('constants.product_img_path'), 'image');
if (! empty($file_name)) {
//If previous image found then remove
if (! empty($product->image_path) && file_exists($product->image_path)) {
unlink($product->image_path);
}
$product->image = $file_name;
//If product image is updated update woocommerce media id
if (! empty($product->woocommerce_media_id)) {
$product->woocommerce_media_id = null;
}
}
$product->save();
$product->touch();
event(new ProductsCreatedOrModified($product, 'updated'));
//Add product locations
$product_locations = ! empty($request->input('product_locations')) ?
$request->input('product_locations') : [];
$permitted_locations = auth()->user()->permitted_locations();
//If not assigned location exists don't remove it
if ($permitted_locations != 'all') {
$existing_product_locations = $product->product_locations()->pluck('id');
foreach ($existing_product_locations as $pl) {
if (! in_array($pl, $permitted_locations)) {
$product_locations[] = $pl;
}
}
}
$product->product_locations()->sync($product_locations);
if ($product->type == 'single') {
$single_data = $request->only(['single_variation_id', 'single_dpp', 'single_dpp_inc_tax', 'single_dsp_inc_tax', 'profit_percent', 'single_dsp']);
$variation = Variation::find($single_data['single_variation_id']);
$variation->sub_sku = $product->sku;
$variation->default_purchase_price = $this->productUtil->num_uf($single_data['single_dpp']);
$variation->dpp_inc_tax = $this->productUtil->num_uf($single_data['single_dpp_inc_tax']);
$variation->profit_percent = $this->productUtil->num_uf($single_data['profit_percent']);
$variation->default_sell_price = $this->productUtil->num_uf($single_data['single_dsp']);
$variation->sell_price_inc_tax = $this->productUtil->num_uf($single_data['single_dsp_inc_tax']);
$variation->save();
Media::uploadMedia($product->business_id, $variation, $request, 'variation_images');
} elseif ($product->type == 'variable') {
//Update existing variations
$input_variations_edit = $request->get('product_variation_edit');
if (! empty($input_variations_edit)) {
$this->productUtil->updateVariableProductVariations($product->id, $input_variations_edit,$request->input('sku_type'));
}
//Add new variations created.
$input_variations = $request->input('product_variation');
if (! empty($input_variations)) {
$this->productUtil->createVariableProductVariations($product->id, $input_variations, $request->input('sku_type'));
}
} elseif ($product->type == 'combo') {
//Create combo_variations array by combining variation_id and quantity.
$combo_variations = [];
if (! empty($request->input('composition_variation_id'))) {
$composition_variation_id = $request->input('composition_variation_id');
$quantity = $request->input('quantity');
$unit = $request->input('unit');
foreach ($composition_variation_id as $key => $value) {
$combo_variations[] = [
'variation_id' => $value,
'quantity' => $quantity[$key],
'unit_id' => $unit[$key],
];
}
}
$variation = Variation::find($request->input('combo_variation_id'));
$variation->sub_sku = $product->sku;
$variation->default_purchase_price = $this->productUtil->num_uf($request->input('item_level_purchase_price_total'));
$variation->dpp_inc_tax = $this->productUtil->num_uf($request->input('purchase_price_inc_tax'));
$variation->profit_percent = $this->productUtil->num_uf($request->input('profit_percent'));
$variation->default_sell_price = $this->productUtil->num_uf($request->input('selling_price'));
$variation->sell_price_inc_tax = $this->productUtil->num_uf($request->input('selling_price_inc_tax'));
$variation->combo_variations = $combo_variations;
$variation->save();
}
//Add product racks details.
$product_racks = $request->get('product_racks', null);
if (! empty($product_racks)) {
$this->productUtil->addRackDetails($business_id, $product->id, $product_racks);
}
$product_racks_update = $request->get('product_racks_update', null);
if (! empty($product_racks_update)) {
$this->productUtil->updateRackDetails($business_id, $product->id, $product_racks_update);
}
//Set Module fields
if (! empty($request->input('has_module_data'))) {
$this->moduleUtil->getModuleData('after_product_saved', ['product' => $product, 'request' => $request]);
}
Media::uploadMedia($product->business_id, $product, $request, 'product_brochure', true);
DB::commit();
$output = ['success' => 1,
'msg' => __('product.product_updated_success'),
];
} catch (\Exception $e) {
DB::rollBack();
\Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage());
$output = ['success' => 0,
'msg' => $e->getMessage(),
];
}
if ($request->input('submit_type') == 'update_n_edit_opening_stock') {
return redirect()->action([\App\Http\Controllers\OpeningStockController::class, 'add'],
['product_id' => $product->id]
);
} elseif ($request->input('submit_type') == 'submit_n_add_selling_prices') {
return redirect()->action([\App\Http\Controllers\ProductController::class, 'addSellingPrices'],
[$product->id]
);
} elseif ($request->input('submit_type') == 'save_n_add_another') {
return redirect()->action([\App\Http\Controllers\ProductController::class, 'create']
)->with('status', $output);
}
return redirect('products')->with('status', $output);
}
/**
* Remove the specified resource from storage.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
if (! auth()->user()->can('product.delete')) {
abort(403, 'Unauthorized action.');
}
if (request()->ajax()) {
try {
$business_id = request()->session()->get('user.business_id');
$can_be_deleted = true;
$error_msg = '';
//Check if any purchase or transfer exists
$count = PurchaseLine::join(
'transactions as T',
'purchase_lines.transaction_id',
'=',
'T.id'
)
->whereIn('T.type', ['purchase'])
->where('T.business_id', $business_id)
->where('purchase_lines.product_id', $id)
->count();
if ($count > 0) {
$can_be_deleted = false;
$error_msg = __('lang_v1.purchase_already_exist');
} else {
//Check if any opening stock sold
$count = PurchaseLine::join(
'transactions as T',
'purchase_lines.transaction_id',
'=',
'T.id'
)
->where('T.type', 'opening_stock')
->where('T.business_id', $business_id)
->where('purchase_lines.product_id', $id)
->where('purchase_lines.quantity_sold', '>', 0)
->count();
if ($count > 0) {
$can_be_deleted = false;
$error_msg = __('lang_v1.opening_stock_sold');
} else {
//Check if any stock is adjusted
$count = PurchaseLine::join(
'transactions as T',
'purchase_lines.transaction_id',
'=',
'T.id'
)
->where('T.business_id', $business_id)
->where('purchase_lines.product_id', $id)
->where('purchase_lines.quantity_adjusted', '>', 0)
->count();
if ($count > 0) {
$can_be_deleted = false;
$error_msg = __('lang_v1.stock_adjusted');
}
}
}
$product = Product::where('id', $id)
->where('business_id', $business_id)
->with('variations')
->first();
// check for enable stock = 0 product
if($product->enable_stock == 0){
$t_count = TransactionSellLine::join(
'transactions as T',
'transaction_sell_lines.transaction_id',
'=',
'T.id'
)
->where('T.business_id', $business_id)
->where('transaction_sell_lines.product_id', $id)
->count();
if ($t_count > 0) {
$can_be_deleted = false;
$error_msg = "can't delete product exit in sell";
}
}
//Check if product is added as an ingredient of any recipe
if ($this->moduleUtil->isModuleInstalled('Manufacturing')) {
$variation_ids = $product->variations->pluck('id');
$exists_as_ingredient = \Modules\Manufacturing\Entities\MfgRecipeIngredient::whereIn('variation_id', $variation_ids)
->exists();
if ($exists_as_ingredient) {
$can_be_deleted = false;
$error_msg = __('manufacturing::lang.added_as_ingredient');
}
}
if ($can_be_deleted) {
if (! empty($product)) {
DB::beginTransaction();
//Delete variation location details
VariationLocationDetails::where('product_id', $id)
->delete();
$product->delete();
event(new ProductsCreatedOrModified($product, 'deleted'));
DB::commit();
}
$output = ['success' => true,
'msg' => __('lang_v1.product_delete_success'),
];
} else {
$output = ['success' => false,
'msg' => $error_msg,
];
}
} catch (\Exception $e) {
DB::rollBack();
\Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage());
$output = ['success' => false,
'msg' => __('messages.something_went_wrong'),
];
}
return $output;
}
}
/**
* Get subcategories list for a category.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function getSubCategories(Request $request)
{
if (! empty($request->input('cat_id'))) {
$category_id = $request->input('cat_id');
$business_id = $request->session()->get('user.business_id');
$sub_categories = Category::where('business_id', $business_id)
->where('parent_id', $category_id)
->select(['name', 'id'])
->get();
$html = '