Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers\API;
- use App\Http\Controllers\API\GForceController;
- use App\Models\Bank;
- use App\Models\CatalogItem;
- use App\Models\CustomerPriceGroup;
- use App\Models\CustomerToken;
- use App\Models\GforcePaymentConfirmation;
- use App\Models\GforcePaymentConfirmationPhoto;
- use App\Models\GlBank;
- use App\Models\GlBankCompany;
- use Illuminate\Http\Request;
- use App\Mail\CustomerRegistration;
- use App\Http\Controllers\Controller;
- use App\Http\Controllers\API\StagingController;
- use App\Http\Controllers\Transaction\OrderParameterController;
- use App\Models\Status;
- use App\Models\Parameter;
- use App\Models\OTPCustomer;
- use App\Models\Customer;
- use App\Models\CustomerPoint;
- use App\Models\SoOrderHeader;
- use App\Models\Country;
- use App\Models\Province;
- use App\Models\PointOFO;
- use App\Models\CustomerGiftClaim;
- use App\Models\City;
- use App\Models\District;
- use App\Models\PostalCode;
- use App\Models\PaymentTerm;
- use App\Models\ProductCategory;
- use App\Models\ProductGift;
- use App\Models\Product;
- use App\Models\ProductPhoto;
- use App\Models\OrderHeader;
- use App\Models\OrderDetail;
- use App\Models\SalesOrganization;
- use App\Models\DailyNews;
- use App\Models\EmployeeRoute;
- use App\Models\CustomerAddress;
- use App\Models\MCompany;
- use App\Models\CustomerNotification;
- use DB;
- use Hash;
- use Response;
- use Mail;
- use File;
- class EcommerceController extends Controller
- {
- private $otp_time_in_sec;
- private $customer_category_type_to_ecommerce;
- private $sd_customer_price_group_id;
- private $auto_send_order;
- public function __construct()
- {
- $this->otp_time_in_sec = Parameter::where('name_param', 'otp_time_in_sec')->first();
- $this->auto_send_order = Parameter::where('name_param', 'auto_send_order')->first();
- $this->add_valid_customer_poin = Parameter::select('int_1')->where('name_param', 'add_valid_customer_poin')->first();
- $this->customer_category_type_to_ecommerce = Parameter::where('name_param', 'customer_category_type_to_ecommerce')->first();
- $this->sd_customer_price_group_id = Parameter::where('name_param', 'sd_customer_price_group_id')->first();
- $this->kota = Parameter::where('name_param', 'get_kota')->first();
- }
- public function ajax_get_sd_country(Request $request)
- {
- $sd_country = Country::where('status_id', 10)->get();
- return Response::json($sd_country);
- }
- public function ajax_get_sd_province(Request $request)
- {
- $country_id = $request->input('country_id');
- if ($country_id != null) {
- $sd_province = Province::where('country_id', $country_id)->where('status_id', 10)->get();
- } else {
- $sd_province = Province::where('status_id', 10)->get();
- }
- return Response::json($sd_province);
- }
- public function ajax_get_sd_city(Request $request)
- {
- $province_id = $request->input('province_id');
- if ($province_id != null) {
- $sd_city = City::where('province_id', $province_id)->where('status_id', 10)->get();
- } else {
- $sd_city = City::where('status_id', 10)->get();
- }
- return Response::json($sd_city);
- }
- public function ajax_get_sd_district(Request $request)
- {
- $city_id = $request->input('city_id');
- if ($city_id != null) {
- $sd_district = District::where('city_id', $city_id)->where('status_id', 10)->get();
- } else {
- $sd_district = District::where('status_id', 10)->get();
- }
- return Response::json($sd_district);
- }
- public function ajax_get_sd_postal_code(Request $request)
- {
- $district_id = $request->input('district_id');
- if ($district_id != null) {
- $sd_postal_code = PostalCode::where('district_id', $district_id)->where('status_id', 10)->get();
- } else {
- $sd_postal_code = PostalCode::where('status_id', 10)->get();
- }
- return Response::json($sd_postal_code);
- }
- public function ajax_get_sd_postal_code_detail(Request $request)
- {
- $postal_code_id = $request->input('postal_code_id');
- $sd_postal_code = DB::table('sd_postal_code')
- ->join('sd_district', 'sd_postal_code.district_id', 'sd_district.id')
- ->join('sd_city', 'sd_district.city_id', 'sd_city.id')
- ->join('sd_province', 'sd_city.province_id', 'sd_province.id')
- ->join('sd_country', 'sd_province.country_id', 'sd_country.id')
- ->select('sd_country.id as country_id',
- 'sd_province.id as province_id',
- 'sd_city.id as city_id',
- 'sd_district.id as district_id',
- 'sd_postal_code.id',
- 'sd_postal_code.zipcode',
- 'sd_postal_code.name',
- 'sd_postal_code.gl_branch_id'
- )
- ->where('sd_postal_code.id', $postal_code_id)
- ->first();
- return Response::json($sd_postal_code);
- }
- public function get_kota(Request $request){
- try{
- $kota = SalesOrganization::where('type_so_id', $this->kota->int_1)->where('status_id',10)->get();
- if(!empty($kota)){
- $code = 0;
- $message = 'succes';
- $result = $kota;
- }else{
- $code = 115;
- $message = 'failed';
- $result = [];
- }
- $json = array(
- "code" => $code,
- "message" => $message,
- "get_kota" => $result
- );
- return response()->json($json);
- }catch (Exception $e) {
- echo $e->getResponse()->getBody();
- }
- }
- public function create_otp($ar_customer_id)
- {
- try {
- $startTime = date("Y-m-d H:i:s");
- $cenvertedTime = date('Y-m-d H:i:s', strtotime('+' . $this->otp_time_in_sec->int_1 . ' seconds', strtotime($startTime)));
- $otp_customer = new OTPCustomer;
- $otp_customer->ar_customer_id = $ar_customer_id;
- $otp_customer->otp_number = mt_rand(100000, 999999);
- $otp_customer->valid_until = $cenvertedTime;
- if ($otp_customer->save()) {
- $customer = Customer::find($ar_customer_id);
- if ($customer->email != null) {
- Mail::to($customer->email)->send(new CustomerRegistration($otp_customer->otp_number));
- }
- } else {
- $this->create_otp($ar_customer_id);
- }
- } catch (Exception $e) {
- echo $e->getResponse()->getBody();
- }
- }
- public function recreate_otp(Request $request)
- {
- try {
- $ar_customer_id = $request->ar_customer_id;
- $this->create_otp($ar_customer_id);
- } catch (Exception $e) {
- echo $e->getResponse()->getBody();
- }
- }
- public function get_customer_notification(Request $request) {
- $ar_customer_id = $request->ar_customer_id;
- $query = CustomerNotification::where('ar_customer_id', $ar_customer_id)->orderBy('created_at', 'desc')->get();
- if (sizeof($query) > 0) {
- $code = 30;
- $message = 'success';
- $result = $query;
- } else {
- $code = 40;
- $message = 'failed';
- $result = [];
- }
- $json = array(
- "code" => $code,
- "message" => $message,
- "get_customer_notification" => $result
- );
- return response()->json($json);
- }
- public function get_customer_notification_detail(Request $request) {
- $id = $request->ar_customer_notification_id;
- // dd($id);
- $query = CustomerNotification::where('id', $id)->orderBy('created_at', 'desc')->first();
- if (!empty($query)) {
- CustomerNotification::where('id', $id)
- ->update([
- 'status_id' => 4
- ]);
- $code = 30;
- $message = 'success';
- $result = $query;
- } else {
- $code = 40;
- $message = 'failed';
- $result = [];
- }
- $json = array(
- "code" => $code,
- "message" => $message,
- "get_customer_notification_detail" => $result
- );
- return response()->json($json);
- }
- public function check_otp(Request $request)
- {
- try {
- $ar_customer_id = $request->ar_customer_id;
- $otp_number = $request->otp_number;
- $otp_customer = OTPCustomer::where('ar_customer_id', $ar_customer_id)
- ->where('otp_number', $otp_number)
- ->first();
- if ($otp_customer != null) {
- if ($otp_customer->valid_until >= date("Y-m-d H:i:s")) {
- $ar_customer = Customer::find($ar_customer_id);
- $ar_customer->isVerified = 1;
- $ar_customer->save();
- $status = 0;
- } else {
- $status = 125;
- }
- } else {
- $status = 124;
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status)];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public static function get_mcompany($data){
- // $sip = 'Oke nih';
- foreach($data as $address_customer){
- // dd($address_customer['is_default']);
- if($address_customer['is_default'] == 1){
- $so = SalesOrganization::where('id', $address_customer['sd_so_main_id'])->first();
- }
- }
- if(!empty($so)){
- return $so;
- }else{
- return null;
- }
- }
- public function register_customer(Request $request)
- {
- // dd($request->address[0]['name']);
- try {
- $status = 0;
- $content = null;
- $email = null;
- $check_email = null;
- $address = null;
- $address = $request->address;
- // $branch_id = Branch::first();
- // $sd_so_main_id = SalesOrganization::where('id', $address);
- $sd_so_main_id = SELF::get_mcompany($address);
- $company_id = MCompany::where('sd_so_main_id', $sd_so_main_id->parent_id)->first();
- DB::beginTransaction();
- if ($request->email != '') {
- $email = $request->email;
- $check_email = Customer::where('email', $request->email)->first();
- }
- $check_phone_number = Customer::where('phone_number', $request->phone_number)->first();
- if ($check_phone_number == null && $check_email == null && $sd_so_main_id != null) {
- $customer = new Customer;
- $customer->phone_number = $request->phone_number;
- $customer->email = $email;
- $customer->name = $request->name;
- $customer->password = Hash::make($request->password);
- $customer->m_company_id = $company_id->id;
- $customer->sd_so_main_id = $sd_so_main_id->id;
- $customer->is_approved_noo = 0;
- $customer->is_noo = 1;
- $customer->status_id = 10;
- if ($customer->save()) {
- // save customer_token
- $customer_token = new CustomerToken();
- $customer_token->ar_customer_id = $customer->id;
- $customer_token->firebase_token = $request->firebase_token;
- $customer_token->status_id = 10;
- if(!$customer_token->save()){
- $status = -1;
- DB::rollBack();
- }
- foreach($request->address as $address_customer){
- //dd($address_customer->name);
- $customer_address = new CustomerAddress;
- $customer_address->name = $address_customer['name'];
- $customer_address->ar_customer_id = $customer->id;
- $customer_address->sd_so_main_id = $address_customer['sd_so_main_id'];
- $customer_address->address = $address_customer['address'];
- $customer_address->is_default = $address_customer['is_default'];
- if(!$customer_address->save()){
- $status = -1;
- DB::rollBack();
- }
- }
- $sequence = OrderParameterController::get_number($customer->id);
- $cust_id = "CUST" . $sequence;
- $customer->cust_id = $cust_id;
- $customer->save();
- $status = 0;
- DB::commit();
- $content = Customer::findOrFail($customer->id);
- //$this->create_otp($customer->id);
- } else {
- DB::rollBack();
- $status = -1;
- }
- } else if ($check_phone_number != null) {
- $status = 103;
- } else if ($check_email != null) {
- $status = 127;
- }elseif ($sd_so_main == null){
- $status = 100;
- } else {
- $status = -1;
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_banner(Request $request)
- {
- try {
- $today = date('Y-m-d');
- $gforce_daily_news = DailyNews::where('periode_start', '<=', $today)
- ->where('periode_end', '>=', $today)
- ->get();
- return \Response::json($gforce_daily_news);
- } catch (\Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_promo(Request $request)
- {
- try {
- $status = 0;
- $today = date('Y-m-d');
- $product_gift = ProductGift::where('until', '>=', $today)
- ->where('status_id', '10')
- ->get();
- $json = ['response_no' => $status,
- 'message' => GForceController::getMsgApi($status),
- 'banner' => $product_gift
- ];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function login_customer(Request $request)
- {
- try {
- $content = null;
- $customer = null;
- $status = 0;
- $email = $request->email;
- $phone_number = $request->phone_number;
- $firebase_token = $request->firebase_token;
- $password = $request->password;
- if ($email != "") {
- $customer = Customer::where('email', $email)->first();
- } else if ($phone_number != "") {
- $customer = Customer::where('phone_number', $phone_number)->first();
- }
- // dd($customer);
- if ($customer && Hash::check($password, $customer->password)) {
- // $customer_token = CustomerToken::firstOrNew('ar_customer_id', $customer->id)->first();
- // $customer_token = $firebase_token;
- // $customer_token->save();
- // $customer_token = CustomerToken::firstOrCreate([
- // 'ar_customer_id' => $customer->id
- // ], [
- // 'ar_customer_id' => $customer->id,
- // 'firebase_token' => $firebase_token,
- // 'status_id'=>'10',
- // ]);
- if($customer->status_id == 10){
- $customer_token = CustomerToken::where('ar_customer_id', $customer->id)->first();
- if ($customer_token != null) {
- $update_token = CustomerToken::find($customer_token->id);
- $update_token->firebase_token = $firebase_token;
- $update_token->status_id = 10;
- $update_token->save();
- } else {
- $create_token = new CustomerToken();
- $create_token->ar_customer_id = $customer->id;
- $create_token->firebase_token = $firebase_token;
- $create_token->status_id = 10;
- $create_token->save();
- }
- $status = 122;
- }else{
- $status = 133;
- }
- $content = $customer;
- } else {
- $status = 123;
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function customer_detail(Request $request)
- {
- try {
- $status = '0';
- $customer_detail = [];
- $today = date('Y-m-d');
- $ar_customer_id = $request->ar_customer_id;
- $last_balance = 0;
- $cek_customer = Customer::find($ar_customer_id);
- $customer = DB::table('ar_customer')
- ->leftjoin('ar_customer_point', 'ar_customer_point.ar_customer_id', 'ar_customer.id')
- ->leftjoin('ar_payment_term', 'ar_payment_term.id', 'ar_customer.ar_payment_term_id')
- ->select('ar_customer.*', DB::raw('SUM(ar_customer_point.amount) as total_point'), 'ar_payment_term.name as payment_name','ar_payment_term.payment_days as payment_days')
- ->where('ar_customer.id', $ar_customer_id)
- ->where('ar_customer_point.valid_to', '>=', $today)
- ->get();
- $customer_address = "";
- $customer_notification = CustomerNotification::where('ar_customer_id', $ar_customer_id)->where('status_id', 3)->get();
- $total_notif = sizeof($customer_notification);
- if ($cek_customer == null) {
- $status = '115';
- } else {
- $customer_detail = $customer;
- $customer_address = CustomerAddress::where('ar_customer_id', $ar_customer_id)->where('is_default', 1)->first();
- $available_cl = DB::table('gforce_payment_history')
- ->where('ar_customer_id', $ar_customer_id)
- ->select('last_balance')
- ->orderBy('id', 'desc')
- ->first();
- if(!empty($available_cl)){
- $last_balance = $available_cl->last_balance;
- }
- }
- $json = ['code' => $status,
- 'message' => GForceController::getMsgApi($status),
- 'customer_detail' => $customer_detail,
- 'customer_address'=>$customer_address,
- 'available_cl'=>$last_balance,
- 'customer_notification'=>$total_notif];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function edit_customer(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $customer = Customer::find($request->ar_customer_id);
- if ($customer != null) {
- $check_existing_phone_number = Customer::where('phone_number', $request->phone_number);
- // $check_postal_code = PostalCode::find($request->delivery_postal_code_id);
- $customer->phone_number = $request->phone_number;
- $customer->email = $request->email;
- $customer->name = $request->name;
- // $customer->delivery_postal_code_id = $request->delivery_postal_code_id;
- // $customer->address_delivery_1 = $request->address_delivery_1;
- // // $customer->gl_branch_id = $check_postal_code->gl_branch_id;
- $customer->status_id = 10;
- if ($customer->save()) {
- $status = 0;
- $content = $customer;
- } else {
- $status = -1;
- }
- } else {
- $status = 115;
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function check_customer(Request $request)
- {
- try {
- $content = null;
- $customer = null;
- $status = 0;
- $email = $request->email;
- $phone_number = $request->phone_number;
- $password = $request->password;
- if ($email != "") {
- $customer = Customer::where('email', $email)->first();
- } else if ($phone_number != "") {
- $customer = Customer::where('phone_number', $phone_number)->first();
- }
- if ($customer != null) {
- $status = 0;
- $content = $customer;
- } else {
- $status = 115;
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_list_address(Request $request) {
- $ar_customer_id = $request['ar_customer_id'];
- $get_data = DB::table('ar_customer_address as a')
- ->join('sd_so_main as b', 'a.sd_so_main_id', '=', 'b.id')
- ->where('a.ar_customer_id', '=', $ar_customer_id)
- ->select('a.*', 'b.name as city_name')
- ->get();
- if ($get_data != null) {
- $code = 0;
- } else {
- $code = -1;
- }
- $json = array(
- 'response_no'=>$code,
- 'message'=>GForceController::getMsgApi($code),
- 'data'=>$get_data
- );
- return response($json);
- }
- public function add_address(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $ar_customer_id = $request->ar_customer_id;
- $sd_so_main_id = $request->sd_so_main_id;
- DB::beginTransaction();
- if ($ar_customer_id != "" && $sd_so_main_id != "") {
- $customer = Customer::where('id', $ar_customer_id)->first();
- $city = SalesOrganization::where('id', $sd_so_main_id)->first();
- if($customer != null && $city != null){
- $new_customer_address = new CustomerAddress;
- $new_customer_address->ar_customer_id = $customer->id;
- $new_customer_address->is_default = $request->is_default;
- $new_customer_address->name = $request->name;
- $new_customer_address->address = $request->address;
- $new_customer_address->sd_so_main_id = $sd_so_main_id;
- if($new_customer_address->save()){
- DB::commit();
- $content = $new_customer_address;
- }else{
- DB::rollBack();
- $status = -1;
- }
- }else{
- $status = 115;
- }
- } else{
- $status = 115;
- // $customer = Customer::where('phone_number', $phone_number)->first();
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function edit_address(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $ar_customer_id = $request->ar_customer_id;
- $sd_so_main_id = $request->sd_so_main_id;
- $ar_customer_address_id = $request->ar_customer_address_id;
- // $default = 0;
- DB::beginTransaction();
- if ($ar_customer_id != "" && $sd_so_main_id != "" && $ar_customer_address_id != "") {
- $customer = Customer::where('id', $ar_customer_id)->first();
- $city = SalesOrganization::where('id', $sd_so_main_id)->first();
- if($customer != null && $city != null){
- $update_customer_address = CustomerAddress::find($ar_customer_address_id);
- $update_customer_address->ar_customer_id = $customer->id;
- $update_customer_address->is_default = $request->is_default;
- $update_customer_address->name = $request->name;
- $update_customer_address->address = $request->address;
- $update_customer_address->sd_so_main_id = $sd_so_main_id;
- if($update_customer_address->save()){
- if($request->is_default == 1){
- $update_others = DB::table('ar_customer_address')
- ->where('ar_customer_id', '=', $customer->id)
- ->whereNotIn('id', array($update_customer_address->id))
- ->update(['is_default'=>0]);
- }
- DB::commit();
- $content = $update_customer_address;
- }else{
- DB::rollBack();
- $status = -1;
- }
- }else{
- $status = 115;
- }
- } else{
- $status = 115;
- // $customer = Customer::where('phone_number', $phone_number)->first();
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function delete_address(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $ar_customer_id = $request->ar_customer_id;
- $sd_so_main_id = $request->city_id;
- $ar_customer_address_id = $request->ar_customer_address_id;
- DB::beginTransaction();
- if ($ar_customer_address_id != "") {
- // $customer = Customer::where('id', $ar_customer_id)->first();
- // $city = City::where('id', $sd_city_id)->first();
- $delete_customer_address = CustomerAddress::find($ar_customer_address_id);
- if($delete_customer_address->delete()){
- DB::commit();
- }else{
- DB::rollBack();
- $status = -1;
- }
- } else{
- $status = 115;
- // $customer = Customer::where('phone_number', $phone_number)->first();
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function change_password(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $customer = Customer::find($request->ar_customer_id);
- if ($customer != null) {
- $customer->password = Hash::make($request->password);
- $customer->is_default_password = 0;
- if ($customer->save()) {
- $status = 0;
- $content = $customer;
- } else {
- $status = -1;
- }
- } else {
- $status = 115;
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_product_category(Request $request)
- {
- try {
- $searching = $request['searching'];
- $product_category = ProductCategory::where('status_id', 10)->where('im_product_category_type_id', $this->customer_category_type_to_ecommerce->int_1)->get();
- $list_product_category = array();
- $x = 0;
- foreach ($product_category as $no => $detail) {
- if (sizeof($detail->im_product_category_profile) > 0) {
- $list_product_category[$x] = $detail;
- $x++;
- }
- }
- return Response::json($list_product_category);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function search_product(Request $request)
- {
- try {
- $searching = $request['searching'];
- $m_company_id = $request['m_company_id'];
- $ar_customer_id = $request['ar_customer_id'];
- $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
- ->where('is_default', 1)
- ->first();
- // dd($get_city->sd_so_main_id);
- if (!empty($get_branch->sd_so_main)) {
- $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
- // dd($get_price_group);
- if(!empty($get_price_group)){
- $product = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
- ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
- ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
- ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
- ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
- ->where('im_product.status_id', 10)
- ->where('im_product.name', 'like', '%' . strtolower($searching) . '%')
- ->where('im_product_branch.m_company_id', $m_company_id)
- ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
- ->get();
- }else {
- $product = [];
- }
- // dd($product);
- }else {
- $product = [];
- }
- return Response::json($product);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function search_product_by_category(Request $request)
- {
- try {
- $searching = $request['searching'];
- $m_company_id = $request['m_company_id'];
- $ar_customer_id = $request['ar_customer_id'];
- $category_id = $request['category_id'];
- $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
- ->where('is_default', 1)
- ->first();
- // dd($get_city->sd_so_main_id);
- if (!empty($get_branch->sd_so_main)) {
- $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
- // dd($get_price_group);
- // dd($get_harga_by_city->id);
- if(!empty($get_price_group)){
- $product = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
- ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
- ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
- ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
- ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
- ->where('im_product.status_id', 10)
- ->where('im_product.name', 'like', '%' . strtolower($searching) . '%')
- ->where('im_product_category_profile.im_product_category_id', $category_id)
- ->where('im_product_branch.m_company_id', $m_company_id)
- ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
- ->get();
- } else {
- $product = [];
- }
- // dd($product);
- }else {
- $product = [];
- }
- return Response::json($product);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_product_by_category(Request $request)
- {
- try {
- $category_id = $request['category_id'];
- $m_company_id = $request['m_company_id'];
- $ar_customer_id = $request['ar_customer_id'];
- $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
- ->where('is_default', 1)
- ->first();
- // dd($get_branch->sd_so_main);
- if (!empty($get_branch->sd_so_main)) {
- $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
- // dd($get_harga_by_city->id);
- if(!empty($get_price_group)){
- $product = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
- ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
- ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
- ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
- ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
- ->where('im_product.status_id', 10)
- ->where('im_product_category_profile.im_product_category_id', $category_id)
- ->where('im_product_branch.m_company_id', $m_company_id)
- ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
- ->get();
- }else {
- $product = [];
- }
- }else{
- $product = [];
- }
- return Response::json($product);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_product_by_category_sort(Request $request)
- {
- try {
- $category_id = $request['category_id'];
- $m_company_id = $request['m_company_id'];
- $ar_customer_id = $request['ar_customer_id'];
- $param = $request['sort'];
- $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
- ->where('is_default', 1)
- ->first();
- if (!empty($get_branch->sd_so_main)) {
- $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
- if(!empty($get_price_group)){
- $product_sort = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
- ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
- ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
- ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
- ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
- ->where('im_product.status_id', 10)
- ->where('im_product_category_profile.im_product_category_id', $category_id)
- ->where('im_product_branch.m_company_id', $m_company_id)
- ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
- ->orderBy('sd_catalog_item.harga', $param)
- ->get();
- }else {
- $product_sort = [];
- }
- // dd($product);
- }else {
- $product_sort = [];
- }
- return Response::json($product_sort);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_product_detail(Request $request)
- {
- try {
- $product_id = $request['product_id'];
- $ar_customer_id = $request['ar_customer_id'];
- if($product_id != '' && $ar_customer_id != ''){
- $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
- ->where('is_default', 1)
- ->first();
- // dd($get_branch->sd_so_main);
- if (!empty($get_branch->sd_so_main)) {
- $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
- if(!empty($get_price_group)){
- $product = Product::join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
- ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
- ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
- ->where('im_product.id', $product_id)
- ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
- ->first();
- }else {
- $product = [];
- }
- }else {
- $product = [];
- }
- }else{
- $product = ['code' => '-1', 'message' => GForceController::getMsgApi(-1)];
- }
- return Response::json($product);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_payment_term(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $status_for_ecommerce = 1;
- $payment_term = PaymentTerm::where('status_for_ecommerce', $status_for_ecommerce)->get();
- return Response::json($payment_term);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_payment_term_by_customer(Request $request)
- {
- try {
- $ar_customer = Customer::find($request['ar_customer_id']);
- $payment_term = array();
- if ($ar_customer != null) {
- $payment_term = PaymentTerm::where('id', $ar_customer->ar_payment_term_id)->get();
- }else{
- $payment_term = [];
- }
- return Response::json($payment_term);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_order_detail(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $order_id = $request['order_id'];
- $sd_order_header = OrderHeader::join('ar_customer', 'ar_customer.id', 'sd_order_header.ar_customer_id')
- ->join('status', 'sd_order_header.status_id', 'status.id')
- ->join('status as status_pembayaran', 'sd_order_header.status_pembayaran_id', 'status_pembayaran.id')
- ->join('ar_customer_address', 'sd_order_header.ar_customer_address_id', 'ar_customer_address.id')
- ->select('sd_order_header.*', 'ar_customer.address_delivery_1',
- 'status.status_name as status_transaksi','status_pembayaran.status_name as status_pembayaran','ar_customer_address.address as address_name')->find($order_id);
- $sd_order_detail = OrderDetail::join('im_product', 'im_product.id', 'sd_order_detail.im_product_id')
- ->select('sd_order_detail.*', 'im_product.*')
- ->where('sd_order_header_id', $order_id)->get();
- $history_payment = GforcePaymentConfirmation::join('status', 'gforce_payment_confirmation.status_id', 'status.id')
- ->select('gforce_payment_confirmation.*', 'status.status_name as status_payment')
- ->where('gforce_payment_confirmation.sd_order_header_id', $order_id)->where('status_id', '!=', 720)->get();
- $sisa_bayar = DB::table('gforce_payment_confirmation')
- ->where('sd_order_header_id', $order_id)
- ->where('status_id', 610)
- ->select('sisa_bayar')
- ->orderBy('sisa_bayar', 'asc')
- ->first();
- // dd($sisa_bayar);
- if($sisa_bayar != null){
- $sd_order_header['sisa_bayar'] = $sisa_bayar->sisa_bayar;
- }else{
- $sd_order_header['sisa_bayar'] = "";
- }
- $sd_order_header['order_detail'] = $sd_order_detail;
- $sd_order_header['history_payment'] = $history_payment;
- return Response::json($sd_order_header);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_status_for_order(Request $request)
- {
- try {
- $status = Status::select('status.*')
- ->join('status_child', 'status_child.status_id', 'status.id')
- ->join('status_on_table', 'status_on_table.status_parent_id', 'status_child.status_parent_id')
- ->where('on_table', 'ecommerce_order_status')
- ->get();
- return Response::json($status);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function history_order(Request $request)
- {
- try {
- $ar_customer_id = $request['ar_customer_id'];
- $sd_order_header = OrderHeader::join('status', 'status.id', 'sd_order_header.status_id')
- ->select('sd_order_header.*', 'status.status_name')
- ->where('ar_customer_id', $ar_customer_id)
- ->orderBy('id', 'desc')
- ->get();
- return Response::json($sd_order_header);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_order_by_status(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $ar_customer_id = $request['ar_customer_id'];
- $status_id = $request['status_id'];
- if ($status_id == "") {
- $sd_order_header = OrderHeader::join('status', 'status.id', 'sd_order_header.status_id')
- ->where('ar_customer_id', $ar_customer_id)
- ->where('sd_order_header.no_order', 'like', '%' . strtolower('OFO') . '%')
- ->select('sd_order_header.*', 'status.status_name')
- ->orderBy('id', 'desc')
- ->get();
- } else {
- $sd_order_header = OrderHeader::join('status', 'status.id', 'sd_order_header.status_id')
- ->where('ar_customer_id', $ar_customer_id)
- ->where('status_id', $status_id)
- ->where('sd_order_header.no_order', 'like', '%' . strtolower('OFO') . '%')
- ->select('sd_order_header.*', 'status.status_name')
- ->orderBy('id', 'desc')
- ->get();
- }
- return Response::json($sd_order_header);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public static function so_order_header($sd_so_main_id, $sd_order_header_id){
- // $sip = 'Oke nih';
- $so = SalesOrganization::where('id', $sd_so_main_id)->first();
- if(!empty($so)){
- $so_order_header = new SoOrderHeader;
- $so_order_header->sd_so_main_id = $so->id;
- $so_order_header->type_so_id = $so->type_so_id;
- $so_order_header->sd_order_header_id = $sd_order_header_id;
- if($so_order_header->save()){
- SELF::so_order_header($so->parent_id,$sd_order_header_id);
- }
- }
- }
- public function get_contact(Request $request){
- try{
- if(!empty($request->ar_customer_id)){
- $customer = Customer::where('id', $request->ar_customer_id)->first();
- if(!empty($customer)){
- $mcompany = MCompany::where('id', $customer->m_company_id)->select('contact_number')->first();
- $code = 0;
- $message = 'succes';
- $result = $mcompany;
- }else{
- $code = 115;
- $message = 'failed';
- $result = [];
- }
- }else{
- $code = -1;
- $message = 'failed';
- $result = [];
- }
- $json = array(
- "code" => $code,
- "message" => $message,
- "get_contact" => $result
- );
- return response()->json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function store_order(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $array_of_tax = array();
- $total_array_of_poin_transaksi = 0;
- $array_of_poin_transaksi = array();
- $total_array_of_poin_product = 0;
- $array_of_poin_product = array();
- $total_array_of_tax = 0;
- $total_poin = 0;
- $point = array();
- $today = date('Y-m-d');
- $p = 1;
- $day = $this->add_valid_customer_poin->int_1;
- $valid = '+' . $day . ' days';
- // dd($valid);
- $array_of_no_tax = array();
- $total_array_of_no_tax = 0;
- $point = DB::table('point_ofo')->where('valid_to', '>=', $today)->where('status_id', 10)->get();
- $check_customer_point = DB::table('ar_customer_point')->where('ar_customer_id', '=', $request->ar_customer_id)->first();
- // dd($point);
- foreach ($point as $detail_point) {
- if ($detail_point->type_poin == 1) {
- $array_of_poin_product[$total_array_of_poin_product] = $detail_point;
- $total_array_of_poin_product++;
- } else {
- $array_of_poin_transaksi[$total_array_of_poin_transaksi] = $detail_point;
- $total_array_of_poin_transaksi++;
- }
- }
- $detail_order = $request->detail;
- $check_customer = Customer::find($request->ar_customer_id);
- if($request->payment_type == "TOP"){
- if ($request->ar_payment_term_id == null || $request->ar_payment_term_id == "") {
- $first_payment_term = PaymentTerm::find($check_customer->ar_payment_term_id);
- $ar_payment_term_id = $first_payment_term->id;
- }
- }else {
- $first_payment_term = PaymentTerm::find($check_customer->ar_payment_term_id);
- $ar_payment_term_id = $first_payment_term->id;
- }
- // dd($check_customer);
- if ($check_customer == null) {
- $status = 120;
- } else {
- $get_city = CustomerAddress::where('id', $request->ar_customer_address_id)->first();
- DB::beginTransaction();
- $head = new OrderHeader;
- $head->no_order = OrderParameterController::get_code();
- $head->sd_order_type_id = 1;
- $head->payment_type = $request->payment_type;
- $head->is_paid = $request->is_paid;
- $head->paid_off = "N";
- $head->status_pembayaran_id = 700;
- $head->ar_customer_id = $request->ar_customer_id;
- $head->sd_employee_id = ($check_customer->sd_employee == NULL || $check_customer->sd_employee == 0)? NULL: $check_customer->sd_employee_id;
- $head->time_transaction = DB::raw('now()');
- $head->ar_payment_term_id = $ar_payment_term_id;
- $head->m_company_id = $request->m_company_id;
- $head->payment_notes = $request->payment_note;
- $head->ar_customer_address_id = $request->ar_customer_address_id;
- $head->status_id = 140;
- if ($head->save()) {
- $sd_order_header = OrderHeader::where('id', $head->id)->first();
- $sd_order_header->order_amt = 0;
- $so = SELF::so_order_header($get_city->sd_so_main_id, $head->id);
- foreach ($detail_order as $keyDet => $valDet) {
- $check_product = Product::find($valDet['im_product_id']);
- // dd($valDet['im_product_id']);
- if ($check_product == null) {
- DB::rollBack();
- $status = 120;
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status)];
- return json_encode($json);
- } else {
- $tax_amt = $valDet['tax_pct'] / 100 * $valDet['price_per_pcs'];
- $det = new OrderDetail;
- $det->sd_order_header_id = $head->id;
- $det->no_order = $head->no_order;
- $det->im_product_id = $valDet['im_product_id'];
- $det->qty = $valDet['qty'];
- $det->price_per_pcs = $valDet['price_per_pcs'];
- $det->qty_approved = $valDet['qty'];
- $det->price_per_pcs_approved = $valDet['price_per_pcs'];
- $det->tax_pct = $valDet['tax_pct'];
- $det->tax_amt = $tax_amt;
- $price_before_tax = $valDet['qty'] * $valDet['price_per_pcs'];
- $price_after_tax = $price_before_tax + ($valDet['qty'] * $tax_amt);
- $sd_order_header->order_amt = $sd_order_header->order_amt + ($price_after_tax);
- foreach ($array_of_poin_product as $keyProd => $valProd) {
- if ($valProd->im_product_id == $valDet['im_product_id'] && $valDet['qty'] >= $valProd->qty) {
- if ($valProd->is_kelipatan == 1) {
- $hasil = $valDet['qty'] / $valProd->qty;
- $total_kelipatan = floor($hasil);
- if ($total_kelipatan > 0) {
- $total_poin = $total_poin + ($valProd->get_poin * $total_kelipatan);
- } else {
- $total_poin = $total_poin + $valProd->get_poin;
- }
- } else {
- $total_poin = $total_poin + $valProd->get_poin;
- }
- }
- }
- if (!$det->save()) {
- DB::rollBack();
- $status = 120;
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status)];
- return json_encode($json);
- }
- }
- }
- if ($sd_order_header->save()) {
- $sd_order_detail = OrderDetail::where('sd_order_header_id', $head->id)->get();
- $sd_order_header['order_detail'] = $sd_order_detail;
- foreach ($array_of_poin_transaksi as $keyTran => $valTran) {
- if ($sd_order_header->order_amt >= $valTran->total_transaksi) {
- if ($valTran->is_kelipatan == 1) {
- $hasil_transaksi = $sd_order_header->order_amt / $valTran->total_transaksi;
- $total_kelipatan_transaksi = floor($hasil_transaksi);
- if ($total_kelipatan_transaksi > 0) {
- $total_poin = $total_poin + ($valTran->get_poin * $total_kelipatan_transaksi);
- } else {
- $total_poin = $total_poin + $valTran->get_poin;
- }
- } else {
- $total_poin = $total_poin + $valTran->get_poin;
- }
- }
- }
- if ($check_customer_point == null) {
- //dd($total_poin);
- $valid = date('Y-m-d', strtotime($valid, strtotime($today)));
- $customer_point = new CustomerPoint;
- $customer_point->ar_customer_id = $request->ar_customer_id;
- $customer_point->amount = $total_poin;
- $customer_point->valid_to = $valid;
- $customer_point->save();
- } else {
- $sum_poin = $check_customer_point->amount + $total_poin;
- $sum_valid = date('Y-m-d', strtotime($valid, strtotime($check_customer_point->valid_to)));
- // dd($sum_poin);
- $update_customer_point = DB::table('ar_customer_point')->where('ar_customer_id', $check_customer_point->ar_customer_id)->update(['amount' => $sum_poin, 'valid_to' => $sum_valid]);
- }
- DB::commit();
- $status = 0;
- $content = $sd_order_header;
- } else {
- DB::rollBack();
- $status = -1;
- }
- if ($this->auto_send_order->int_1 == 1) {
- StagingController::store_order($sd_order_header->id);
- }
- } else {
- // Do Nothing
- }
- }
- $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
- return Response::json($json);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function update_order(Request $request)
- {
- try {
- DB::beginTransaction();
- $sd_order_header_id = $request->sd_order_header_id;
- $is_cod = $request->is_cod;
- $tgl_pembayaran = strval($request->tgl_pembayaran);
- $image_path = "storage/uploads/order/";
- GForceController::check_exist_folder($image_path);
- $sd_order_header = OrderHeader::find($sd_order_header_id);
- // dd($sd_order_header);
- $pembayaran = GforcePaymentConfirmation::where('sd_order_header_id', $sd_order_header_id)->where('status_id', 610)->get();
- // $sisa_bayar = DB::table('gforce_payment_confirmation')->where('sd_order_header_id', $sd_order_header_id)->select(\DB::raw("MIN(sisa_bayar) as sisa_bayar"))->first();
- // dd($pembayaran);
- $gl_bank_id = GlBank::find($request->detail['gl_bank_id_pengirim']);
- $gl_bank_company_id = GlBankCompany::find($request->detail['gl_bank_company_id']);
- if ($sd_order_header != null) {
- if ($is_cod) {
- $total_order = OrderHeader::find($sd_order_header_id);
- $payment_confirmation = new GforcePaymentConfirmation();
- $payment_confirmation->sd_order_header_id = $sd_order_header_id;
- $payment_confirmation->status_id = 600;
- $payment_confirmation->tgl_pembayaran = $tgl_pembayaran;
- $payment_confirmation->is_cod = $request->is_cod;
- $payment_confirmation->nominal_transfer = $total_order->order_net_amt;
- $payment_confirmation->sisa_bayar = $total_order->order_net_amt;
- $payment_confirmation->deskripsi = $request->deskripsi;
- if ($payment_confirmation->save()) {
- $payment_confirmation_photo = new GforcePaymentConfirmationPhoto();
- $payment_confirmation_photo->gforce_payment_confirmation_id = $payment_confirmation->id;
- if ($request->transfer_receipt != null || $request->transfer_receipt != "") {
- $image_upload = $image_path . $payment_confirmation->id . date("YmdHis") . ".jpg";
- file_put_contents($image_upload, base64_decode($request->transfer_receipt));
- $payment_confirmation_photo->picture_path = $image_upload;
- }
- if ($payment_confirmation_photo->save()) {
- $order = OrderHeader::find($sd_order_header_id);
- $order->is_paid = "Y";
- if($order->save()){
- DB::commit();
- $code = 0;
- }
- }
- } else {
- DB::rollBack();
- $code = -1;
- }
- } else {
- if ($gl_bank_id != null && $gl_bank_company_id != null) {
- $payment_confirmation = new GforcePaymentConfirmation();
- $payment_confirmation->sd_order_header_id = $sd_order_header_id;
- $payment_confirmation->status_id = 600;
- $payment_confirmation->nama_pengirim = $request->detail['nama_pengirim'];
- $payment_confirmation->no_rekening_pengirim = $request->detail['no_rekening_pengirim'];
- $payment_confirmation->gl_bank_id_pengirim = $gl_bank_id->id;
- $payment_confirmation->nominal_transfer = $request->detail['nominal_transfer'];
- $payment_confirmation->cabang_bank_pengirim = $request->detail['cabang_bank_pengirim'];
- $payment_confirmation->tgl_pembayaran = $tgl_pembayaran;
- $payment_confirmation->gl_bank_company_id = $gl_bank_company_id->id;
- $payment_confirmation->is_cod = $request->is_cod;
- $payment_confirmation->deskripsi = $request->deskripsi;
- if(empty($pembayaran)){
- $payment_confirmation->sisa_bayar = $sd_order_header->order_net_amt;
- }else{
- // $sisa_bayar = DB::table('gforce_payment_confirmation')->where('sd_order_header_id', $sd_order_header_id)->select(\DB::raw("MIN(sisa_bayar) as sisa_bayar"))->where('status_id', 620)->first();
- $sisa_bayar = DB::table('gforce_payment_confirmation')
- ->where('sd_order_header_id', $sd_order_header_id)
- ->where('status_id', 610)
- ->select('sisa_bayar')
- ->orderBy('sisa_bayar', 'asc')
- ->first();
- // dd($sisa_bayar);
- if($sisa_bayar != null){
- $payment_confirmation->sisa_bayar = $sisa_bayar->sisa_bayar;
- }else{
- $payment_confirmation->sisa_bayar = $sd_order_header->order_net_amt;
- }
- }
- if ($payment_confirmation->save()) {
- $payment_confirmation_photo = new GforcePaymentConfirmationPhoto();
- $payment_confirmation_photo->gforce_payment_confirmation_id = $payment_confirmation->id;
- if ($request->transfer_receipt != null || $request->transfer_receipt != "") {
- $image_upload = $image_path . $payment_confirmation->id . date("YmdHis") . ".jpg";
- file_put_contents($image_upload, base64_decode($request->transfer_receipt));
- $payment_confirmation_photo->picture_path = $image_upload;
- }
- if ($payment_confirmation_photo->save()) {
- $order = OrderHeader::find($sd_order_header_id);
- $order->is_paid = "Y";
- if($order->save()){
- DB::commit();
- $code = 0;
- }
- }
- } else {
- DB::rollBack();
- $code = -1;
- }
- } else {
- $code = 115;
- }
- }
- } else {
- $code = 115;
- }
- $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
- return Response::json($json);
- } catch (\Exception $e) {
- return Response::json($e->getMessage());
- }
- }
- public function get_order_notification(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $ar_customer_id = $request['ar_customer_id'];
- $status_id = 150; // Confirmed Status
- $sd_order_header = OrderHeader::where('ar_customer_id', $ar_customer_id)
- ->where('send_to_staging', 1)
- ->where('update_from_staging', 1)
- ->where('notification_send', 0)
- ->where('status_id', $status_id)
- ->get();
- $update_order = OrderHeader::where('ar_customer_id', $ar_customer_id)
- ->where('send_to_staging', 1)
- ->where('update_from_staging', 1)
- ->where('notification_send', 0)
- ->where('status_id', $status_id)
- ->update(['notification_send' => 1]);
- return Response::json($sd_order_header);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_notification_ofo(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $ar_customer_id = $request['ar_customer_id'];
- $status_id = 150; // Confirmed Status
- $sd_order_header = OrderHeader::where('ar_customer_id', $ar_customer_id)
- ->join('status', 'status.id', 'sd_order_header.status_id')
- ->where('send_to_staging', 1)
- ->where('update_from_staging', 1)
- ->where('notification_send', 1)
- ->select(DB::raw('sd_order_header.id,sd_order_header.no_order,status.status_name, DATE(sd_order_header.updated_at) as date'))
- ->where('status_id', $status_id)
- ->get();
- // $json = ['status'=>$status_id,'order'=>$sd_order_header];
- return Response::json($sd_order_header);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function routine_order(Request $request)
- {
- try {
- $content = null;
- $status = 0;
- $ar_customer_id = $request['ar_customer_id'];
- if($ar_customer_id != ''){
- $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
- ->where('is_default', 1)
- ->first();
- if (!empty($get_branch->sd_so_main)) {
- $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
- if(!empty($get_price_group)){
- $product = Product::join('sd_order_detail', 'sd_order_detail.im_product_id', 'im_product.id')
- ->join('sd_order_header', 'sd_order_header.id', 'sd_order_detail.sd_order_header_id')
- ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
- ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
- ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
- ->where('sd_order_header.ar_customer_id', $ar_customer_id)
- ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
- ->distinct()
- ->get();
- }else {
- $product = [];
- }
- }else {
- $product = [];
- }
- }else{
- $product = ['code' => '-1', 'message' => GForceController::getMsgApi(-1)];
- }
- return Response::json($product);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function gifts_product(Request $request)
- {
- try {
- $code = '0';
- $today = date('Y-m-d');
- $gifts_product = ProductGift::join('im_product', 'im_product_gift.im_product_id', 'im_product.id')
- ->select('im_product_gift.id as im_product_gift_id',
- 'im_product_gift.point as point',
- 'im_product_gift.valid_to as im_product_gift_until',
- 'im_product_gift.description as im_product_gift_description',
- 'im_product_gift.image as im_product_gift_image',
- 'im_product_gift.status_id',
- 'im_product.*')
- ->where('im_product_gift.valid_to', '>=', $today)
- ->get();
- $json = ['code' => $code, 'message' => GForceController::getMsgApi($code), 'list_product_gifts' => $gifts_product];
- return Response::json($json);
- } catch (Exception $e) {
- $code = '-1';
- $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
- }
- }
- public function history_redeem(Request $request)
- {
- try {
- $code = '0';
- // $today = date('Y-m-d');
- $history_redeem = CustomerGiftClaim::join('status', 'ar_customer_gift_claim.status_id', 'status.id')
- ->join('im_product_gift', 'ar_customer_gift_claim.im_product_gift_id', 'im_product_gift.id')
- ->join('im_product', 'im_product_gift.im_product_id', 'im_product.id')
- ->select('ar_customer_gift_claim.*', 'status.status_name as status', 'im_product.name as product_name')
- ->where('ar_customer_gift_claim.ar_customer_id', $request->ar_customer_id)
- ->get();
- $json = ['code' => $code, 'message' => GForceController::getMsgApi($code), 'history_gift_claim' => $history_redeem];
- return Response::json($json);
- } catch (Exception $e) {
- $code = '-1';
- $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
- }
- }
- public function redeem_point(Request $request)
- {
- try {
- $today = date('Y-m-d');
- $customer_point = DB::table('ar_customer_point')->Where('ar_customer_id', '=', $request->ar_customer_id)
- ->Where('valid_to', '>=', $today)
- ->first();
- $im_product_gift = DB::table('im_product_gift')->where('id', '=', $request->im_product_gift)->where('status_id', 10)->first();
- // dd($customer_point->amount);
- if ($customer_point != null && $customer_point->amount >= $im_product_gift->point) {
- $calculate_poin = $customer_point->amount - $im_product_gift->point;
- DB::table('ar_customer_point')->where('ar_customer_id', $request->ar_customer_id)->update(['amount' => $calculate_poin]);
- $customerGiftClaim = new CustomerGiftClaim();
- $customerGiftClaim->ar_customer_id = $request->ar_customer_id;
- $customerGiftClaim->no_claim_gift = 'CG-' . $request->ar_customer_id . date('hms');
- $customerGiftClaim->im_product_gift_id = $request->im_product_gift;
- $customerGiftClaim->status_id = '740';
- if($customerGiftClaim->save()){
- $update_customer_point = DB::table('ar_customer_point')->where('ar_customer_id', $request->ar_customer_id)->update(['amount' => $calculate_poin]);
- $code = '0';
- }else{
- $code = '42';
- }
- } else {
- $code = '40';
- }
- $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
- return Response::json($json);
- } catch (Exception $e) {
- $code = '-1';
- $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
- }
- }
- public function get_menu_home(Request $request)
- {
- try {
- $ar_customer_id = $request['ar_customer_id'];
- $m_company_id = $request['m_company_id'];
- if($ar_customer_id != '' && $m_company_id != ''){
- /**
- * Banner
- */
- $today = date('Y-m-d');
- $gforce_daily_news = DailyNews::where('periode_start', '<=', $today)
- ->select('id', 'periode_start', 'periode_end', 'content', 'image', 'image_title')
- ->where('periode_end', '>=', $today)
- ->get();
- /**
- * Category
- */
- $product_category = ProductCategory::where('status_id', 10)->where('im_product_category_type_id', $this->customer_category_type_to_ecommerce->int_1)
- ->get();
- $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
- ->where('is_default', 1)
- ->first();
- if (!empty($get_branch->sd_so_main)) {
- $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
- if(!empty($get_price_group)){
- /*
- *Routine Order
- */
- $product = Product::join('sd_order_detail', 'sd_order_detail.im_product_id', 'im_product.id')
- ->join('sd_order_header', 'sd_order_header.id', 'sd_order_detail.sd_order_header_id')
- ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
- ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
- ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
- ->where('sd_order_header.ar_customer_id', $ar_customer_id)
- ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
- ->distinct()
- ->get();
- /*
- * Suggestion Order
- */
- $product_suggestion = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
- ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
- ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
- ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
- ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
- ->where('im_product.status_id', 10)
- ->where('im_product_branch.m_company_id', $m_company_id)
- ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
- ->take(10)
- ->get();
- }else {
- $product = [];
- $product_suggestion = [];
- }
- }else {
- $product = [];
- $product_suggestion = [];
- }
- $response = Array(
- "menu_home" => array(
- array(
- "menu_code" => "600",
- "menu_type" => "banner",
- "menu_list" => $gforce_daily_news
- ),
- array(
- "menu_code" => "610",
- "menu_type" => "Category",
- "menu_list" => $product_category
- ),
- array(
- "menu_code" => "620",
- "menu_type" => "Routine Oder",
- "menu_list" => $product
- ),
- array(
- "menu_code" => "630",
- "menu_type" => "Top Product",
- "menu_list" => $product_suggestion
- )
- )
- );
- }else{
- $response = ['code' => '-1', 'message' => GForceController::getMsgApi(-1)];
- }
- return Response::json($response);
- } catch (Exception $e) {
- $code = '-1';
- return Response::$json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
- }
- }
- public function search_history_order(Request $request)
- {
- try {
- $ar_customer_id = $request['ar_customer_id'];
- $searching = $request['searching'];
- $sd_order_header = OrderHeader::join('status', 'status.id', 'sd_order_header.status_id')
- ->where('ar_customer_id', $ar_customer_id)
- ->whereNull('gforce_customer_visit_id')
- ->where('sd_order_header.no_order', 'like', '%' . strtolower($searching) . '%')
- ->select('sd_order_header.*', 'status.status_name')
- ->orderBy('id', 'desc')
- ->get();
- return Response::json($sd_order_header);
- } catch (Exception $e) {
- return Response::json((string)$e->getResponse()->getBody());
- }
- }
- public function get_bank_company() {
- try {
- $data = GlBankCompany::join('gl_bank','gl_bank_company.gl_bank_id','gl_bank.id')
- ->select('gl_bank_company.*','gl_bank.name')
- ->get();
- if ($data != null) {
- $code = 0;
- $content = $data;
- } else {
- $code = -1;
- $content = [];
- }
- } catch (\Exception $e) {
- $code = -1;
- $content = [];
- }
- $json = array(
- 'response_no'=> $code,
- 'message' => GForceController::getMsgApi($code),
- 'data' => $content
- );
- return Response::json($json);
- }
- public function get_bank_master() {
- try {
- $data = GlBank::all();
- if ($data != null) {
- $code = 0;
- $content = $data;
- } else {
- $code = -1;
- $content = [];
- }
- } catch (\Exception $e) {
- $code = -1;
- $content = [];
- }
- $json = array(
- 'response_no'=> $code,
- 'message' => GForceController::getMsgApi($code),
- 'data' => $content
- );
- return Response::json($json);
- }
- public function check_price(Request $request) {
- $sd_so_main_id = $request->sd_so_main_id;
- $get_branch = SalesOrganization::where('id', $sd_so_main_id)->first();
- // dd($get_branch->parent_id);
- $sd_customer_price_group = CustomerPriceGroup::where('sd_so_main_id', $get_branch->parent_id)->first();
- if ($sd_customer_price_group != null) {
- $sd_catalog_item = CatalogItem::join('im_product', 'sd_catalog_item.im_product_id', 'im_product.id')
- ->where('sd_catalog_item.sd_customer_price_group_id', $sd_customer_price_group->id)
- ->whereIn('sd_catalog_item.im_product_id', $request->products)
- ->select('sd_catalog_item.*', 'im_product.name')->get();
- if (sizeof($sd_catalog_item) > 0) {
- $code = 0;
- $data = $sd_catalog_item;
- } else {
- $code = 115;
- $data = [];
- }
- } else {
- $code = 115;
- $data = [];
- }
- $json = array(
- 'response_no'=>$code,
- 'message'=>GForceController::getMsgApi($code),
- 'list_product'=>$data
- );
- return response($json);
- }
- public function test_order()
- {
- StagingController::postGuzzleRequest();
- }
- public function test_email()
- {
- //Mail::to("anggiahmadi@gmail.com")->send(new CustomerRegistration());
- }
- public static function send_firebase_notif($fb_token, $message_bodys) {
- $recipients = array($fb_token);
- fcm()
- ->to($recipients) // $recipients must an array
- ->priority('high')
- ->timeToLive(0)
- ->data([
- 'title' => 'Notification from HARSINDO',
- 'body' => $message_body,
- ])
- ->send();
- }
- }
Add Comment
Please, Sign In to add comment