Guest User

Untitled

a guest
Mar 31st, 2020
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 82.71 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\API;
  4.  
  5. use App\Http\Controllers\API\GForceController;
  6. use App\Models\Bank;
  7. use App\Models\CatalogItem;
  8. use App\Models\CustomerPriceGroup;
  9. use App\Models\CustomerToken;
  10. use App\Models\GforcePaymentConfirmation;
  11. use App\Models\GforcePaymentConfirmationPhoto;
  12. use App\Models\GlBank;
  13. use App\Models\GlBankCompany;
  14. use Illuminate\Http\Request;
  15. use App\Mail\CustomerRegistration;
  16. use App\Http\Controllers\Controller;
  17. use App\Http\Controllers\API\StagingController;
  18. use App\Http\Controllers\Transaction\OrderParameterController;
  19. use App\Models\Status;
  20. use App\Models\Parameter;
  21. use App\Models\OTPCustomer;
  22. use App\Models\Customer;
  23. use App\Models\CustomerPoint;
  24. use App\Models\SoOrderHeader;
  25. use App\Models\Country;
  26. use App\Models\Province;
  27. use App\Models\PointOFO;
  28. use App\Models\CustomerGiftClaim;
  29. use App\Models\City;
  30. use App\Models\District;
  31. use App\Models\PostalCode;
  32. use App\Models\PaymentTerm;
  33. use App\Models\ProductCategory;
  34. use App\Models\ProductGift;
  35. use App\Models\Product;
  36. use App\Models\ProductPhoto;
  37. use App\Models\OrderHeader;
  38. use App\Models\OrderDetail;
  39. use App\Models\SalesOrganization;
  40. use App\Models\DailyNews;
  41. use App\Models\EmployeeRoute;
  42. use App\Models\CustomerAddress;
  43. use App\Models\MCompany;
  44. use App\Models\CustomerNotification;
  45. use DB;
  46. use Hash;
  47. use Response;
  48. use Mail;
  49. use File;
  50.  
  51. class EcommerceController extends Controller
  52. {
  53. private $otp_time_in_sec;
  54. private $customer_category_type_to_ecommerce;
  55. private $sd_customer_price_group_id;
  56. private $auto_send_order;
  57.  
  58. public function __construct()
  59. {
  60. $this->otp_time_in_sec = Parameter::where('name_param', 'otp_time_in_sec')->first();
  61. $this->auto_send_order = Parameter::where('name_param', 'auto_send_order')->first();
  62. $this->add_valid_customer_poin = Parameter::select('int_1')->where('name_param', 'add_valid_customer_poin')->first();
  63. $this->customer_category_type_to_ecommerce = Parameter::where('name_param', 'customer_category_type_to_ecommerce')->first();
  64.  
  65. $this->sd_customer_price_group_id = Parameter::where('name_param', 'sd_customer_price_group_id')->first();
  66. $this->kota = Parameter::where('name_param', 'get_kota')->first();
  67. }
  68.  
  69. public function ajax_get_sd_country(Request $request)
  70. {
  71. $sd_country = Country::where('status_id', 10)->get();
  72. return Response::json($sd_country);
  73. }
  74.  
  75. public function ajax_get_sd_province(Request $request)
  76. {
  77. $country_id = $request->input('country_id');
  78. if ($country_id != null) {
  79. $sd_province = Province::where('country_id', $country_id)->where('status_id', 10)->get();
  80. } else {
  81. $sd_province = Province::where('status_id', 10)->get();
  82. }
  83. return Response::json($sd_province);
  84. }
  85.  
  86. public function ajax_get_sd_city(Request $request)
  87. {
  88. $province_id = $request->input('province_id');
  89. if ($province_id != null) {
  90. $sd_city = City::where('province_id', $province_id)->where('status_id', 10)->get();
  91. } else {
  92. $sd_city = City::where('status_id', 10)->get();
  93. }
  94. return Response::json($sd_city);
  95. }
  96.  
  97. public function ajax_get_sd_district(Request $request)
  98. {
  99. $city_id = $request->input('city_id');
  100. if ($city_id != null) {
  101. $sd_district = District::where('city_id', $city_id)->where('status_id', 10)->get();
  102. } else {
  103. $sd_district = District::where('status_id', 10)->get();
  104. }
  105. return Response::json($sd_district);
  106. }
  107.  
  108. public function ajax_get_sd_postal_code(Request $request)
  109. {
  110. $district_id = $request->input('district_id');
  111. if ($district_id != null) {
  112. $sd_postal_code = PostalCode::where('district_id', $district_id)->where('status_id', 10)->get();
  113. } else {
  114. $sd_postal_code = PostalCode::where('status_id', 10)->get();
  115. }
  116. return Response::json($sd_postal_code);
  117. }
  118.  
  119. public function ajax_get_sd_postal_code_detail(Request $request)
  120. {
  121. $postal_code_id = $request->input('postal_code_id');
  122. $sd_postal_code = DB::table('sd_postal_code')
  123. ->join('sd_district', 'sd_postal_code.district_id', 'sd_district.id')
  124. ->join('sd_city', 'sd_district.city_id', 'sd_city.id')
  125. ->join('sd_province', 'sd_city.province_id', 'sd_province.id')
  126. ->join('sd_country', 'sd_province.country_id', 'sd_country.id')
  127. ->select('sd_country.id as country_id',
  128. 'sd_province.id as province_id',
  129. 'sd_city.id as city_id',
  130. 'sd_district.id as district_id',
  131. 'sd_postal_code.id',
  132. 'sd_postal_code.zipcode',
  133. 'sd_postal_code.name',
  134. 'sd_postal_code.gl_branch_id'
  135. )
  136. ->where('sd_postal_code.id', $postal_code_id)
  137. ->first();
  138. return Response::json($sd_postal_code);
  139. }
  140.  
  141. public function get_kota(Request $request){
  142. try{
  143. $kota = SalesOrganization::where('type_so_id', $this->kota->int_1)->where('status_id',10)->get();
  144.  
  145. if(!empty($kota)){
  146. $code = 0;
  147. $message = 'succes';
  148. $result = $kota;
  149. }else{
  150. $code = 115;
  151. $message = 'failed';
  152. $result = [];
  153. }
  154. $json = array(
  155. "code" => $code,
  156. "message" => $message,
  157. "get_kota" => $result
  158. );
  159.  
  160. return response()->json($json);
  161. }catch (Exception $e) {
  162. echo $e->getResponse()->getBody();
  163. }
  164. }
  165.  
  166. public function create_otp($ar_customer_id)
  167. {
  168. try {
  169. $startTime = date("Y-m-d H:i:s");
  170. $cenvertedTime = date('Y-m-d H:i:s', strtotime('+' . $this->otp_time_in_sec->int_1 . ' seconds', strtotime($startTime)));
  171. $otp_customer = new OTPCustomer;
  172. $otp_customer->ar_customer_id = $ar_customer_id;
  173. $otp_customer->otp_number = mt_rand(100000, 999999);
  174. $otp_customer->valid_until = $cenvertedTime;
  175. if ($otp_customer->save()) {
  176. $customer = Customer::find($ar_customer_id);
  177. if ($customer->email != null) {
  178. Mail::to($customer->email)->send(new CustomerRegistration($otp_customer->otp_number));
  179. }
  180. } else {
  181. $this->create_otp($ar_customer_id);
  182. }
  183.  
  184. } catch (Exception $e) {
  185. echo $e->getResponse()->getBody();
  186. }
  187. }
  188.  
  189. public function recreate_otp(Request $request)
  190. {
  191. try {
  192. $ar_customer_id = $request->ar_customer_id;
  193. $this->create_otp($ar_customer_id);
  194. } catch (Exception $e) {
  195. echo $e->getResponse()->getBody();
  196. }
  197. }
  198.  
  199. public function get_customer_notification(Request $request) {
  200. $ar_customer_id = $request->ar_customer_id;
  201. $query = CustomerNotification::where('ar_customer_id', $ar_customer_id)->orderBy('created_at', 'desc')->get();
  202. if (sizeof($query) > 0) {
  203. $code = 30;
  204. $message = 'success';
  205. $result = $query;
  206. } else {
  207. $code = 40;
  208. $message = 'failed';
  209. $result = [];
  210. }
  211. $json = array(
  212. "code" => $code,
  213. "message" => $message,
  214. "get_customer_notification" => $result
  215. );
  216. return response()->json($json);
  217. }
  218.  
  219. public function get_customer_notification_detail(Request $request) {
  220. $id = $request->ar_customer_notification_id;
  221. // dd($id);
  222. $query = CustomerNotification::where('id', $id)->orderBy('created_at', 'desc')->first();
  223. if (!empty($query)) {
  224. CustomerNotification::where('id', $id)
  225. ->update([
  226. 'status_id' => 4
  227. ]);
  228. $code = 30;
  229. $message = 'success';
  230. $result = $query;
  231. } else {
  232. $code = 40;
  233. $message = 'failed';
  234. $result = [];
  235. }
  236. $json = array(
  237. "code" => $code,
  238. "message" => $message,
  239. "get_customer_notification_detail" => $result
  240. );
  241. return response()->json($json);
  242. }
  243.  
  244. public function check_otp(Request $request)
  245. {
  246. try {
  247. $ar_customer_id = $request->ar_customer_id;
  248. $otp_number = $request->otp_number;
  249.  
  250. $otp_customer = OTPCustomer::where('ar_customer_id', $ar_customer_id)
  251. ->where('otp_number', $otp_number)
  252. ->first();
  253.  
  254. if ($otp_customer != null) {
  255. if ($otp_customer->valid_until >= date("Y-m-d H:i:s")) {
  256. $ar_customer = Customer::find($ar_customer_id);
  257. $ar_customer->isVerified = 1;
  258. $ar_customer->save();
  259. $status = 0;
  260. } else {
  261. $status = 125;
  262. }
  263. } else {
  264. $status = 124;
  265. }
  266.  
  267. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status)];
  268.  
  269. return Response::json($json);
  270. } catch (Exception $e) {
  271. return Response::json((string)$e->getResponse()->getBody());
  272. }
  273. }
  274.  
  275. public static function get_mcompany($data){
  276. // $sip = 'Oke nih';
  277. foreach($data as $address_customer){
  278.  
  279. // dd($address_customer['is_default']);
  280.  
  281. if($address_customer['is_default'] == 1){
  282. $so = SalesOrganization::where('id', $address_customer['sd_so_main_id'])->first();
  283. }
  284. }
  285.  
  286. if(!empty($so)){
  287. return $so;
  288. }else{
  289. return null;
  290. }
  291. }
  292.  
  293. public function register_customer(Request $request)
  294. {
  295. // dd($request->address[0]['name']);
  296. try {
  297. $status = 0;
  298. $content = null;
  299. $email = null;
  300. $check_email = null;
  301. $address = null;
  302. $address = $request->address;
  303.  
  304. // $branch_id = Branch::first();
  305.  
  306. // $sd_so_main_id = SalesOrganization::where('id', $address);
  307.  
  308. $sd_so_main_id = SELF::get_mcompany($address);
  309. $company_id = MCompany::where('sd_so_main_id', $sd_so_main_id->parent_id)->first();
  310.  
  311. DB::beginTransaction();
  312. if ($request->email != '') {
  313. $email = $request->email;
  314. $check_email = Customer::where('email', $request->email)->first();
  315. }
  316. $check_phone_number = Customer::where('phone_number', $request->phone_number)->first();
  317. if ($check_phone_number == null && $check_email == null && $sd_so_main_id != null) {
  318. $customer = new Customer;
  319. $customer->phone_number = $request->phone_number;
  320. $customer->email = $email;
  321. $customer->name = $request->name;
  322. $customer->password = Hash::make($request->password);
  323. $customer->m_company_id = $company_id->id;
  324. $customer->sd_so_main_id = $sd_so_main_id->id;
  325. $customer->is_approved_noo = 0;
  326. $customer->is_noo = 1;
  327. $customer->status_id = 10;
  328. if ($customer->save()) {
  329. // save customer_token
  330. $customer_token = new CustomerToken();
  331. $customer_token->ar_customer_id = $customer->id;
  332. $customer_token->firebase_token = $request->firebase_token;
  333. $customer_token->status_id = 10;
  334.  
  335. if(!$customer_token->save()){
  336. $status = -1;
  337. DB::rollBack();
  338. }
  339.  
  340. foreach($request->address as $address_customer){
  341.  
  342. //dd($address_customer->name);
  343. $customer_address = new CustomerAddress;
  344. $customer_address->name = $address_customer['name'];
  345. $customer_address->ar_customer_id = $customer->id;
  346. $customer_address->sd_so_main_id = $address_customer['sd_so_main_id'];
  347. $customer_address->address = $address_customer['address'];
  348. $customer_address->is_default = $address_customer['is_default'];
  349.  
  350. if(!$customer_address->save()){
  351. $status = -1;
  352. DB::rollBack();
  353. }
  354. }
  355.  
  356.  
  357. $sequence = OrderParameterController::get_number($customer->id);
  358. $cust_id = "CUST" . $sequence;
  359.  
  360. $customer->cust_id = $cust_id;
  361. $customer->save();
  362. $status = 0;
  363. DB::commit();
  364. $content = Customer::findOrFail($customer->id);
  365. //$this->create_otp($customer->id);
  366. } else {
  367.  
  368. DB::rollBack();
  369. $status = -1;
  370. }
  371. } else if ($check_phone_number != null) {
  372. $status = 103;
  373. } else if ($check_email != null) {
  374. $status = 127;
  375. }elseif ($sd_so_main == null){
  376. $status = 100;
  377. } else {
  378. $status = -1;
  379. }
  380.  
  381. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
  382.  
  383. return Response::json($json);
  384. } catch (Exception $e) {
  385. return Response::json((string)$e->getResponse()->getBody());
  386. }
  387. }
  388.  
  389. public function get_banner(Request $request)
  390. {
  391. try {
  392. $today = date('Y-m-d');
  393. $gforce_daily_news = DailyNews::where('periode_start', '<=', $today)
  394. ->where('periode_end', '>=', $today)
  395. ->get();
  396.  
  397. return \Response::json($gforce_daily_news);
  398. } catch (\Exception $e) {
  399. return Response::json((string)$e->getResponse()->getBody());
  400. }
  401. }
  402.  
  403. public function get_promo(Request $request)
  404. {
  405. try {
  406. $status = 0;
  407. $today = date('Y-m-d');
  408. $product_gift = ProductGift::where('until', '>=', $today)
  409. ->where('status_id', '10')
  410. ->get();
  411. $json = ['response_no' => $status,
  412. 'message' => GForceController::getMsgApi($status),
  413. 'banner' => $product_gift
  414. ];
  415. return Response::json($json);
  416. } catch (Exception $e) {
  417. return Response::json((string)$e->getResponse()->getBody());
  418. }
  419. }
  420.  
  421. public function login_customer(Request $request)
  422. {
  423. try {
  424. $content = null;
  425. $customer = null;
  426. $status = 0;
  427. $email = $request->email;
  428. $phone_number = $request->phone_number;
  429. $firebase_token = $request->firebase_token;
  430. $password = $request->password;
  431.  
  432. if ($email != "") {
  433. $customer = Customer::where('email', $email)->first();
  434. } else if ($phone_number != "") {
  435. $customer = Customer::where('phone_number', $phone_number)->first();
  436. }
  437.  
  438. // dd($customer);
  439.  
  440. if ($customer && Hash::check($password, $customer->password)) {
  441. // $customer_token = CustomerToken::firstOrNew('ar_customer_id', $customer->id)->first();
  442. // $customer_token = $firebase_token;
  443. // $customer_token->save();
  444. // $customer_token = CustomerToken::firstOrCreate([
  445. // 'ar_customer_id' => $customer->id
  446. // ], [
  447. // 'ar_customer_id' => $customer->id,
  448. // 'firebase_token' => $firebase_token,
  449. // 'status_id'=>'10',
  450. // ]);
  451. if($customer->status_id == 10){
  452. $customer_token = CustomerToken::where('ar_customer_id', $customer->id)->first();
  453. if ($customer_token != null) {
  454. $update_token = CustomerToken::find($customer_token->id);
  455. $update_token->firebase_token = $firebase_token;
  456. $update_token->status_id = 10;
  457. $update_token->save();
  458. } else {
  459. $create_token = new CustomerToken();
  460. $create_token->ar_customer_id = $customer->id;
  461. $create_token->firebase_token = $firebase_token;
  462. $create_token->status_id = 10;
  463. $create_token->save();
  464. }
  465. $status = 122;
  466. }else{
  467. $status = 133;
  468. }
  469. $content = $customer;
  470. } else {
  471. $status = 123;
  472. }
  473.  
  474. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
  475.  
  476. return Response::json($json);
  477. } catch (Exception $e) {
  478. return Response::json((string)$e->getResponse()->getBody());
  479. }
  480. }
  481.  
  482.  
  483. public function customer_detail(Request $request)
  484. {
  485. try {
  486. $status = '0';
  487. $customer_detail = [];
  488. $today = date('Y-m-d');
  489. $ar_customer_id = $request->ar_customer_id;
  490. $last_balance = 0;
  491. $cek_customer = Customer::find($ar_customer_id);
  492. $customer = DB::table('ar_customer')
  493. ->leftjoin('ar_customer_point', 'ar_customer_point.ar_customer_id', 'ar_customer.id')
  494. ->leftjoin('ar_payment_term', 'ar_payment_term.id', 'ar_customer.ar_payment_term_id')
  495. ->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')
  496. ->where('ar_customer.id', $ar_customer_id)
  497. ->where('ar_customer_point.valid_to', '>=', $today)
  498. ->get();
  499. $customer_address = "";
  500.  
  501. $customer_notification = CustomerNotification::where('ar_customer_id', $ar_customer_id)->where('status_id', 3)->get();
  502. $total_notif = sizeof($customer_notification);
  503.  
  504.  
  505.  
  506. if ($cek_customer == null) {
  507. $status = '115';
  508. } else {
  509. $customer_detail = $customer;
  510. $customer_address = CustomerAddress::where('ar_customer_id', $ar_customer_id)->where('is_default', 1)->first();
  511.  
  512. $available_cl = DB::table('gforce_payment_history')
  513. ->where('ar_customer_id', $ar_customer_id)
  514. ->select('last_balance')
  515. ->orderBy('id', 'desc')
  516. ->first();
  517.  
  518. if(!empty($available_cl)){
  519. $last_balance = $available_cl->last_balance;
  520. }
  521.  
  522. }
  523. $json = ['code' => $status,
  524. 'message' => GForceController::getMsgApi($status),
  525. 'customer_detail' => $customer_detail,
  526. 'customer_address'=>$customer_address,
  527. 'available_cl'=>$last_balance,
  528. 'customer_notification'=>$total_notif];
  529. return Response::json($json);
  530.  
  531. } catch (Exception $e) {
  532. return Response::json((string)$e->getResponse()->getBody());
  533. }
  534. }
  535.  
  536. public function edit_customer(Request $request)
  537. {
  538. try {
  539. $content = null;
  540. $status = 0;
  541. $customer = Customer::find($request->ar_customer_id);
  542. if ($customer != null) {
  543. $check_existing_phone_number = Customer::where('phone_number', $request->phone_number);
  544. // $check_postal_code = PostalCode::find($request->delivery_postal_code_id);
  545. $customer->phone_number = $request->phone_number;
  546. $customer->email = $request->email;
  547. $customer->name = $request->name;
  548. // $customer->delivery_postal_code_id = $request->delivery_postal_code_id;
  549. // $customer->address_delivery_1 = $request->address_delivery_1;
  550. // // $customer->gl_branch_id = $check_postal_code->gl_branch_id;
  551. $customer->status_id = 10;
  552. if ($customer->save()) {
  553. $status = 0;
  554. $content = $customer;
  555. } else {
  556. $status = -1;
  557. }
  558. } else {
  559. $status = 115;
  560. }
  561.  
  562. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
  563.  
  564. return Response::json($json);
  565. } catch (Exception $e) {
  566. return Response::json((string)$e->getResponse()->getBody());
  567. }
  568. }
  569.  
  570. public function check_customer(Request $request)
  571. {
  572. try {
  573. $content = null;
  574. $customer = null;
  575. $status = 0;
  576. $email = $request->email;
  577. $phone_number = $request->phone_number;
  578. $password = $request->password;
  579.  
  580. if ($email != "") {
  581. $customer = Customer::where('email', $email)->first();
  582. } else if ($phone_number != "") {
  583. $customer = Customer::where('phone_number', $phone_number)->first();
  584. }
  585.  
  586. if ($customer != null) {
  587. $status = 0;
  588. $content = $customer;
  589. } else {
  590. $status = 115;
  591. }
  592.  
  593. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
  594.  
  595. return Response::json($json);
  596. } catch (Exception $e) {
  597. return Response::json((string)$e->getResponse()->getBody());
  598. }
  599. }
  600.  
  601. public function get_list_address(Request $request) {
  602. $ar_customer_id = $request['ar_customer_id'];
  603.  
  604. $get_data = DB::table('ar_customer_address as a')
  605. ->join('sd_so_main as b', 'a.sd_so_main_id', '=', 'b.id')
  606. ->where('a.ar_customer_id', '=', $ar_customer_id)
  607. ->select('a.*', 'b.name as city_name')
  608. ->get();
  609. if ($get_data != null) {
  610. $code = 0;
  611. } else {
  612. $code = -1;
  613. }
  614. $json = array(
  615. 'response_no'=>$code,
  616. 'message'=>GForceController::getMsgApi($code),
  617. 'data'=>$get_data
  618. );
  619. return response($json);
  620. }
  621.  
  622. public function add_address(Request $request)
  623. {
  624. try {
  625. $content = null;
  626. $status = 0;
  627. $ar_customer_id = $request->ar_customer_id;
  628. $sd_so_main_id = $request->sd_so_main_id;
  629.  
  630.  
  631. DB::beginTransaction();
  632.  
  633. if ($ar_customer_id != "" && $sd_so_main_id != "") {
  634. $customer = Customer::where('id', $ar_customer_id)->first();
  635. $city = SalesOrganization::where('id', $sd_so_main_id)->first();
  636.  
  637.  
  638. if($customer != null && $city != null){
  639.  
  640.  
  641. $new_customer_address = new CustomerAddress;
  642. $new_customer_address->ar_customer_id = $customer->id;
  643. $new_customer_address->is_default = $request->is_default;
  644. $new_customer_address->name = $request->name;
  645. $new_customer_address->address = $request->address;
  646. $new_customer_address->sd_so_main_id = $sd_so_main_id;
  647.  
  648. if($new_customer_address->save()){
  649. DB::commit();
  650. $content = $new_customer_address;
  651. }else{
  652. DB::rollBack();
  653. $status = -1;
  654. }
  655.  
  656.  
  657. }else{
  658. $status = 115;
  659. }
  660.  
  661.  
  662. } else{
  663. $status = 115;
  664. // $customer = Customer::where('phone_number', $phone_number)->first();
  665. }
  666.  
  667.  
  668. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
  669.  
  670. return Response::json($json);
  671. } catch (Exception $e) {
  672. return Response::json((string)$e->getResponse()->getBody());
  673. }
  674. }
  675.  
  676. public function edit_address(Request $request)
  677. {
  678. try {
  679. $content = null;
  680. $status = 0;
  681. $ar_customer_id = $request->ar_customer_id;
  682. $sd_so_main_id = $request->sd_so_main_id;
  683. $ar_customer_address_id = $request->ar_customer_address_id;
  684. // $default = 0;
  685.  
  686.  
  687. DB::beginTransaction();
  688.  
  689. if ($ar_customer_id != "" && $sd_so_main_id != "" && $ar_customer_address_id != "") {
  690. $customer = Customer::where('id', $ar_customer_id)->first();
  691. $city = SalesOrganization::where('id', $sd_so_main_id)->first();
  692.  
  693.  
  694. if($customer != null && $city != null){
  695.  
  696.  
  697. $update_customer_address = CustomerAddress::find($ar_customer_address_id);
  698. $update_customer_address->ar_customer_id = $customer->id;
  699. $update_customer_address->is_default = $request->is_default;
  700. $update_customer_address->name = $request->name;
  701. $update_customer_address->address = $request->address;
  702. $update_customer_address->sd_so_main_id = $sd_so_main_id;
  703.  
  704. if($update_customer_address->save()){
  705. if($request->is_default == 1){
  706. $update_others = DB::table('ar_customer_address')
  707. ->where('ar_customer_id', '=', $customer->id)
  708. ->whereNotIn('id', array($update_customer_address->id))
  709. ->update(['is_default'=>0]);
  710. }
  711. DB::commit();
  712. $content = $update_customer_address;
  713. }else{
  714. DB::rollBack();
  715. $status = -1;
  716. }
  717.  
  718.  
  719. }else{
  720. $status = 115;
  721. }
  722.  
  723.  
  724. } else{
  725. $status = 115;
  726. // $customer = Customer::where('phone_number', $phone_number)->first();
  727. }
  728.  
  729.  
  730. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
  731.  
  732. return Response::json($json);
  733. } catch (Exception $e) {
  734. return Response::json((string)$e->getResponse()->getBody());
  735. }
  736. }
  737.  
  738. public function delete_address(Request $request)
  739. {
  740. try {
  741. $content = null;
  742. $status = 0;
  743. $ar_customer_id = $request->ar_customer_id;
  744. $sd_so_main_id = $request->city_id;
  745. $ar_customer_address_id = $request->ar_customer_address_id;
  746.  
  747.  
  748. DB::beginTransaction();
  749.  
  750. if ($ar_customer_address_id != "") {
  751. // $customer = Customer::where('id', $ar_customer_id)->first();
  752. // $city = City::where('id', $sd_city_id)->first();
  753.  
  754.  
  755.  
  756. $delete_customer_address = CustomerAddress::find($ar_customer_address_id);
  757.  
  758. if($delete_customer_address->delete()){
  759. DB::commit();
  760. }else{
  761. DB::rollBack();
  762. $status = -1;
  763. }
  764.  
  765.  
  766. } else{
  767. $status = 115;
  768. // $customer = Customer::where('phone_number', $phone_number)->first();
  769. }
  770.  
  771.  
  772. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
  773.  
  774. return Response::json($json);
  775. } catch (Exception $e) {
  776. return Response::json((string)$e->getResponse()->getBody());
  777. }
  778. }
  779.  
  780. public function change_password(Request $request)
  781. {
  782. try {
  783. $content = null;
  784. $status = 0;
  785. $customer = Customer::find($request->ar_customer_id);
  786. if ($customer != null) {
  787. $customer->password = Hash::make($request->password);
  788. $customer->is_default_password = 0;
  789. if ($customer->save()) {
  790. $status = 0;
  791. $content = $customer;
  792. } else {
  793. $status = -1;
  794. }
  795. } else {
  796. $status = 115;
  797. }
  798.  
  799. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
  800.  
  801. return Response::json($json);
  802. } catch (Exception $e) {
  803. return Response::json((string)$e->getResponse()->getBody());
  804. }
  805. }
  806.  
  807. public function get_product_category(Request $request)
  808. {
  809. try {
  810. $searching = $request['searching'];
  811.  
  812. $product_category = ProductCategory::where('status_id', 10)->where('im_product_category_type_id', $this->customer_category_type_to_ecommerce->int_1)->get();
  813.  
  814. $list_product_category = array();
  815. $x = 0;
  816.  
  817. foreach ($product_category as $no => $detail) {
  818. if (sizeof($detail->im_product_category_profile) > 0) {
  819. $list_product_category[$x] = $detail;
  820. $x++;
  821. }
  822. }
  823.  
  824. return Response::json($list_product_category);
  825. } catch (Exception $e) {
  826. return Response::json((string)$e->getResponse()->getBody());
  827. }
  828. }
  829.  
  830. public function search_product(Request $request)
  831. {
  832. try {
  833. $searching = $request['searching'];
  834. $m_company_id = $request['m_company_id'];
  835. $ar_customer_id = $request['ar_customer_id'];
  836.  
  837. $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
  838. ->where('is_default', 1)
  839. ->first();
  840.  
  841. // dd($get_city->sd_so_main_id);
  842. if (!empty($get_branch->sd_so_main)) {
  843.  
  844. $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
  845.  
  846. // dd($get_price_group);
  847.  
  848. if(!empty($get_price_group)){
  849.  
  850.  
  851.  
  852. $product = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
  853. ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
  854. ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
  855. ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
  856. ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
  857. ->where('im_product.status_id', 10)
  858. ->where('im_product.name', 'like', '%' . strtolower($searching) . '%')
  859. ->where('im_product_branch.m_company_id', $m_company_id)
  860. ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
  861. ->get();
  862. }else {
  863. $product = [];
  864. }
  865.  
  866. // dd($product);
  867. }else {
  868. $product = [];
  869. }
  870.  
  871.  
  872.  
  873. return Response::json($product);
  874. } catch (Exception $e) {
  875. return Response::json((string)$e->getResponse()->getBody());
  876. }
  877. }
  878.  
  879. public function search_product_by_category(Request $request)
  880. {
  881. try {
  882. $searching = $request['searching'];
  883. $m_company_id = $request['m_company_id'];
  884. $ar_customer_id = $request['ar_customer_id'];
  885. $category_id = $request['category_id'];
  886.  
  887. $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
  888. ->where('is_default', 1)
  889. ->first();
  890.  
  891. // dd($get_city->sd_so_main_id);
  892. if (!empty($get_branch->sd_so_main)) {
  893.  
  894. $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
  895. // dd($get_price_group);
  896. // dd($get_harga_by_city->id);
  897.  
  898. if(!empty($get_price_group)){
  899.  
  900. $product = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
  901. ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
  902. ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
  903. ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
  904. ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
  905. ->where('im_product.status_id', 10)
  906. ->where('im_product.name', 'like', '%' . strtolower($searching) . '%')
  907. ->where('im_product_category_profile.im_product_category_id', $category_id)
  908. ->where('im_product_branch.m_company_id', $m_company_id)
  909. ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
  910. ->get();
  911. } else {
  912. $product = [];
  913. }
  914.  
  915. // dd($product);
  916. }else {
  917. $product = [];
  918. }
  919.  
  920.  
  921.  
  922. return Response::json($product);
  923. } catch (Exception $e) {
  924. return Response::json((string)$e->getResponse()->getBody());
  925. }
  926. }
  927.  
  928. public function get_product_by_category(Request $request)
  929. {
  930. try {
  931. $category_id = $request['category_id'];
  932. $m_company_id = $request['m_company_id'];
  933. $ar_customer_id = $request['ar_customer_id'];
  934.  
  935.  
  936. $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
  937. ->where('is_default', 1)
  938. ->first();
  939. // dd($get_branch->sd_so_main);
  940. if (!empty($get_branch->sd_so_main)) {
  941.  
  942. $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
  943.  
  944. // dd($get_harga_by_city->id);
  945.  
  946. if(!empty($get_price_group)){
  947.  
  948.  
  949. $product = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
  950. ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
  951. ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
  952. ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
  953. ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
  954. ->where('im_product.status_id', 10)
  955. ->where('im_product_category_profile.im_product_category_id', $category_id)
  956. ->where('im_product_branch.m_company_id', $m_company_id)
  957. ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
  958. ->get();
  959.  
  960. }else {
  961. $product = [];
  962. }
  963.  
  964. }else{
  965. $product = [];
  966. }
  967. return Response::json($product);
  968. } catch (Exception $e) {
  969. return Response::json((string)$e->getResponse()->getBody());
  970. }
  971. }
  972.  
  973. public function get_product_by_category_sort(Request $request)
  974. {
  975. try {
  976. $category_id = $request['category_id'];
  977. $m_company_id = $request['m_company_id'];
  978. $ar_customer_id = $request['ar_customer_id'];
  979. $param = $request['sort'];
  980.  
  981. $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
  982. ->where('is_default', 1)
  983. ->first();
  984.  
  985. if (!empty($get_branch->sd_so_main)) {
  986.  
  987. $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
  988.  
  989.  
  990.  
  991. if(!empty($get_price_group)){
  992. $product_sort = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
  993. ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
  994. ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
  995. ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
  996. ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
  997. ->where('im_product.status_id', 10)
  998. ->where('im_product_category_profile.im_product_category_id', $category_id)
  999. ->where('im_product_branch.m_company_id', $m_company_id)
  1000. ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
  1001. ->orderBy('sd_catalog_item.harga', $param)
  1002. ->get();
  1003. }else {
  1004. $product_sort = [];
  1005. }
  1006.  
  1007. // dd($product);
  1008.  
  1009. }else {
  1010. $product_sort = [];
  1011. }
  1012.  
  1013. return Response::json($product_sort);
  1014. } catch (Exception $e) {
  1015. return Response::json((string)$e->getResponse()->getBody());
  1016. }
  1017. }
  1018.  
  1019.  
  1020. public function get_product_detail(Request $request)
  1021. {
  1022. try {
  1023. $product_id = $request['product_id'];
  1024. $ar_customer_id = $request['ar_customer_id'];
  1025.  
  1026. if($product_id != '' && $ar_customer_id != ''){
  1027.  
  1028.  
  1029. $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
  1030. ->where('is_default', 1)
  1031. ->first();
  1032.  
  1033. // dd($get_branch->sd_so_main);
  1034. if (!empty($get_branch->sd_so_main)) {
  1035.  
  1036. $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
  1037.  
  1038.  
  1039. if(!empty($get_price_group)){
  1040.  
  1041.  
  1042. $product = Product::join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
  1043. ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
  1044. ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
  1045. ->where('im_product.id', $product_id)
  1046. ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
  1047. ->first();
  1048. }else {
  1049. $product = [];
  1050. }
  1051.  
  1052. }else {
  1053. $product = [];
  1054. }
  1055.  
  1056. }else{
  1057. $product = ['code' => '-1', 'message' => GForceController::getMsgApi(-1)];
  1058. }
  1059.  
  1060. return Response::json($product);
  1061. } catch (Exception $e) {
  1062. return Response::json((string)$e->getResponse()->getBody());
  1063. }
  1064. }
  1065.  
  1066. public function get_payment_term(Request $request)
  1067. {
  1068. try {
  1069. $content = null;
  1070. $status = 0;
  1071. $status_for_ecommerce = 1;
  1072.  
  1073. $payment_term = PaymentTerm::where('status_for_ecommerce', $status_for_ecommerce)->get();
  1074.  
  1075. return Response::json($payment_term);
  1076. } catch (Exception $e) {
  1077. return Response::json((string)$e->getResponse()->getBody());
  1078. }
  1079. }
  1080.  
  1081. public function get_payment_term_by_customer(Request $request)
  1082. {
  1083. try {
  1084. $ar_customer = Customer::find($request['ar_customer_id']);
  1085.  
  1086. $payment_term = array();
  1087.  
  1088. if ($ar_customer != null) {
  1089. $payment_term = PaymentTerm::where('id', $ar_customer->ar_payment_term_id)->get();
  1090. }else{
  1091. $payment_term = [];
  1092. }
  1093.  
  1094. return Response::json($payment_term);
  1095. } catch (Exception $e) {
  1096. return Response::json((string)$e->getResponse()->getBody());
  1097. }
  1098. }
  1099.  
  1100. public function get_order_detail(Request $request)
  1101. {
  1102. try {
  1103. $content = null;
  1104. $status = 0;
  1105. $order_id = $request['order_id'];
  1106. $sd_order_header = OrderHeader::join('ar_customer', 'ar_customer.id', 'sd_order_header.ar_customer_id')
  1107. ->join('status', 'sd_order_header.status_id', 'status.id')
  1108. ->join('status as status_pembayaran', 'sd_order_header.status_pembayaran_id', 'status_pembayaran.id')
  1109. ->join('ar_customer_address', 'sd_order_header.ar_customer_address_id', 'ar_customer_address.id')
  1110. ->select('sd_order_header.*', 'ar_customer.address_delivery_1',
  1111. 'status.status_name as status_transaksi','status_pembayaran.status_name as status_pembayaran','ar_customer_address.address as address_name')->find($order_id);
  1112. $sd_order_detail = OrderDetail::join('im_product', 'im_product.id', 'sd_order_detail.im_product_id')
  1113. ->select('sd_order_detail.*', 'im_product.*')
  1114. ->where('sd_order_header_id', $order_id)->get();
  1115.  
  1116. $history_payment = GforcePaymentConfirmation::join('status', 'gforce_payment_confirmation.status_id', 'status.id')
  1117. ->select('gforce_payment_confirmation.*', 'status.status_name as status_payment')
  1118. ->where('gforce_payment_confirmation.sd_order_header_id', $order_id)->where('status_id', '!=', 720)->get();
  1119.  
  1120. $sisa_bayar = DB::table('gforce_payment_confirmation')
  1121. ->where('sd_order_header_id', $order_id)
  1122. ->where('status_id', 610)
  1123. ->select('sisa_bayar')
  1124. ->orderBy('sisa_bayar', 'asc')
  1125. ->first();
  1126. // dd($sisa_bayar);
  1127. if($sisa_bayar != null){
  1128. $sd_order_header['sisa_bayar'] = $sisa_bayar->sisa_bayar;
  1129. }else{
  1130. $sd_order_header['sisa_bayar'] = "";
  1131. }
  1132.  
  1133. $sd_order_header['order_detail'] = $sd_order_detail;
  1134. $sd_order_header['history_payment'] = $history_payment;
  1135.  
  1136. return Response::json($sd_order_header);
  1137. } catch (Exception $e) {
  1138. return Response::json((string)$e->getResponse()->getBody());
  1139. }
  1140. }
  1141.  
  1142. public function get_status_for_order(Request $request)
  1143. {
  1144. try {
  1145. $status = Status::select('status.*')
  1146. ->join('status_child', 'status_child.status_id', 'status.id')
  1147. ->join('status_on_table', 'status_on_table.status_parent_id', 'status_child.status_parent_id')
  1148. ->where('on_table', 'ecommerce_order_status')
  1149. ->get();
  1150. return Response::json($status);
  1151. } catch (Exception $e) {
  1152. return Response::json((string)$e->getResponse()->getBody());
  1153. }
  1154. }
  1155.  
  1156. public function history_order(Request $request)
  1157. {
  1158. try {
  1159. $ar_customer_id = $request['ar_customer_id'];
  1160. $sd_order_header = OrderHeader::join('status', 'status.id', 'sd_order_header.status_id')
  1161. ->select('sd_order_header.*', 'status.status_name')
  1162. ->where('ar_customer_id', $ar_customer_id)
  1163. ->orderBy('id', 'desc')
  1164. ->get();
  1165. return Response::json($sd_order_header);
  1166. } catch (Exception $e) {
  1167. return Response::json((string)$e->getResponse()->getBody());
  1168. }
  1169. }
  1170.  
  1171. public function get_order_by_status(Request $request)
  1172. {
  1173. try {
  1174. $content = null;
  1175. $status = 0;
  1176. $ar_customer_id = $request['ar_customer_id'];
  1177. $status_id = $request['status_id'];
  1178. if ($status_id == "") {
  1179. $sd_order_header = OrderHeader::join('status', 'status.id', 'sd_order_header.status_id')
  1180. ->where('ar_customer_id', $ar_customer_id)
  1181. ->where('sd_order_header.no_order', 'like', '%' . strtolower('OFO') . '%')
  1182. ->select('sd_order_header.*', 'status.status_name')
  1183. ->orderBy('id', 'desc')
  1184. ->get();
  1185. } else {
  1186. $sd_order_header = OrderHeader::join('status', 'status.id', 'sd_order_header.status_id')
  1187. ->where('ar_customer_id', $ar_customer_id)
  1188. ->where('status_id', $status_id)
  1189. ->where('sd_order_header.no_order', 'like', '%' . strtolower('OFO') . '%')
  1190. ->select('sd_order_header.*', 'status.status_name')
  1191. ->orderBy('id', 'desc')
  1192. ->get();
  1193. }
  1194. return Response::json($sd_order_header);
  1195. } catch (Exception $e) {
  1196. return Response::json((string)$e->getResponse()->getBody());
  1197. }
  1198. }
  1199.  
  1200. public static function so_order_header($sd_so_main_id, $sd_order_header_id){
  1201. // $sip = 'Oke nih';
  1202. $so = SalesOrganization::where('id', $sd_so_main_id)->first();
  1203. if(!empty($so)){
  1204.  
  1205. $so_order_header = new SoOrderHeader;
  1206. $so_order_header->sd_so_main_id = $so->id;
  1207. $so_order_header->type_so_id = $so->type_so_id;
  1208. $so_order_header->sd_order_header_id = $sd_order_header_id;
  1209.  
  1210. if($so_order_header->save()){
  1211. SELF::so_order_header($so->parent_id,$sd_order_header_id);
  1212. }
  1213. }
  1214. }
  1215.  
  1216. public function get_contact(Request $request){
  1217. try{
  1218. if(!empty($request->ar_customer_id)){
  1219.  
  1220. $customer = Customer::where('id', $request->ar_customer_id)->first();
  1221.  
  1222. if(!empty($customer)){
  1223.  
  1224. $mcompany = MCompany::where('id', $customer->m_company_id)->select('contact_number')->first();
  1225. $code = 0;
  1226. $message = 'succes';
  1227. $result = $mcompany;
  1228. }else{
  1229. $code = 115;
  1230. $message = 'failed';
  1231. $result = [];
  1232. }
  1233. }else{
  1234.  
  1235. $code = -1;
  1236. $message = 'failed';
  1237. $result = [];
  1238. }
  1239. $json = array(
  1240. "code" => $code,
  1241. "message" => $message,
  1242. "get_contact" => $result
  1243. );
  1244.  
  1245. return response()->json($json);
  1246. } catch (Exception $e) {
  1247. return Response::json((string)$e->getResponse()->getBody());
  1248. }
  1249. }
  1250.  
  1251.  
  1252.  
  1253. public function store_order(Request $request)
  1254. {
  1255. try {
  1256. $content = null;
  1257. $status = 0;
  1258. $array_of_tax = array();
  1259. $total_array_of_poin_transaksi = 0;
  1260. $array_of_poin_transaksi = array();
  1261. $total_array_of_poin_product = 0;
  1262. $array_of_poin_product = array();
  1263. $total_array_of_tax = 0;
  1264. $total_poin = 0;
  1265. $point = array();
  1266. $today = date('Y-m-d');
  1267.  
  1268. $p = 1;
  1269. $day = $this->add_valid_customer_poin->int_1;
  1270. $valid = '+' . $day . ' days';
  1271. // dd($valid);
  1272.  
  1273. $array_of_no_tax = array();
  1274. $total_array_of_no_tax = 0;
  1275. $point = DB::table('point_ofo')->where('valid_to', '>=', $today)->where('status_id', 10)->get();
  1276.  
  1277. $check_customer_point = DB::table('ar_customer_point')->where('ar_customer_id', '=', $request->ar_customer_id)->first();
  1278. // dd($point);
  1279.  
  1280.  
  1281. foreach ($point as $detail_point) {
  1282.  
  1283. if ($detail_point->type_poin == 1) {
  1284.  
  1285. $array_of_poin_product[$total_array_of_poin_product] = $detail_point;
  1286. $total_array_of_poin_product++;
  1287. } else {
  1288. $array_of_poin_transaksi[$total_array_of_poin_transaksi] = $detail_point;
  1289. $total_array_of_poin_transaksi++;
  1290.  
  1291. }
  1292. }
  1293.  
  1294.  
  1295. $detail_order = $request->detail;
  1296.  
  1297.  
  1298. $check_customer = Customer::find($request->ar_customer_id);
  1299.  
  1300. if($request->payment_type == "TOP"){
  1301. if ($request->ar_payment_term_id == null || $request->ar_payment_term_id == "") {
  1302. $first_payment_term = PaymentTerm::find($check_customer->ar_payment_term_id);
  1303. $ar_payment_term_id = $first_payment_term->id;
  1304. }
  1305. }else {
  1306.  
  1307. $first_payment_term = PaymentTerm::find($check_customer->ar_payment_term_id);
  1308. $ar_payment_term_id = $first_payment_term->id;
  1309. }
  1310. // dd($check_customer);
  1311.  
  1312. if ($check_customer == null) {
  1313. $status = 120;
  1314. } else {
  1315. $get_city = CustomerAddress::where('id', $request->ar_customer_address_id)->first();
  1316. DB::beginTransaction();
  1317. $head = new OrderHeader;
  1318. $head->no_order = OrderParameterController::get_code();
  1319. $head->sd_order_type_id = 1;
  1320. $head->payment_type = $request->payment_type;
  1321. $head->is_paid = $request->is_paid;
  1322. $head->paid_off = "N";
  1323. $head->status_pembayaran_id = 700;
  1324. $head->ar_customer_id = $request->ar_customer_id;
  1325. $head->sd_employee_id = ($check_customer->sd_employee == NULL || $check_customer->sd_employee == 0)? NULL: $check_customer->sd_employee_id;
  1326. $head->time_transaction = DB::raw('now()');
  1327. $head->ar_payment_term_id = $ar_payment_term_id;
  1328. $head->m_company_id = $request->m_company_id;
  1329. $head->payment_notes = $request->payment_note;
  1330. $head->ar_customer_address_id = $request->ar_customer_address_id;
  1331. $head->status_id = 140;
  1332.  
  1333.  
  1334. if ($head->save()) {
  1335. $sd_order_header = OrderHeader::where('id', $head->id)->first();
  1336. $sd_order_header->order_amt = 0;
  1337. $so = SELF::so_order_header($get_city->sd_so_main_id, $head->id);
  1338. foreach ($detail_order as $keyDet => $valDet) {
  1339. $check_product = Product::find($valDet['im_product_id']);
  1340. // dd($valDet['im_product_id']);
  1341. if ($check_product == null) {
  1342. DB::rollBack();
  1343. $status = 120;
  1344. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status)];
  1345. return json_encode($json);
  1346. } else {
  1347. $tax_amt = $valDet['tax_pct'] / 100 * $valDet['price_per_pcs'];
  1348. $det = new OrderDetail;
  1349. $det->sd_order_header_id = $head->id;
  1350. $det->no_order = $head->no_order;
  1351. $det->im_product_id = $valDet['im_product_id'];
  1352. $det->qty = $valDet['qty'];
  1353. $det->price_per_pcs = $valDet['price_per_pcs'];
  1354. $det->qty_approved = $valDet['qty'];
  1355. $det->price_per_pcs_approved = $valDet['price_per_pcs'];
  1356. $det->tax_pct = $valDet['tax_pct'];
  1357. $det->tax_amt = $tax_amt;
  1358. $price_before_tax = $valDet['qty'] * $valDet['price_per_pcs'];
  1359. $price_after_tax = $price_before_tax + ($valDet['qty'] * $tax_amt);
  1360.  
  1361. $sd_order_header->order_amt = $sd_order_header->order_amt + ($price_after_tax);
  1362.  
  1363. foreach ($array_of_poin_product as $keyProd => $valProd) {
  1364. if ($valProd->im_product_id == $valDet['im_product_id'] && $valDet['qty'] >= $valProd->qty) {
  1365. if ($valProd->is_kelipatan == 1) {
  1366. $hasil = $valDet['qty'] / $valProd->qty;
  1367. $total_kelipatan = floor($hasil);
  1368. if ($total_kelipatan > 0) {
  1369. $total_poin = $total_poin + ($valProd->get_poin * $total_kelipatan);
  1370. } else {
  1371. $total_poin = $total_poin + $valProd->get_poin;
  1372. }
  1373. } else {
  1374. $total_poin = $total_poin + $valProd->get_poin;
  1375. }
  1376. }
  1377. }
  1378. if (!$det->save()) {
  1379. DB::rollBack();
  1380. $status = 120;
  1381. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status)];
  1382. return json_encode($json);
  1383. }
  1384. }
  1385. }
  1386. if ($sd_order_header->save()) {
  1387. $sd_order_detail = OrderDetail::where('sd_order_header_id', $head->id)->get();
  1388. $sd_order_header['order_detail'] = $sd_order_detail;
  1389.  
  1390.  
  1391. foreach ($array_of_poin_transaksi as $keyTran => $valTran) {
  1392.  
  1393. if ($sd_order_header->order_amt >= $valTran->total_transaksi) {
  1394. if ($valTran->is_kelipatan == 1) {
  1395. $hasil_transaksi = $sd_order_header->order_amt / $valTran->total_transaksi;
  1396. $total_kelipatan_transaksi = floor($hasil_transaksi);
  1397. if ($total_kelipatan_transaksi > 0) {
  1398. $total_poin = $total_poin + ($valTran->get_poin * $total_kelipatan_transaksi);
  1399. } else {
  1400. $total_poin = $total_poin + $valTran->get_poin;
  1401. }
  1402. } else {
  1403. $total_poin = $total_poin + $valTran->get_poin;
  1404. }
  1405. }
  1406. }
  1407.  
  1408.  
  1409. if ($check_customer_point == null) {
  1410.  
  1411. //dd($total_poin);
  1412. $valid = date('Y-m-d', strtotime($valid, strtotime($today)));
  1413. $customer_point = new CustomerPoint;
  1414. $customer_point->ar_customer_id = $request->ar_customer_id;
  1415. $customer_point->amount = $total_poin;
  1416. $customer_point->valid_to = $valid;
  1417. $customer_point->save();
  1418. } else {
  1419.  
  1420.  
  1421. $sum_poin = $check_customer_point->amount + $total_poin;
  1422. $sum_valid = date('Y-m-d', strtotime($valid, strtotime($check_customer_point->valid_to)));
  1423. // dd($sum_poin);
  1424. $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]);
  1425. }
  1426. DB::commit();
  1427. $status = 0;
  1428. $content = $sd_order_header;
  1429. } else {
  1430. DB::rollBack();
  1431. $status = -1;
  1432. }
  1433. if ($this->auto_send_order->int_1 == 1) {
  1434. StagingController::store_order($sd_order_header->id);
  1435. }
  1436. } else {
  1437. // Do Nothing
  1438. }
  1439. }
  1440. $json = ['response_no' => $status, 'message' => GForceController::getMsgApi($status), 'content' => $content];
  1441.  
  1442. return Response::json($json);
  1443. } catch (Exception $e) {
  1444. return Response::json((string)$e->getResponse()->getBody());
  1445. }
  1446. }
  1447.  
  1448. public function update_order(Request $request)
  1449. {
  1450. try {
  1451. DB::beginTransaction();
  1452. $sd_order_header_id = $request->sd_order_header_id;
  1453.  
  1454. $is_cod = $request->is_cod;
  1455. $tgl_pembayaran = strval($request->tgl_pembayaran);
  1456. $image_path = "storage/uploads/order/";
  1457. GForceController::check_exist_folder($image_path);
  1458. $sd_order_header = OrderHeader::find($sd_order_header_id);
  1459. // dd($sd_order_header);
  1460. $pembayaran = GforcePaymentConfirmation::where('sd_order_header_id', $sd_order_header_id)->where('status_id', 610)->get();
  1461. // $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();
  1462. // dd($pembayaran);
  1463. $gl_bank_id = GlBank::find($request->detail['gl_bank_id_pengirim']);
  1464. $gl_bank_company_id = GlBankCompany::find($request->detail['gl_bank_company_id']);
  1465. if ($sd_order_header != null) {
  1466. if ($is_cod) {
  1467. $total_order = OrderHeader::find($sd_order_header_id);
  1468. $payment_confirmation = new GforcePaymentConfirmation();
  1469. $payment_confirmation->sd_order_header_id = $sd_order_header_id;
  1470. $payment_confirmation->status_id = 600;
  1471. $payment_confirmation->tgl_pembayaran = $tgl_pembayaran;
  1472. $payment_confirmation->is_cod = $request->is_cod;
  1473. $payment_confirmation->nominal_transfer = $total_order->order_net_amt;
  1474. $payment_confirmation->sisa_bayar = $total_order->order_net_amt;
  1475. $payment_confirmation->deskripsi = $request->deskripsi;
  1476.  
  1477.  
  1478. if ($payment_confirmation->save()) {
  1479. $payment_confirmation_photo = new GforcePaymentConfirmationPhoto();
  1480. $payment_confirmation_photo->gforce_payment_confirmation_id = $payment_confirmation->id;
  1481. if ($request->transfer_receipt != null || $request->transfer_receipt != "") {
  1482. $image_upload = $image_path . $payment_confirmation->id . date("YmdHis") . ".jpg";
  1483. file_put_contents($image_upload, base64_decode($request->transfer_receipt));
  1484. $payment_confirmation_photo->picture_path = $image_upload;
  1485. }
  1486. if ($payment_confirmation_photo->save()) {
  1487.  
  1488. $order = OrderHeader::find($sd_order_header_id);
  1489. $order->is_paid = "Y";
  1490. if($order->save()){
  1491.  
  1492. DB::commit();
  1493. $code = 0;
  1494. }
  1495. }
  1496. } else {
  1497. DB::rollBack();
  1498. $code = -1;
  1499. }
  1500. } else {
  1501. if ($gl_bank_id != null && $gl_bank_company_id != null) {
  1502. $payment_confirmation = new GforcePaymentConfirmation();
  1503. $payment_confirmation->sd_order_header_id = $sd_order_header_id;
  1504. $payment_confirmation->status_id = 600;
  1505. $payment_confirmation->nama_pengirim = $request->detail['nama_pengirim'];
  1506. $payment_confirmation->no_rekening_pengirim = $request->detail['no_rekening_pengirim'];
  1507. $payment_confirmation->gl_bank_id_pengirim = $gl_bank_id->id;
  1508. $payment_confirmation->nominal_transfer = $request->detail['nominal_transfer'];
  1509. $payment_confirmation->cabang_bank_pengirim = $request->detail['cabang_bank_pengirim'];
  1510. $payment_confirmation->tgl_pembayaran = $tgl_pembayaran;
  1511. $payment_confirmation->gl_bank_company_id = $gl_bank_company_id->id;
  1512. $payment_confirmation->is_cod = $request->is_cod;
  1513. $payment_confirmation->deskripsi = $request->deskripsi;
  1514. if(empty($pembayaran)){
  1515. $payment_confirmation->sisa_bayar = $sd_order_header->order_net_amt;
  1516.  
  1517. }else{
  1518. // $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();
  1519. $sisa_bayar = DB::table('gforce_payment_confirmation')
  1520. ->where('sd_order_header_id', $sd_order_header_id)
  1521. ->where('status_id', 610)
  1522. ->select('sisa_bayar')
  1523. ->orderBy('sisa_bayar', 'asc')
  1524. ->first();
  1525. // dd($sisa_bayar);
  1526. if($sisa_bayar != null){
  1527.  
  1528. $payment_confirmation->sisa_bayar = $sisa_bayar->sisa_bayar;
  1529.  
  1530. }else{
  1531. $payment_confirmation->sisa_bayar = $sd_order_header->order_net_amt;
  1532. }
  1533. }
  1534. if ($payment_confirmation->save()) {
  1535. $payment_confirmation_photo = new GforcePaymentConfirmationPhoto();
  1536. $payment_confirmation_photo->gforce_payment_confirmation_id = $payment_confirmation->id;
  1537. if ($request->transfer_receipt != null || $request->transfer_receipt != "") {
  1538. $image_upload = $image_path . $payment_confirmation->id . date("YmdHis") . ".jpg";
  1539. file_put_contents($image_upload, base64_decode($request->transfer_receipt));
  1540. $payment_confirmation_photo->picture_path = $image_upload;
  1541. }
  1542. if ($payment_confirmation_photo->save()) {
  1543.  
  1544. $order = OrderHeader::find($sd_order_header_id);
  1545. $order->is_paid = "Y";
  1546. if($order->save()){
  1547.  
  1548. DB::commit();
  1549. $code = 0;
  1550. }
  1551. }
  1552. } else {
  1553. DB::rollBack();
  1554. $code = -1;
  1555. }
  1556. } else {
  1557. $code = 115;
  1558. }
  1559. }
  1560. } else {
  1561. $code = 115;
  1562. }
  1563. $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
  1564. return Response::json($json);
  1565. } catch (\Exception $e) {
  1566. return Response::json($e->getMessage());
  1567. }
  1568. }
  1569.  
  1570.  
  1571. public function get_order_notification(Request $request)
  1572. {
  1573. try {
  1574. $content = null;
  1575. $status = 0;
  1576. $ar_customer_id = $request['ar_customer_id'];
  1577. $status_id = 150; // Confirmed Status
  1578. $sd_order_header = OrderHeader::where('ar_customer_id', $ar_customer_id)
  1579. ->where('send_to_staging', 1)
  1580. ->where('update_from_staging', 1)
  1581. ->where('notification_send', 0)
  1582. ->where('status_id', $status_id)
  1583. ->get();
  1584.  
  1585. $update_order = OrderHeader::where('ar_customer_id', $ar_customer_id)
  1586. ->where('send_to_staging', 1)
  1587. ->where('update_from_staging', 1)
  1588. ->where('notification_send', 0)
  1589. ->where('status_id', $status_id)
  1590. ->update(['notification_send' => 1]);
  1591.  
  1592. return Response::json($sd_order_header);
  1593. } catch (Exception $e) {
  1594. return Response::json((string)$e->getResponse()->getBody());
  1595. }
  1596. }
  1597.  
  1598. public function get_notification_ofo(Request $request)
  1599. {
  1600. try {
  1601. $content = null;
  1602. $status = 0;
  1603. $ar_customer_id = $request['ar_customer_id'];
  1604. $status_id = 150; // Confirmed Status
  1605. $sd_order_header = OrderHeader::where('ar_customer_id', $ar_customer_id)
  1606. ->join('status', 'status.id', 'sd_order_header.status_id')
  1607. ->where('send_to_staging', 1)
  1608. ->where('update_from_staging', 1)
  1609. ->where('notification_send', 1)
  1610. ->select(DB::raw('sd_order_header.id,sd_order_header.no_order,status.status_name, DATE(sd_order_header.updated_at) as date'))
  1611. ->where('status_id', $status_id)
  1612. ->get();
  1613.  
  1614.  
  1615. // $json = ['status'=>$status_id,'order'=>$sd_order_header];
  1616.  
  1617.  
  1618. return Response::json($sd_order_header);
  1619. } catch (Exception $e) {
  1620. return Response::json((string)$e->getResponse()->getBody());
  1621. }
  1622. }
  1623.  
  1624. public function routine_order(Request $request)
  1625. {
  1626. try {
  1627. $content = null;
  1628. $status = 0;
  1629. $ar_customer_id = $request['ar_customer_id'];
  1630.  
  1631. if($ar_customer_id != ''){
  1632.  
  1633. $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
  1634. ->where('is_default', 1)
  1635. ->first();
  1636.  
  1637. if (!empty($get_branch->sd_so_main)) {
  1638.  
  1639. $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
  1640.  
  1641. if(!empty($get_price_group)){
  1642.  
  1643.  
  1644. $product = Product::join('sd_order_detail', 'sd_order_detail.im_product_id', 'im_product.id')
  1645. ->join('sd_order_header', 'sd_order_header.id', 'sd_order_detail.sd_order_header_id')
  1646. ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
  1647. ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
  1648. ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
  1649. ->where('sd_order_header.ar_customer_id', $ar_customer_id)
  1650. ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
  1651. ->distinct()
  1652. ->get();
  1653. }else {
  1654. $product = [];
  1655. }
  1656.  
  1657. }else {
  1658. $product = [];
  1659. }
  1660. }else{
  1661. $product = ['code' => '-1', 'message' => GForceController::getMsgApi(-1)];
  1662. }
  1663. return Response::json($product);
  1664. } catch (Exception $e) {
  1665. return Response::json((string)$e->getResponse()->getBody());
  1666. }
  1667. }
  1668.  
  1669. public function gifts_product(Request $request)
  1670. {
  1671. try {
  1672. $code = '0';
  1673. $today = date('Y-m-d');
  1674. $gifts_product = ProductGift::join('im_product', 'im_product_gift.im_product_id', 'im_product.id')
  1675. ->select('im_product_gift.id as im_product_gift_id',
  1676. 'im_product_gift.point as point',
  1677. 'im_product_gift.valid_to as im_product_gift_until',
  1678. 'im_product_gift.description as im_product_gift_description',
  1679. 'im_product_gift.image as im_product_gift_image',
  1680. 'im_product_gift.status_id',
  1681. 'im_product.*')
  1682. ->where('im_product_gift.valid_to', '>=', $today)
  1683. ->get();
  1684. $json = ['code' => $code, 'message' => GForceController::getMsgApi($code), 'list_product_gifts' => $gifts_product];
  1685. return Response::json($json);
  1686. } catch (Exception $e) {
  1687. $code = '-1';
  1688. $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
  1689. }
  1690. }
  1691.  
  1692. public function history_redeem(Request $request)
  1693. {
  1694. try {
  1695. $code = '0';
  1696. // $today = date('Y-m-d');
  1697. $history_redeem = CustomerGiftClaim::join('status', 'ar_customer_gift_claim.status_id', 'status.id')
  1698. ->join('im_product_gift', 'ar_customer_gift_claim.im_product_gift_id', 'im_product_gift.id')
  1699. ->join('im_product', 'im_product_gift.im_product_id', 'im_product.id')
  1700. ->select('ar_customer_gift_claim.*', 'status.status_name as status', 'im_product.name as product_name')
  1701. ->where('ar_customer_gift_claim.ar_customer_id', $request->ar_customer_id)
  1702. ->get();
  1703. $json = ['code' => $code, 'message' => GForceController::getMsgApi($code), 'history_gift_claim' => $history_redeem];
  1704. return Response::json($json);
  1705. } catch (Exception $e) {
  1706. $code = '-1';
  1707. $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
  1708. }
  1709. }
  1710.  
  1711. public function redeem_point(Request $request)
  1712. {
  1713. try {
  1714. $today = date('Y-m-d');
  1715. $customer_point = DB::table('ar_customer_point')->Where('ar_customer_id', '=', $request->ar_customer_id)
  1716. ->Where('valid_to', '>=', $today)
  1717. ->first();
  1718. $im_product_gift = DB::table('im_product_gift')->where('id', '=', $request->im_product_gift)->where('status_id', 10)->first();
  1719. // dd($customer_point->amount);
  1720. if ($customer_point != null && $customer_point->amount >= $im_product_gift->point) {
  1721.  
  1722. $calculate_poin = $customer_point->amount - $im_product_gift->point;
  1723. DB::table('ar_customer_point')->where('ar_customer_id', $request->ar_customer_id)->update(['amount' => $calculate_poin]);
  1724. $customerGiftClaim = new CustomerGiftClaim();
  1725. $customerGiftClaim->ar_customer_id = $request->ar_customer_id;
  1726. $customerGiftClaim->no_claim_gift = 'CG-' . $request->ar_customer_id . date('hms');
  1727. $customerGiftClaim->im_product_gift_id = $request->im_product_gift;
  1728. $customerGiftClaim->status_id = '740';
  1729. if($customerGiftClaim->save()){
  1730. $update_customer_point = DB::table('ar_customer_point')->where('ar_customer_id', $request->ar_customer_id)->update(['amount' => $calculate_poin]);
  1731. $code = '0';
  1732. }else{
  1733. $code = '42';
  1734. }
  1735. } else {
  1736.  
  1737. $code = '40';
  1738. }
  1739. $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
  1740. return Response::json($json);
  1741. } catch (Exception $e) {
  1742. $code = '-1';
  1743. $json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
  1744. }
  1745. }
  1746.  
  1747. public function get_menu_home(Request $request)
  1748. {
  1749. try {
  1750.  
  1751. $ar_customer_id = $request['ar_customer_id'];
  1752. $m_company_id = $request['m_company_id'];
  1753.  
  1754. if($ar_customer_id != '' && $m_company_id != ''){
  1755.  
  1756. /**
  1757. * Banner
  1758. */
  1759. $today = date('Y-m-d');
  1760. $gforce_daily_news = DailyNews::where('periode_start', '<=', $today)
  1761. ->select('id', 'periode_start', 'periode_end', 'content', 'image', 'image_title')
  1762. ->where('periode_end', '>=', $today)
  1763. ->get();
  1764.  
  1765. /**
  1766. * Category
  1767. */
  1768. $product_category = ProductCategory::where('status_id', 10)->where('im_product_category_type_id', $this->customer_category_type_to_ecommerce->int_1)
  1769. ->get();
  1770.  
  1771. $get_branch = CustomerAddress::where('ar_customer_id', $ar_customer_id)
  1772. ->where('is_default', 1)
  1773. ->first();
  1774.  
  1775. if (!empty($get_branch->sd_so_main)) {
  1776.  
  1777. $get_price_group = DB::table('sd_customer_price_group')->where('sd_so_main_id', $get_branch->sd_so_main->parent_id)->first();
  1778.  
  1779. if(!empty($get_price_group)){
  1780.  
  1781. /*
  1782. *Routine Order
  1783. */
  1784. $product = Product::join('sd_order_detail', 'sd_order_detail.im_product_id', 'im_product.id')
  1785. ->join('sd_order_header', 'sd_order_header.id', 'sd_order_detail.sd_order_header_id')
  1786. ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
  1787. ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
  1788. ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
  1789. ->where('sd_order_header.ar_customer_id', $ar_customer_id)
  1790. ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
  1791. ->distinct()
  1792. ->get();
  1793.  
  1794. /*
  1795. * Suggestion Order
  1796. */
  1797.  
  1798. $product_suggestion = Product::join('im_product_category_profile', 'im_product_category_profile.im_product_id', 'im_product.id')
  1799. ->join('sd_catalog_item', 'sd_catalog_item.im_product_id', 'im_product.id')
  1800. ->join('im_product_branch', 'im_product_branch.im_product_id', 'im_product.id')
  1801. ->join('ar_tax', 'ar_tax.id', 'im_product.ar_tax_id')
  1802. ->select('im_product.*', 'sd_catalog_item.harga', 'ar_tax.percent')
  1803. ->where('im_product.status_id', 10)
  1804. ->where('im_product_branch.m_company_id', $m_company_id)
  1805. ->where('sd_catalog_item.sd_customer_price_group_id', $get_price_group->id)
  1806. ->take(10)
  1807. ->get();
  1808. }else {
  1809. $product = [];
  1810. $product_suggestion = [];
  1811. }
  1812.  
  1813. }else {
  1814. $product = [];
  1815. $product_suggestion = [];
  1816. }
  1817.  
  1818.  
  1819. $response = Array(
  1820. "menu_home" => array(
  1821. array(
  1822. "menu_code" => "600",
  1823. "menu_type" => "banner",
  1824. "menu_list" => $gforce_daily_news
  1825. ),
  1826. array(
  1827. "menu_code" => "610",
  1828. "menu_type" => "Category",
  1829. "menu_list" => $product_category
  1830. ),
  1831. array(
  1832. "menu_code" => "620",
  1833. "menu_type" => "Routine Oder",
  1834. "menu_list" => $product
  1835. ),
  1836. array(
  1837. "menu_code" => "630",
  1838. "menu_type" => "Top Product",
  1839. "menu_list" => $product_suggestion
  1840. )
  1841.  
  1842. )
  1843. );
  1844.  
  1845. }else{
  1846. $response = ['code' => '-1', 'message' => GForceController::getMsgApi(-1)];
  1847. }
  1848.  
  1849. return Response::json($response);
  1850. } catch (Exception $e) {
  1851. $code = '-1';
  1852. return Response::$json = ['code' => $code, 'message' => GForceController::getMsgApi($code)];
  1853. }
  1854. }
  1855.  
  1856.  
  1857. public function search_history_order(Request $request)
  1858. {
  1859. try {
  1860. $ar_customer_id = $request['ar_customer_id'];
  1861. $searching = $request['searching'];
  1862. $sd_order_header = OrderHeader::join('status', 'status.id', 'sd_order_header.status_id')
  1863. ->where('ar_customer_id', $ar_customer_id)
  1864. ->whereNull('gforce_customer_visit_id')
  1865. ->where('sd_order_header.no_order', 'like', '%' . strtolower($searching) . '%')
  1866. ->select('sd_order_header.*', 'status.status_name')
  1867. ->orderBy('id', 'desc')
  1868. ->get();
  1869. return Response::json($sd_order_header);
  1870. } catch (Exception $e) {
  1871. return Response::json((string)$e->getResponse()->getBody());
  1872. }
  1873. }
  1874.  
  1875. public function get_bank_company() {
  1876. try {
  1877. $data = GlBankCompany::join('gl_bank','gl_bank_company.gl_bank_id','gl_bank.id')
  1878. ->select('gl_bank_company.*','gl_bank.name')
  1879. ->get();
  1880. if ($data != null) {
  1881. $code = 0;
  1882. $content = $data;
  1883. } else {
  1884. $code = -1;
  1885. $content = [];
  1886. }
  1887. } catch (\Exception $e) {
  1888. $code = -1;
  1889. $content = [];
  1890. }
  1891. $json = array(
  1892. 'response_no'=> $code,
  1893. 'message' => GForceController::getMsgApi($code),
  1894. 'data' => $content
  1895. );
  1896. return Response::json($json);
  1897. }
  1898.  
  1899. public function get_bank_master() {
  1900. try {
  1901. $data = GlBank::all();
  1902. if ($data != null) {
  1903. $code = 0;
  1904. $content = $data;
  1905. } else {
  1906. $code = -1;
  1907. $content = [];
  1908. }
  1909. } catch (\Exception $e) {
  1910. $code = -1;
  1911. $content = [];
  1912. }
  1913. $json = array(
  1914. 'response_no'=> $code,
  1915. 'message' => GForceController::getMsgApi($code),
  1916. 'data' => $content
  1917. );
  1918. return Response::json($json);
  1919. }
  1920.  
  1921. public function check_price(Request $request) {
  1922. $sd_so_main_id = $request->sd_so_main_id;
  1923. $get_branch = SalesOrganization::where('id', $sd_so_main_id)->first();
  1924. // dd($get_branch->parent_id);
  1925. $sd_customer_price_group = CustomerPriceGroup::where('sd_so_main_id', $get_branch->parent_id)->first();
  1926. if ($sd_customer_price_group != null) {
  1927. $sd_catalog_item = CatalogItem::join('im_product', 'sd_catalog_item.im_product_id', 'im_product.id')
  1928. ->where('sd_catalog_item.sd_customer_price_group_id', $sd_customer_price_group->id)
  1929. ->whereIn('sd_catalog_item.im_product_id', $request->products)
  1930. ->select('sd_catalog_item.*', 'im_product.name')->get();
  1931. if (sizeof($sd_catalog_item) > 0) {
  1932. $code = 0;
  1933. $data = $sd_catalog_item;
  1934. } else {
  1935. $code = 115;
  1936. $data = [];
  1937. }
  1938. } else {
  1939. $code = 115;
  1940. $data = [];
  1941. }
  1942. $json = array(
  1943. 'response_no'=>$code,
  1944. 'message'=>GForceController::getMsgApi($code),
  1945. 'list_product'=>$data
  1946. );
  1947. return response($json);
  1948. }
  1949.  
  1950. public function test_order()
  1951. {
  1952. StagingController::postGuzzleRequest();
  1953. }
  1954.  
  1955. public function test_email()
  1956. {
  1957. //Mail::to("anggiahmadi@gmail.com")->send(new CustomerRegistration());
  1958. }
  1959.  
  1960. public static function send_firebase_notif($fb_token, $message_bodys) {
  1961. $recipients = array($fb_token);
  1962. fcm()
  1963. ->to($recipients) // $recipients must an array
  1964. ->priority('high')
  1965. ->timeToLive(0)
  1966. ->data([
  1967. 'title' => 'Notification from HARSINDO',
  1968. 'body' => $message_body,
  1969. ])
  1970. ->send();
  1971. }
  1972.  
  1973. }
Add Comment
Please, Sign In to add comment