Guest User

Eccommerce

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