The first item scanned is coming correct, but the items scanned after are not calculating VAT. I attempted to implement the necessary adjustments, but unfortunately, my efforts failed. I'm still determining the specific areas that need changes to achieve the desired outcome. Additionally, I encountered difficulties while installing the debug bar, which further complicated the troubleshooting process. Despite my best efforts, I remain unable to resolve the issue. Any guidance or assistance would be greatly appreciated.
public function getProductsByBarcode()
{
if (request()->ajax()) {
$output = [];
try {
$location_id = request()->input('location_id', null);
$check_qty = request()->input('check_qty', false);
$business_id = request()->session()->get('user.business_id');
$product_types = request()->get('product_types', []);
$price_group_id = request()->input('price_group', null);
$sku = request()->get('sku');
if(empty($sku)){
$sku = request()->input('sku');
}
$query = Product::join('variations', 'products.id', '=', 'variations.product_id')
->active()
->whereNull('variations.deleted_at')
->leftjoin('units as U', 'products.unit_id', '=', 'U.id')
->leftjoin(
'variation_location_details AS VLD',
function ($join) use ($location_id) {
$join->on('variations.id', '=', 'VLD.variation_id');
if (! empty($location_id)) {
$join->where(function ($query) use ($location_id) {
$query->where('VLD.location_id', '=', $location_id);
$query->orWhereNull('VLD.location_id');
});
}
}
);
if (! empty($price_group_id)) {
$query->leftjoin(
'variation_group_prices AS VGP',
function ($join) use ($price_group_id) {
$join->on('variations.id', '=', 'VGP.variation_id')
->where('VGP.price_group_id', '=', $price_group_id);
}
);
}
$query->where('products.business_id', $business_id)
->where('products.type', '!=', 'modifier');
if (! empty($product_types)) {
$query->whereIn('products.type', $product_types);
}
$query->where('products.business_id', $business_id)
->where('products.type', '!=', 'modifier')
->where('products.sku', '=', $sku);
if ($check_qty) {
$query->where('VLD.qty_available', '>', 0);
}
if (!empty($location_id)) {
$query->ForLocation($location_id);
}
$query->select(
'products.id as product_id',
'products.name',
'products.type',
'products.enable_stock',
'variations.id as variation_id',
'variations.name as variation',
'VLD.qty_available',
'variations.sell_price_inc_tax as selling_price',
'variations.sub_sku',
'U.short_name as unit'
);
$query->groupBy('variations.id');
$product = $query->orderBy('VLD.qty_available', 'desc')->first();
if(empty($product)){
$output['success'] = false;
$output['msg'] = __('lang_v1.no_products_found');
return $output;
} else {
$is_overselling_allowed = request()->get('is_overselling_allowed');
$for_so = request()->get('for_so');
$is_draft = request()->get('is_draft');
$enable_stock = $product->enable_stock;
$qty_available = $product->qty_available;
$variation_id = $product->variation_id;
if ($enable_stock != 1 || $qty_available > 0 || $is_overselling_allowed || $for_so || $is_draft) {
$row_count = request()->get('product_row');
$row_count = $row_count + 1;
$quantity = request()->get('quantity', 1);
$is_direct_sell = false;
$output = $this->getSellLineRowForBarcode($variation_id, $location_id, $quantity, $row_count, $is_direct_sell);
} else {
$output['success'] = false;
$output['msg'] = __('lang_v1.item_out_of_stock');
return $output;
}
}
} catch (\Exception $e) {
Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage());
$output['success'] = false;
$output['msg'] = __('lang_v1.item_out_of_stock');
}
return $output;
}
}
private function getSellLineRowForBarcode($variation_id, $location_id, $quantity, $row_count, $is_direct_sell, $so_line = null)
{
// omitted for brevity
}
Update the below function and let me know the results: