Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eries Trisnadi committed Dec 16, 2017
2 parents 5a049e1 + 139a20a commit a42c9a5
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 12 deletions.
5 changes: 5 additions & 0 deletions app/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public function company()
return $this->belongsTo('\App\Company');
}

public function order()
{
return $this->hasOne('\App\Order');
}

protected $hidden = [
'company_id'
];
Expand Down
32 changes: 30 additions & 2 deletions app/Http/Controllers/Api/V1/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use App\Customer;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;

class CustomerController extends Controller
Expand All @@ -15,9 +16,36 @@ public function __construct(){
}

public function get(Request $request){
$customer = Customer::where('company_id', Auth::user()->company->id)->get();
$customer = Customer::where('company_id', Auth::user()->company->id);

if($request->has('filter')){
$params = (object) json_decode($request->filter, true);

if(is_array($params->date_range)){
$params->date_range = (object) $params->date_range;
}
if($params->name){
$customer = $customer->where('full_name', 'like', '%' . $params->name . '%');
}
if($params->company){
$customer = $customer->where('company_name', 'like', '%' . $params->company . '%');
}
if($params->city){
$customer = $customer->where('city', 'like', '%' . $params->city . '%');
}
if($params->country){
$customer = $customer->where('country', 'like', '%' . $params->country . '%');
}

if(is_object($params->date_range) && ($params->date_range->from && $params->date_range->to)){
$customer = $customer->whereBetween('created_at', [
Carbon::createFromFormat('m/d/Y', $params->date_range->from)->format('Y-m-d')." 00:00:00",
Carbon::createFromFormat('m/d/Y', $params->date_range->to)->format('Y-m-d')." 23:59:59"
]);
}
}

if($this->content['data'] = $customer){
if($this->content['data'] = $customer->get()){
$this->content['status'] = 200;
return response()->json($this->content, $this->content['status']);
}
Expand Down
35 changes: 32 additions & 3 deletions app/Http/Controllers/Api/V1/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,39 @@ public function __construct(){

public function get(Request $request){
$order = Order::with(['order_detail.product', 'customer'])
->where('company_id', Auth::user()->company->id)
->get();
->where('company_id', Auth::user()->company->id);

if($this->content['data'] = $order){
if($request->has('filter')){
$params = (object) json_decode($request->filter, true);

if(is_array($params->date_range)){
$params->date_range = (object) $params->date_range;
}
if($params->id){
$order = $order->where('id', 'like', '%' . $params->id . '%');
}
if($params->product){
$order = $order->whereHas('order_detail', function($q) use ($params) {
$q->whereHas('product', function($q) use ($params) {
$q->where('name', 'like', '%' . $params->product . '%');
});
});
}
if($params->customer){
$order = $order->whereHas('customer', function($q) use ($params) {
$q->where('full_name', 'like', '%' . $params->customer . '%');
});
}

if(is_object($params->date_range) && ($params->date_range->from && $params->date_range->to)){
$customer = $customer->whereBetween('created_at', [
Carbon::createFromFormat('m/d/Y', $params->date_range->from)->format('Y-m-d')." 00:00:00",
Carbon::createFromFormat('m/d/Y', $params->date_range->to)->format('Y-m-d')." 23:59:59"
]);
}
}

if($this->content['data'] = $order->get()){
$this->content['status'] = 200;
return response()->json($this->content, $this->content['status'], [], JSON_NUMERIC_CHECK);
}
Expand Down
52 changes: 49 additions & 3 deletions app/Http/Controllers/Api/V1/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Http\Controllers\Controller;
use App\Product;
use App\ProductType;
use App\Customer;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use DB;

Expand All @@ -18,10 +20,35 @@ public function __construct(){

public function get(Request $request){
$product = Product::with('type')
->where('company_id', Auth::user()->company->id)
->get();
->where('company_id', Auth::user()->company->id);

if($request->has('filter')){
$params = (object) json_decode($request->filter, true);

if(is_array($params->type)){
$params->type = (object) $params->type;
}
if(is_array($params->date_range)){
$params->date_range = (object) $params->date_range;
}
if($params->name){
$product = $product->where('name', 'like', '%' . $params->name . '%');
}
if($params->sku){
$product = $product->where('sku', 'like', '%' . $params->sku . '%');
}
if(is_object($params->type) && $params->type->id){
$product = $product->where('type_id', $params->type->id);
}
if(is_object($params->date_range) && ($params->date_range->from && $params->date_range->to)){
$product = $product->whereBetween('created_at', [
Carbon::createFromFormat('m/d/Y', $params->date_range->from)->format('Y-m-d')." 00:00:00",
Carbon::createFromFormat('m/d/Y', $params->date_range->to)->format('Y-m-d')." 23:59:59"
]);
}
}

if($this->content['data'] = $product){
if($this->content['data'] = $product->get()){
$this->content['status'] = 200;
return response()->json($this->content, $this->content['status'], [], JSON_NUMERIC_CHECK);
}
Expand All @@ -48,6 +75,25 @@ public function find(Request $request){
return response()->json($this->content, $this->content['status'], [], JSON_NUMERIC_CHECK);
}

public function customers(Request $request){
$product_id = $request->id;
$customers = Customer::whereHas('order', function($query) use ($product_id) {
$query->whereHas('order_detail', function($query) use ($product_id) {
$query->where('product_id', $product_id);
});
})->get();

if($this->content['data'] = $customers){
$this->content['status'] = 200;
return response()->json($this->content, $this->content['status'], [], JSON_NUMERIC_CHECK);
}

$this->content['error'] = "Server Error";
$this->content['status'] = 500;

return response()->json($this->content, $this->content['status'], [], JSON_NUMERIC_CHECK);
}

public function add(Request $request)
{
$product = Product::create([
Expand Down
13 changes: 9 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ Storaji is an Open Source, Responsive Inventory Management System, powered by El
Go to [Release Section](https://github.com/IndomaximTechID/storaji/releases/)

### Status
Version: 1.0.0-alpha
Version: 1.0.0-beta.0
[TRY DEMO WEBSITE HERE](https://indomaximtechid.github.io/storaji/)

### Latest updates
- First released version 1.0.0-alpha
- Released version 1.0.0-beta.0

### Consumer features
- Products Management
- Customers Management
- Add Order and Order Overview
- Orders Management and Order Overview
- Statistics
- Top Selling Products
- Top Selling Products
- Customers List on Product Overview
- Reports for Products, Orders, Customers
- Translations for Bahasa Indonesia, English
- Save Report as PDF
- Check for update app
5 changes: 5 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
'middleware' => 'auth:api',
'uses' => 'ProductController@find',
]);
Route::get('/{id}/customers', [
'as' => 'api.products.customers',
'middleware' => 'auth:api',
'uses' => 'ProductController@customers',
]);
Route::put('/{id}/update', [
'as' => 'api.products.update',
'middleware' => 'auth:api',
Expand Down

0 comments on commit a42c9a5

Please sign in to comment.