163 lines
4.2 KiB
PHP
163 lines
4.2 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: root
|
|
* Date: 10/3/18
|
|
* Time: 3:36 PM
|
|
*/
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Contracts\ProductDetailsResourceInterface;
|
|
use App\ProductCategory;
|
|
use App\ProductDetails;
|
|
use App\ProductsDetails;
|
|
use App\Contracts\ProductsDetailsResourceInterface;
|
|
use App\Libraries\UuidHelper;
|
|
use Response;
|
|
use Schema;
|
|
use Hash;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
use App\SystemPreference;
|
|
use App\Helpers\HttpStatusCode;
|
|
use Ramsey\Uuid\Uuid;
|
|
use App\Helpers\CurrentUserHelper;
|
|
|
|
class ProductDetailsService implements ProductDetailsResourceInterface
|
|
{
|
|
|
|
public $product_details;
|
|
public $product_category;
|
|
|
|
public function __construct(Request $request)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
public function getProductCategoryByField($field,$value)
|
|
{
|
|
$this->product_category = ProductCategory::where($field,$value);
|
|
return $this->product_category->get();
|
|
}
|
|
public function getProductDetailsByField($field,$value)
|
|
{
|
|
$this->product_details = ProductDetails::where($field,$value);
|
|
return $this->product_details->get();
|
|
}
|
|
public function storeProductDetails($value)
|
|
{
|
|
$this->product_details = new ProductDetails;
|
|
|
|
$uuid = new UuidHelper;
|
|
$this->product_details->pd_uuid = $uuid->generate_uuid1();
|
|
$this->product_details->code = "";
|
|
$this->product_details->name = $value['name'];
|
|
$this->product_details->description = $value['description'];
|
|
$this->product_details->details = $value['details'];
|
|
$this->product_details->image = $value['image'];
|
|
$this->product_details->is_active = 1;
|
|
$this->product_details->pc_id = $value['pc_id'];
|
|
|
|
if ($this->product_details->save())
|
|
{
|
|
return $this->product_details->pd_id;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function storeProductCategory($value)
|
|
{
|
|
$this->product_category = new ProductCategory;
|
|
|
|
$uuid = new UuidHelper;
|
|
$this->product_category->pc_uuid = $uuid->generate_uuid1();
|
|
$this->product_category->type = $value['type'];
|
|
$this->product_category->description = $value['description'];
|
|
$this->product_category->is_active = 1;
|
|
|
|
if ($this->product_category->save())
|
|
{
|
|
return $this->product_category->pc_id;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function updateProductCategory($value)
|
|
{
|
|
$this->product_category = ProductCategory::where([
|
|
['pc_id',$value['pc_id']]
|
|
])->first();
|
|
|
|
$this->product_category->type = $value['type'];
|
|
$this->product_category->description = $value['description'];
|
|
|
|
if ($this->product_category->save())
|
|
{
|
|
return $this->product_category;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
public function updateProductDetails($value)
|
|
{
|
|
$this->product_details = ProductDetails::where([
|
|
['pd_id',$value['pd_id']]
|
|
])->first();
|
|
|
|
$this->product_details->code = $value['code'];
|
|
$this->product_details->name = $value['name'];
|
|
$this->product_details->description = $value['description'];
|
|
$this->product_details->details = $value['details'];
|
|
$this->product_details->image = $value['image'];
|
|
$this->product_details->pc_id = $value['pc_id'];
|
|
$this->product_details->is_active = $value['is_active'];
|
|
|
|
|
|
if ($this->product_details->save())
|
|
{
|
|
return $this->product_details;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getAllProductCategory()
|
|
{
|
|
return $this->product_details = ProductCategory::where([
|
|
['is_active',1]
|
|
])->get();
|
|
}
|
|
|
|
public function getProductsByCategory($pc_id)
|
|
{
|
|
return $this->product_details = ProductDetails::where([
|
|
['is_active',1],
|
|
['pc_id',$pc_id],
|
|
])
|
|
->orderBy('name')
|
|
->get();
|
|
}
|
|
|
|
public function inActiveProductDetails()
|
|
{
|
|
ProductDetails::where('is_active', '=', 1)->update(['is_active' => 0]);
|
|
}
|
|
|
|
}
|