[php] ManualInvoiceController.php
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Http\Response;
- use Illuminate\Support\Str;
- use GuzzleHttp\Client;
- use Session;
- use Storage;
- use Log;
- use PDF;
- use Exception;
- use File;
- use Excel;
- use Carbon;
- // Model
- use DB;
- use App\ManualInvoice;
- use App\Department;
- use App\Client as ClientModel;
- use App\Division;
- use App\DetailManual;
- use App\ServiceCategory;
- use App\Invoice;
- use Validator;
- class ManualInvoiceController extends Controller
- {
- public function __construct()
- {
- $this->middleware('checksession');
- $this->middleware('checktoken');
- // $logFile = 'log.log';
- // Log::useDailyFiles(storage_path() . '/logs/performance_invoice_upload/' . $logFile);
- }
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index(Request $request)
- {
- // return "Maintain";
- if (empty($_COOKIE["token"])) {
- return redirect("https://backoffice.sprintasia.net:82/sprint-sysadmin/public/login");
- } else {
- $title = "Invoice";
- $gen = "Manual Invoice";
- $content = "Manual Invoice";
- $data = DB::table('db_sprint_ar.manual_invoice AS m')
- ->join('db_sprint_ar.invoice AS i', 'i.id_manual', 'm.id')
- ->whereIn('i.status', [0,2,7])
- ->select('i.*', 'm.*', 'i.submit_date AS tanggal')
- ->orderBy('i.submit_date', 'desc')
- ->get();
- $dtdepts = DB::table('invoice')->select('dept_code', 'dept_name')->get();
- $dtclients = DB::table('invoice')->select('client_code', 'client_name')->get();
- $dtdivs = DB::table('invoice')->select('division_code', 'division_name')->get();
- $dtservs = ServiceCategory::select('service_category_code', 'service_category_name')->get();
- // return view('manual_invoice.index', compact('title','content','gen','data','dtdepts', 'dtclients', 'dtdivs', 'dtservs'));
- return view('manual_invoice.index', compact('title', 'content', 'gen', 'data', 'dtdepts', 'dtclients', 'dtdivs', 'dtservs'));
- }
- }
- public function upload_manual_invoice(Request $request)
- {
- $title = "Manual Invoice";
- $gen = "Upload Manual Invoice";
- $content = "Upload Manual Invoice";
- return view('manual_invoice.index_upload', compact('title', 'content', 'gen'));
- }
- public function get_id_desc($desc)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_id_desc']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['as_description' => $desc]
- ]);
- $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- if(count($data) > 0){
- return (int)$data['id_provider_odoo'];
- }else{
- return 0;
- }
- } catch (Exception $e) {
- return 0;
- }
- }
- public function store(Request $request)
- {
- // try{
- date_default_timezone_set("Asia/Bangkok");
- $dateNow = date('Y-m-d H:i:s');
- $username_login = session()->get('profile')['name'];
- $cn = $request['cn'];
- $cc = $request['cc'];
- $dic = $request['dic'];
- $dec = $request['dec'];
- $desc = $request['desc'];
- $sc_Add = $request['sc_Add'];
- $materai = $request['materai'];
- $vat = $request['vat'];
- $uso = $request['uso'];
- $bhp = $request['bhp'];
- $total_temp = $request['total_s'];
- $total = str_replace(',', '', $total_temp);
- $item = $request['item'];
- $description_inv = $request['temp_desc'];
- $unitprice = $request['unitprice'];
- $quantity = $request['quantity'];
- $manual_detail = $request['manual_detail'];
- // echo "</br>";
- // echo "</br> cn : " ; print_r('cn');
- // echo "</br> cc : " ; print_r('cc');
- // echo "</br> dic : " ; print_r('dic');
- // echo "</br> dec : " ; print_r('dec');
- // echo "</br> desc : " ; print_r('desc');
- // echo "</br> sc_Add : " ; print_r('sc_Add');
- // echo "</br> materai : " ; print_r('materai');
- // echo "</br> vat : " ; print_r('vat');
- // echo "</br> uso : " ; print_r('uso');
- // echo "</br> bhp : " ; print_r('bhp');
- // echo "</br> total_temp : " ; print_r('total_temp');
- // die();
- $data_div = $this->get_data_division_by_id($dic);
- if (count($data_div) == 0) {
- return "division";
- }
- $division_name = $data_div['division_name'];
- $bank_acc_number_sprint = $data_div['division_bank_acc_number_sprint'];
- $bank_acc_name_sprint = $data_div['division_bank_acc_name_sprint'];
- $bank_coa_sprint = $data_div['division_bank_coa_sprint'];
- $zahir_name = $data_div['division_zahir_name'];
- $client_npwp_no = $data_div['division_npwp'];
- $bank_acc_name_client = $data_div['division_bank_account_name'];
- $bank_acc_number_client = $data_div['division_bank_account_number'];
- $bank_name = $data_div['division_bank_name_sprint'];
- // $client_coa = $data_div['division_bank_name_sprint'];
- $division_address = $data_div['division_address'];
- $division_description = $data_div['division_description'];
- $ba = $data_div['berita_acara'];
- if($ba == 1){
- $ba = "Yes";
- }else{
- $ba = "No";
- }
- $fp = $data_div['faktur_pajak'];
- if($fp == 1){$fp = "Yes";}else{$fp = "No";}
- $softcopy = $data_div['soft_copy'];
- if($softcopy == 1){$softcopy = "Yes";}else{$softcopy = "No";}
- $hardcopy = $data_div['hard_copy'];
- if($hardcopy == 1){$hardcopy = "Yes";}else{$hardcopy = "No";}
- $data_pic = $this->get_data_pics_by_id($dic);
- if (count($data_pic) == 0) {
- return "pics";//redirect()->back()->with('error', 'Data PIC Not Found For '. $division_name .' Division. Please Check AM');
- // return "Data PIC Not Found For $division_name Division. Please Check AM";
- }
- $pic_id = $data_pic['pic_id'];
- $pic_name = $data_pic['pic_name'];
- $email_client = $data_pic['pic_email'];
- $pic_position = $data_pic['pic_position'];
- $data_pic_collection = $this->get_data_pic_collection($dic);
- if (count($data_pic_collection) == 0) {
- $pic_collection_name = $pic_name;
- $email_pic_collection = $email_client;
- }else{
- $pic_collection_name = $data_pic_collection['pic_name'];
- $email_pic_collection = $data_pic_collection['pic_email'];
- }
- $data_pic_pph23 = $this->get_data_pic_pph23($dic);
- if (count($data_pic_pph23) == 0) {
- $pic_pph23_name = $pic_name;
- $email_pic_pph23 = $email_client;
- }else{
- $pic_pph23_name = $data_pic_pph23['pic_name'];
- $email_pic_pph23 = $data_pic_pph23['pic_email'];
- }
- $data_client = $this->get_data_client_by_id($cc);
- if (count($data_client) == 0) {
- return redirect()->back()->with('alert', 'Data PIC Not Found For '. $division_name .' Division. Please Check AM');
- }
- $client_domicile_address = $data_client['client_domicile_address'];
- $client_coa = $data_client['client_coa'];
- $lmbg = $data_client['lmbnegara']; //"yes";
- $no_spk = $data_client['client_no_spk'];
- $no_addendum_spk = $data_client['client_no_addendum_spk'];
- $max_amount = $data_client['max_amount']; //10000000;
- $invoice_rule = $data_client['invoice_rule'];
- $data_dept = $this->get_data_dept_by_id($dec);
- if (count($data_dept) == 0) {
- return "dept"; //$dept_name = "";
- }
- $dept_name = $data_dept['dept_name'];
- $id_manual = 0;
- $description = join(", ", $description_inv);
- $sub_total = ceil($total);
- $new_ppn = $this->check_ppn($vat, $sub_total);
- $amount_invoice_rule = $sub_total + $new_ppn;
- // return $lmbg;
- // return $invoice_rule;
- // return $max_amount;
- // return $amount_invoice_rule;
- // return $sub_total;
- // return $vat;
- $real = $this->real_field($lmbg, $invoice_rule, $max_amount, $amount_invoice_rule, $sub_total, $vat);
- // return $real;
- $sub_total_now = $real[0];
- $sub_total_real = $real[1];
- $new_ppn_now = $real[2];
- $new_ppn_real = $real[3];
- if ($materai == "yes") {
- $new_materai = $this->check_materai($sub_total_now, $new_ppn_now);
- }else if ($materai == "no") {
- $new_materai = 0;
- }
- $pph23 = $this->check_pph23($cc, $sub_total_now);
- if ($bhp == "yes") {
- $bhp_Add = ($sub_total_now ) * 0.005; //+ $new_ppn_now
- $bhp_manual = "yes";
- } else {
- $bhp_Add = 0;
- $bhp_manual = "no";
- }
- if ($uso == "yes") {
- $uso_Add = ($sub_total_now ) * 0.0125; //+ $new_ppn_now
- $uso_manual = "yes";
- } else {
- $uso_Add = 0;
- $uso_manual = "no";
- }
- $json = [
- "detail" => [
- "info" => [
- "from" => "PT Sprint Asia",
- "recipient" => $cn,
- "reff_no" => '',
- "cust_id" => '',
- "sales_person" => ''
- ],
- "data" => array($item),
- "total" => [
- "quantity" => $quantity,
- "unitprice" => $unitprice,
- "sub_total" => ceil($sub_total_now), // sum_total
- "with_ppn" => floor($new_ppn_now), // new_ppn
- "bhp" => $bhp_Add,
- "uso" => $uso_Add,
- "with_pph" => $pph23
- ]
- ],
- ];
- // if($quantity == "NaN" || $unitprice == "NaN"){
- // return "NaN";
- // }
- $serialize = json_encode($json);
- // return $serialize;
- $Total = round($sub_total_now + $new_ppn_now + $new_materai - $pph23 - $bhp_Add - $uso_Add);
- $Total_real = round($sub_total_real + $new_ppn_real + $new_materai - $pph23 - $bhp_Add - $uso_Add);
- $revenue_coa = $sc_Add;
- $data_revebue_coa = $this->get_data_revenue_coa($revenue_coa);
- $product_id = $data_revebue_coa['product_id'];
- // Manual Invoice
- $manual_invoice = [
- "client_code" => $cc,
- "dept_code" => $dec,
- "division_code" => $dic,
- "desc" => $desc,
- "vat" => $vat,
- "materai" => $materai,
- "bhp" => $bhp_manual,
- "uso" => $uso_manual,
- "total" => $Total_real,
- "created_by" => $username_login,
- "created_at" => NOW()
- ];
- try {
- $last_id = DB::table("db_sprint_ar.manual_invoice")->insertGetId($manual_invoice);
- } catch (Exception $e) {
- return ["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- }
- $invoice = [
- "client_code" => $cc,
- "client_name" => $cn,
- "division_code" => $dic,
- "division_name" => $division_name,
- "division_description" => $division_description,
- "dept_code" => $dec,
- "dept_name" => $dept_name,
- "pic_id" => $pic_id,
- "inv_month" => date("m"),
- "inv_year" => date("Y"),
- "unitprice" => $unitprice,
- "quantity" => $quantity,
- "sub_total" => ceil($sub_total_now),
- "sub_total_real" => ceil($sub_total_real),
- "ppn" => floor($new_ppn_now),
- "ppn_real" => floor($new_ppn_real),
- "materai" => $new_materai,
- "pph23" => $pph23,
- "total" => $Total,
- "total_real" => $Total_real,
- "serialize_data" => $serialize,
- "selisih" => 0,
- "status" => 0,
- "addmanual" => 1,
- "submit_date" => NOW(),
- "id_manual" => $last_id,
- "pic_name" => $pic_name,
- "division_address" => $division_address,
- "bank_acc_number_sprint" => $bank_acc_number_sprint,
- "bank_acc_name_sprint" => $bank_acc_name_sprint,
- "bank_acc_number_client" => $bank_acc_number_client,
- "bank_acc_name_client" => $bank_acc_name_client,
- "bank_coa_sprint" => $bank_coa_sprint,
- "zahir_name" => $zahir_name,
- "client_npwp_no" => $client_npwp_no,
- "bank_name" => $bank_name,
- "client_coa" => $client_coa,
- "revenue_coa" => $revenue_coa,
- "product_id" => $product_id,
- "email_client" => $email_client,
- "email_collection" => $email_pic_collection,
- // "pic_collection" => $pic_collection_name,
- "email_pph23" => $email_pic_pph23,
- // "pic_pph23" => $pic_pph23_name,
- "pic_position" => $pic_position,
- "description" => $description,
- "id_collection" =>'[""]',
- "ba" => $ba,
- "fp" => $fp,
- "softcopy" => $softcopy,
- "hardcopy" => $hardcopy,
- "created_by" => $username_login,
- "created_at" => NOW()
- ];
- try {
- $last_id_invoice = DB::table("db_sprint_ar.invoice")->insertGetId($invoice);
- $now = NOW();
- $username = session()->get('profile')['name'];
- $descriptionss = "$last_id_invoice tanggal: $now submit by $username";
- $email = session()->get('profile')['email'];
- $description_log = "serialize_data: $serialize";
- $activity = "Add Manual Invoice";
- DB::table('invoice_log_history')->insert(['id_inv' => $last_id_invoice, 'activity' => $activity, 'username' => $username, 'email' => $email, 'description' => $description_log,'created_at' => $now]);
- $saved_log_datas = preg_replace( "/\r|\n/", " ", json_encode($invoice) );
- $saved_log_datas = str_replace("\\", "", $saved_log_datas);
- // DB::table('history')->insert([ 'activity'=> "Create Manual Invoice", 'description'=> "Create values : ". $saved_log_datas , 'created_by' => $username , 'created_at' => $now ]);
- DB::table('history')->insert([ 'client_name'=> $cn, 'division_name'=> $division_name, 'dept_name'=> $dept_name, 'inp_desc2' => "Create Manual Invoice, Client Name : " . $cn . " , Division Name : " . $division_name . " , Dept Name : " . $dept_name . " , Quantity : " . $quantity . " , Description : " .$description, 'inp_desc'=> $description, 'activity'=> "Create Manual Invoice", 'description'=> "Create values : ". $saved_log_datas , 'created_by' => $username , 'created_at' => $now ]);
- DB::table("db_sprint_ar.manual_invoice")->where('id', $last_id)->update(["total" => $Total]);
- } catch (Exception $e) {
- return ["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- }
- // Insert to table manual_detail
- for ($i = 0; $i < count($manual_detail); $i++) {
- $item_temp = $manual_detail[$i]['desc'];
- $manual_details[] = [
- "id_manual" => $last_id,
- "service" => $manual_detail[$i]['service'],
- "quantity" => $manual_detail[$i]['quantity'],
- "unit_price" => $manual_detail[$i]['unit_price'],
- "desc" => $item_temp, //$manual_detail[$i]['desc'],
- "total" => $manual_detail[$i]['total']
- ];
- }
- // return $manual_details;
- try {
- $last_id = DB::table("db_sprint_ar.manual_detail")->insert($manual_details);
- } catch (Exception $e) {
- return ["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- }
- return "success";
- // }catch (Exception $e) {
- // return "error";//["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- // }
- // return redirect(url('/manual-invoice'))->with('success');
- }
- public function get_data_revenue_coa($revenue_coa)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_revenue_coa']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['revenue_coa' => $revenue_coa]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- }
- public function update(Request $request)
- {
- if ($request->input('sc_Edit') == "" || $request->input('sc_Edit') == null || $request->input('sc_Edit') == null) {
- return redirect()->back()->with('alert', 'Service Category Tidak Dapat Dipilih. Silahkan Periksa di Account Management. Data Tidak Tersimpan.');
- }
- $id = $request->input('id');
- $client_name = $request->input('client');
- $client_code = $request->input('client_code');
- $division_code = $request->input('division_code');
- $dept_code = $request->input('dept_code');
- $desc = $request->input('desc');
- $sc_coa = $request->input('sc_Edit');
- $vat = $request->input('vat');
- $bhp = $request->input('bhp_Edit');
- $uso = $request->input('uso_Edit');
- $materai = $request->input('materai');
- $dataInv = DB::table('invoice')->where('id_manual', $id)->get();
- $status = $dataInv[0]->status;
- // return $dataInv[0]->serialize_data;
- $serialize_data = json_decode($dataInv[0]->serialize_data);
- $cust_id = $serialize_data->detail->info->cust_id; // data serialize data json (sekarang)
- $update_printDate = $dataInv[0]->update_print_date;
- $data_div = $this->get_data_division_by_id($division_code);
- if (count($data_div) == 0) {
- return redirect()->back()->with('alert', 'Data Division Not Found For '. $division_code .'. Please Check AM');
- }
- $division_name = $data_div['division_name'];
- $bank_acc_number_sprint = $data_div['division_bank_acc_number_sprint'];
- $bank_acc_name_sprint = $data_div['division_bank_acc_name_sprint'];
- $bank_coa_sprint = $data_div['division_bank_coa_sprint'];
- $zahir_name = $data_div['division_zahir_name'];
- $client_npwp_no = $data_div['division_npwp'];
- $bank_acc_name_client = $data_div['division_bank_account_name'];
- $bank_acc_number_client = $data_div['division_bank_account_number'];
- $bank_name = $data_div['division_bank_name_sprint'];
- $client_coa = $data_div['division_bank_name_sprint'];
- $division_address = $data_div['division_address'];
- $division_invoice_rule = $data_div['division_invoice_rule'];
- $division_max_amount = $data_div['division_max_amount'];
- $division_description = $data_div['division_description'];
- $ba = $data_div['berita_acara'];
- if($ba == 1){$ba = "Yes";}else{$ba = "No";}
- $fp = $data_div['faktur_pajak'];
- if($fp == 1){$fp = "Yes";}else{$fp = "No";}
- $softcopy = $data_div['soft_copy'];
- if($softcopy == 1){$softcopy = "Yes";}else{$softcopy = "No";}
- $hardcopy = $data_div['hard_copy'];
- if($hardcopy == 1){$hardcopy = "Yes";}else{$hardcopy = "No";}
- $data_pic = $this->get_data_pics_by_id($division_code);
- if (count($data_pic) == 0) {
- return redirect()->back()->with('alert', 'Data PIC Not Found For '. $division_code .'. Please Check AM');
- }
- $pic_id = $data_pic['pic_id'];
- $pic_name = $data_pic['pic_name'];
- $email_client = $data_pic['pic_email'];
- $pic_position = $data_pic['pic_position'];
- $data_pic_collection = $this->get_data_pic_collection($division_code);
- if (count($data_pic_collection) == 0) {
- $pic_collection_name = $pic_name;
- $email_pic_collection = $email_client;
- }else{
- $pic_collection_name = $data_pic_collection['pic_name'];
- $email_pic_collection = $data_pic_collection['pic_email'];
- }
- $data_pic_pph23 = $this->get_data_pic_pph23($division_code);
- if (count($data_pic_pph23) == 0) {
- $pic_pph23_name = $pic_name;
- $email_pic_pph23 = $email_client;
- }else{
- $pic_pph23_name = $data_pic_pph23['pic_name'];
- $email_pic_pph23 = $data_pic_pph23['pic_email'];
- }
- $data_client = $this->get_data_client_by_id($client_code);
- if (count($data_client) == 0) {
- return redirect()->back()->with('alert', 'Data Client Not Found For '. $client_code .'. Please Check AM');
- }
- $client_domicile_address = $data_client['client_domicile_address'];
- $client_coa = $data_client['client_coa'];
- $lmbg = $data_client['lmbnegara']; //"yes" ;
- $max_amount = $data_client['max_amount'];
- $invoice_rule = $data_client['invoice_rule'];
- $data_dept = $this->get_data_dept_by_id($dept_code);
- if (count($data_dept) == 0) {
- return redirect()->back()->with('alert', 'Data Department Not Found For '. $division_name .'. Please Check AM');
- }
- $dept_name = $data_dept['dept_name'];
- $id_manual = 0;
- $sum_quantity = 0;
- $sum_unitprice = 0;
- $sum_total = 0;
- // JSON Serialize
- $length = count($request->input('service_cat'));
- if ($length > 0) {
- $item_name = $request->input('vdesc');
- $service = $request->input('service_cat');
- $id_service = $request->input('id_service_cat');
- $temp_desc = [];
- for($c = 0; $c < count($item_name); $c++){
- if($item_name[$c] == null || $item_name[$c] == '' || $item_name[$c] == ""){
- continue;
- }
- array_push($temp_desc, $item_name[$c]);
- }
- $description = join(", ", $temp_desc);
- $quantity = $request->input('quantity');
- $unitprice = $request->input('unitprice');
- $total = $request->input('total');
- // return $description;
- for ($x = 0; $x < $length; $x++) {
- // return $id_service[2];
- if($id_service[$x] == '0') return redirect()->back()->with('alert', "Id Description $service[$x] Tidak Tersedia. Silahkan Create/Update Provider $service[$x]");
- $item_desc = [
- "item_name" => $service[$x],
- "quantity" => $quantity[$x],
- "unitprice" => $unitprice[$x],
- "total" => intval(str_replace(',', '', $total[$x]))
- ];
- $item[] = [
- "item" => $item_name[$x],
- "item_desc" => array($item_desc)
- ];
- $sum_quantity = $sum_quantity + intval($quantity[$x]);
- $sum_unitprice = $sum_unitprice + intval($unitprice[$x]);
- $sum_total = $sum_total + intval(str_replace(',', '', $total[$x]));
- }
- $sub_total = ceil($sum_total);
- $new_ppn = floor($this->check_ppn($vat, $sub_total));
- $amount_invoice_rule = $sub_total + $new_ppn;
- $real = $this->real_field($lmbg, $invoice_rule, $max_amount, $amount_invoice_rule, $sub_total, $vat);
- $sub_total_now = $real[0];
- $sub_total_real = $real[1];
- $new_ppn_now = $real[2];
- $new_ppn_real = $real[3];
- if ($materai == "yes") {
- $new_materai = $this->check_materai($sub_total_now, $new_ppn_now);
- } else if ($materai == "no") {
- $new_materai = 0;
- }
- $pph23 = $this->check_pph23($client_code, $sub_total_now);
- if ($bhp == "yes") {
- $bhp_Edit = ($sub_total_now ) * 0.005; //+ $new_ppn_now
- $bhp_manual_e = "yes";
- } else {
- $bhp_Edit = 0;
- $bhp_manual_e = "no";
- }
- if ($uso == "yes") {
- $uso_Edit = ($sub_total_now ) * 0.0125; //+ $new_ppn_now
- $uso_manual_e = "yes";
- } else {
- $uso_Edit = 0;
- $uso_manual_e = "no";
- }
- $json = [
- "detail" => [
- "info" => [
- "from" => "PT Sprint Asia",
- "recipient" => $client_name,
- "reff_no" => '',
- "cust_id" => $cust_id,
- "sales_person" => ''
- ],
- "data" => array($item),
- "total" => [
- "quantity" => $sum_quantity,
- "unitprice" => $sum_unitprice,
- "sub_total" => ceil($sub_total_now),
- "with_ppn" => floor($new_ppn_now),
- "bhp" => $bhp_Edit,
- "uso" => $uso_Edit,
- "with_pph" => $pph23
- ]
- ],
- ];
- $serialize = json_encode($json);
- }
- // return $serialize;
- $Total = round($sub_total_now + $new_ppn_now + $new_materai - $pph23- $bhp_Edit- $uso_Edit);
- $Total_real = round($sub_total_real + $new_ppn_real + $new_materai - $pph23 - $bhp_Edit - $uso_Edit);
- $revenue_coa = $sc_coa;
- $datas_mi = DB::table('manual_invoice')->select('*')->where('id', $id)->get();
- $id_mi_old = $datas_mi[0]->id;
- $client_code_old = $datas_mi[0]->client_code;
- $division_code_old = $datas_mi[0]->division_code;
- $dept_code_old = $datas_mi[0]->dept_code;
- $desc_old = $datas_mi[0]->desc;
- $vat_old = $datas_mi[0]->vat;
- $materai_old = $datas_mi[0]->materai;
- $bhp_old = $datas_mi[0]->bhp;
- $uso_old = $datas_mi[0]->uso;
- $total_old = $datas_mi[0]->total;
- $conn = DB::connection('account129');
- $datas_clients = $conn->select("Select client_name FROM clients WHERE client_code = '$client_code_old' AND deleted_at is null ");
- $clients_name = $datas_clients[0]->client_name;
- $datas_divisions = $conn->select("Select division_name FROM divisions WHERE division_code = '$division_code_old' AND deleted_at is null ");
- $divisions_name = $datas_divisions[0]->division_name;
- $datas_depts = $conn->select("Select dept_name FROM depts WHERE dept_code = '$dept_code_old' AND deleted_at is null ");
- $depts_name = $datas_depts[0]->dept_name;
- $result_update = "";
- if ( $client_code_old != $client_code ) $result_update = $result_update . ". Client before : " . $clients_name;
- if ( $division_code_old != $division_code ) $result_update = $result_update . ". Division before : " . $divisions_name;
- if ( $dept_code_old != $dept_code ) $result_update = $result_update . ". Departement before : " . $depts_name;
- if ( $desc_old != $request->input('desc') ) $result_update = $result_update . ". Description before : " . $desc_old;
- if ( $vat_old != $vat ) $result_update = $result_update . ". VAT before : " . $vat_old;
- if ( $materai_old != $materai ) $result_update = $result_update . ". Materai before : " . $materai_old;
- if ( $bhp_old != $bhp_manual_e ) $result_update = $result_update . ". BHP before : " . $bhp_old;
- if ( $uso_old != $bhp_manual_e ) $result_update = $result_update . ". USO before : " . $uso_old;
- if ( $total_old != $Total_real ) $result_update = $result_update . ". Total before : " . $total_old;
- if( $result_update == "" ) $result_update = "No Data Updated."; else $result_update = $result_update . " has been Updated.";
- // Manual Invoice
- $manual_invoice = [
- "client_code" => $client_code,
- "dept_code" => $dept_code,
- "division_code" => $division_code,
- "desc" => $desc,
- "vat" => $vat,
- "materai" => $materai,
- "bhp" => $bhp_manual_e,
- "uso" => $uso_manual_e,
- "total" => $Total_real
- ];
- try {
- DB::table("db_sprint_ar.manual_invoice")->where('id', $id)->update($manual_invoice);
- } catch (Exception $e) {
- return ["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- }
- $invoice = [
- "client_code" => $client_code,
- "client_name" => $client_name,
- "division_code" => $division_code,
- "division_name" => $division_name,
- "division_description" => $division_description,
- "dept_code" => $dept_code,
- "dept_name" => $dept_name,
- "pic_id" => $pic_id,
- // "inv_month" => date("m"),
- // "inv_year" => date("yy"),
- "unitprice" => $sum_unitprice,
- "quantity" => $sum_quantity,
- "sub_total" => ceil($sub_total_now),
- "ppn" => floor($new_ppn_now),
- "sub_total_real" => ceil($sub_total_real),
- "ppn_real" => floor($new_ppn_real),
- "materai" => $new_materai,
- "pph23" => $pph23,
- "total" => $Total,
- "total_real" => $Total_real,
- "serialize_data" => $serialize,
- "selisih" => 0,
- // "status" => $statusInv,
- "addmanual" => 1,
- "id_manual" => $id,
- "pic_name" => $pic_name,
- "division_address" => $division_address,
- "bank_acc_number_sprint" => $bank_acc_number_sprint,
- "bank_acc_name_sprint" => $bank_acc_name_sprint,
- "bank_acc_number_client" => $bank_acc_number_client,
- "bank_acc_name_client" => $bank_acc_name_client,
- "bank_coa_sprint" => $bank_coa_sprint,
- "zahir_name" => $zahir_name,
- "client_npwp_no" => $client_npwp_no,
- "bank_name" => $bank_name,
- "client_coa" => $client_coa,
- "revenue_coa" => $revenue_coa,
- "email_client" => $email_client,
- // "pic_collection" => $pic_collection_name,
- "email_collection" => $email_pic_collection,
- // "pic_collection" => $pic_pph23_name,
- "email_pph23" => $email_pic_pph23,
- "pic_position" => $pic_position,
- // "update_print_date" => $update_print_date,
- "description" => $description,
- "ba" => $ba,
- "fp" => $fp,
- "softcopy" => $softcopy,
- "hardcopy" => $hardcopy
- ];
- // $invoice['client_code'] = (bool)$invoice['client_code']; // 0/1 -> PHP false/true
- // return json_encode($invoice); // {'id':true}
- try {
- DB::table("db_sprint_ar.invoice")->where('id_manual', $id)->update($invoice);
- DB::table("db_sprint_ar.manual_invoice")->where('id', $id)->update(["total" => $Total]);
- $username = session()->get('profile')['name'];
- $saved_log_datas = preg_replace( "/\r|\n/", " ", json_encode($invoice) );
- $saved_log_datas = str_replace("\\", "", $saved_log_datas);
- DB::table('history')->insert([ 'client_name'=> $client_name, 'division_name'=> $division_name, 'dept_name'=> $dept_name, 'inp_desc2' => 'Update Manual Invoice , Id : ' . $id_mi_old . ' ' . $result_update , 'inp_desc' => $description, 'activity'=> "Update Manual Invoice", 'description'=> "Update values : ". $saved_log_datas , 'created_by' => $username , 'created_at' => now() ]);
- } catch (Exception $e) {
- return ["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- }
- // Insert to table manual_detail
- for ($i = 0; $i < $length; $i++) {
- $item_temp = $item_name[$i];
- $manual_detail[] = [
- "id_manual" => $id,
- "service" => $service[$i],
- "quantity" => $quantity[$i],
- "unit_price" => $unitprice[$i],
- "desc" => $item_temp, //$item_name[$i],
- "total" => intval(str_replace(',', '', $total[$i]))
- ];
- }
- try {
- DB::beginTransaction();
- DB::table("db_sprint_ar.manual_detail")->where('id_manual', $id)->delete();
- DB::table("db_sprint_ar.manual_detail")->insert($manual_detail);
- DB::commit();
- } catch (Exception $e) {
- DB::rollBack();
- return ["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- }
- return redirect(url('/manual-invoice'))->with('success');
- }
- public function destroy($id)
- {
- try {
- DB::beginTransaction();
- // delete manual invoice
- $mi = ManualInvoice::find($id);
- $gets_mi = DB::table('invoice')->select('*')->where('id_manual', $id)->where('addmanual', '1')->get();
- $client_name = $gets_mi[0]->client_name;
- $division_name = $gets_mi[0]->division_name;
- $dept_name = $gets_mi[0]->dept_name;
- $description = $gets_mi[0]->description;
- $totals = $gets_mi[0]->quantity;
- $username = session()->get('profile')['name'];
- DB::table('history')->insert([ 'client_name'=> $client_name, 'division_name'=> $division_name, 'dept_name'=> $dept_name, 'inp_desc2' => 'Delete Manual Invoice, Id Inv ' . $id . ' , Client Name : ' . $client_name . ' , Division Name : ' . $division_name . ' , Quantity : ' . $totals . ' , Description : ' . $description , 'inp_desc'=> 'Delete Manual Invoice : '.$description . ' Success', 'activity'=> "Delete Manual Invoice", 'description'=> "Delete Manual Invoice id : [". $id . "] , Client Name : [".$client_name."] , Division Name : [".$division_name."] , Dept Name : [".$dept_name."] , Total : [".$totals."] Success " , 'created_by' => $username , 'created_at' => now() ]);
- // DB::table('history')->insert([ 'activity'=> "Delete Manual Invoice", 'description'=> "Delete Manual Invoice id : [". $id . "] Success " , 'created_by' => $username , 'created_at' => now() ]);
- $mi->delete();
- // delete manual detail invoice
- DB::table('manual_detail')->where('manual_detail.id_manual', $id)->delete();
- // Delete Invoice
- DB::table('invoice')->where('id_manual', $id)->delete();
- DB::commit();
- return response()->json(["success" => "Deleted id " . $id]);
- } catch (Exception $e) {
- DB::rollBack();
- return response()->json(["error" => $e->getMessage()]);
- }
- }
- public function upload(Request $request)
- {
- date_default_timezone_set("Asia/Bangkok");
- $dateNow = date('Y-m-d H:i:s');
- $username_login = session()->get('profile')['name'];
- if ($request->input('sc_upload_manual') == "" || $request->input('sc_upload_manual') == "-" || $request->input('sc_upload_manual') == null || $request->input('sc_upload_manual') == '') {
- return redirect()->back()->with('alert_warning', 'Please select a service category!');
- }
- if ($request->file('file_upload_manual') == "" || $request->file('file_upload_manual') == "-" || $request->file('file_upload_manual') == null || $request->file('file_upload_manual') == '') {
- return redirect()->back()->with('alert_warning', 'Please upload file!');
- }
- $service_category = $request->input('sc_upload_manual');
- $File = $request->file('file_upload_manual');
- $revenue_coa = $request->input('sc_upload_manual');
- $nameFileUpload = $File->getClientOriginalName();
- $nameFile = explode("_", $nameFileUpload);
- $client_code = $nameFile[0];
- $month = $nameFile[1];
- $fake_year = $nameFile[2];
- $fake = explode(".", $fake_year);
- $year = $fake[0];
- $path_name = Storage::put('/upload_manual_invoice', $File);
- $results = Excel::selectSheetsByIndex(0)->load($File)->get();
- $header = $results->getHeading(); //get xls's header
- $extension = $File->getClientOriginalExtension();
- $size = $File->getSize();
- $path = $File->getRealPath();
- $username = session()->get('profile')['name'];
- // echo "</br></br> \n service_category : "; print_r($service_category) ; die();
- $arrClient = $this->get_data_client_by_id($client_code);
- if ($arrClient == null || $arrClient == '' || $arrClient == "") {
- return redirect()->back()->with('alert_warning', 'Please Check Client Code Again. File Cannot be Executed.');;
- }
- $client_coas = $arrClient['client_coa'];
- $client_code = $arrClient['client_code'];
- $client_names = $arrClient['client_name'];
- $client_domicile_address = $arrClient['client_domicile_address'];
- $no_spk = $arrClient['client_no_spk'];
- $no_addendum_spk = $arrClient['client_no_addendum_spk'];
- $materai_client = $arrClient['materai'];
- $lmbg = $arrClient['lmbnegara'];
- $max_amount = $arrClient['max_amount'];
- $invoice_rule = $arrClient['invoice_rule'];
- $uploads_manuals = [];
- $conn_am = DB::connection('account129');
- if ($extension == "xlsx" || $extension == "xls")
- {
- $datas = Excel::load($path)->get(); //load all of the data in sheet excel file
- // return $datas;
- // return count($datas);
- $headerRow = $datas->first()->keys()->toArray();
- $index = 0;
- $serialize = [];
- $item_desc_temp = [];
- $datasDivisi = [];
- $rowsDiv = [];
- $jmlhDiv = 0;
- $arryDiv = 0;
- $arryDivMin1 = 0;
- $plusplus = 0;
- $hx = 0;
- $pic_name = '';
- //// Menggabungkan & mengklasifikasikan dengan values Division
- foreach ($datas as $vals)
- {
- $vals_div = $vals['divisi'];
- // echo "</br></br> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ";
- // echo "</br></br> \n vals_div : "; print_r($vals_div) ;
- // echo "</br></br> \n rowsDiv sebelum : "; print_r($rowsDiv) ;
- // echo "</br></br> \n datasDivisi sebelum : "; print_r($datasDivisi) ; echo "</br>";
- if ( in_array($vals_div, $rowsDiv) ) {
- $checkDiv = array_keys($rowsDiv, $vals_div);
- $brsDiv = $checkDiv[0];
- $countdDatasDivisi = count($datasDivisi[$brsDiv]);
- // echo "</br> \n -- checkDiv 1 : "; print_r($checkDiv) ;
- // echo "</br> \n -- brsDiv 1 : "; print_r($brsDiv) ;
- // echo "</br> \n -- countdDatasDivisi 1 : "; print_r($countdDatasDivisi) ;
- $datasDivisi[$brsDiv][$countdDatasDivisi] = $vals ;
- }
- else {
- array_push($rowsDiv,$vals_div);
- $checkDiv = array_keys($rowsDiv, $vals_div);
- $brsDiv = $checkDiv[0];
- // echo "</br> \n -- checkDiv 2 : "; print_r($checkDiv) ;
- // echo "</br> \n -- brsDiv 2 : "; print_r($brsDiv) ;
- $datasDivisi[$brsDiv][] = $vals ;
- }
- // echo "</br></br> \n rowsDiv sesudah : "; print_r($rowsDiv) ;
- // echo "</br></br> \n datasDivisi sesudah : "; print_r($datasDivisi) ;
- // echo "</br></br> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ";
- }
- // return $datasDivisi;
- // echo "</br></br> \n datasDivisi FINAL : "; print_r($datasDivisi) ;
- // echo "</br></br> \n datasDivisi FINAL : "; print_r($datasDivisi) ; die();
- //// END mengabungkan values Division
- // echo "</br></br> \n Datas Divisi Testing : "; print_r($datasDivisi[0][1]['jenis_sms']) ;
- // echo "</br></br> \n Count Divisi : "; print_r(count($datasDivisi)) ;
- $item_description = array();
- $serialize = [];
- //// Men Serialize Data
- for ($ij=0; $ij < count($datasDivisi) ; $ij++)
- {
- $division_name = '';
- $tot_traffict = 0;
- $sum_quantity = 0;
- $sum_uprice = 0;
- $sum_total = 0;
- $new_ppn = 0;
- $new_ppns = 0;
- $cDD = count($datasDivisi[$ij]);
- // echo "</br></br> \n cDD : "; print_r($cDD) ;
- $arrClient = $this->get_data_client_by_id($client_code);
- if ($arrClient == null || $arrClient == '' || $arrClient == "") return redirect()->back()->with('alert_warning', 'Please Check Client Code Again. File Cannot be Executed.');
- //// Menghitung TOtal Trafict tot_traffict
- for ($ih = 0; $ih < $cDD ; $ih++)
- {
- $division_name = $datasDivisi[$ij][$ih]['divisi'];
- $produk = $datasDivisi[$ij][$ih]['produk'];
- if($service_category == '430000001') {$jenis_service = $datasDivisi[$ij][$ih]['jenis_layanan']; $service_code = 'W011'; } // for whatsapp
- else if($service_category == '4102004') { $jenis_service = $datasDivisi[$ij][$ih]['jenis_layanan']; } // for SMS Pull
- else if($service_category == '410000001') { $jenis_service = $datasDivisi[$ij][$ih]['jenis_layanan']; } // for SMS PUSH
- else if($service_category == '450000001') { $jenis_service = $datasDivisi[$ij][$ih]['jenis_layanan']; } // for Email PUSH
- else return redirect()->back()->with('alert_warning', 'Service Category Not Available. Please Check Service Category !!! ');
- $countDatas = count($datasDivisi[$ij][$ih]);
- if (isset($datasDivisi[$ij][$ih]['international'])) {
- $countDatasHeader = $countDatas;
- } else {
- $countDatasHeader = $countDatas-1;
- }
- echo "countDatasHeader ATAS : ". $countDatasHeader. "</br>";
- // if ($countDatasHeader == 9) $countDatasHeader--;
- for ($ik = 3; $ik < $countDatasHeader -1; $ik++) {
- $headers = [ucfirst($header[$ik])];
- $heads = $headers[0];
- $heads_lowers = strtolower($headers[0]);
- $qtty = 'qty_' . str_replace(" ","_", $heads);
- if($headers[0] != "") {
- $qtys = $datasDivisi[$ij][$ih][$heads_lowers];
- $contains_qtty = str_contains($qtys, '-');
- if($contains_qtty == true){
- continue;
- }
- if( $heads == 'Hutchinson' ) $tot_traffict = $tot_traffict + $qtys;
- if( $heads == 'Indosat' ) $tot_traffict = $tot_traffict + $qtys;
- if( $heads == 'Telkomsel' ) $tot_traffict = $tot_traffict + $qtys;
- if( $heads == 'Smartfren' ) $tot_traffict = $tot_traffict + $qtys;
- if( $heads == 'Excelcom' ) $tot_traffict = $tot_traffict + $qtys;
- if( $heads == 'Email Blast' ) $tot_traffict = $tot_traffict + $qtys;
- else $tot_traffict = $tot_traffict;
- }
- }
- }
- // End Menghitung TOtal Trafict tot_traffict
- //dd($tot_traffict);
- // For generate itemdesc
- for ($ih = 0; $ih < $cDD ; $ih++)
- {
- $division_name = $datasDivisi[$ij][$ih]['divisi'];
- $produk = $datasDivisi[$ij][$ih]['produk'];
- if($service_category == '430000001') $jenis_service = $datasDivisi[$ij][$ih]['jenis_layanan']; // for whatsapp
- else if($service_category == '4102004') { $jenis_service = $datasDivisi[$ij][$ih]['jenis_layanan']; } // for SMS Pull
- else if($service_category == '410000001') $jenis_service = $datasDivisi[$ij][$ih]['jenis_layanan']; // for SMS PUSH
- else if($service_category == '450000001') { $jenis_service = $datasDivisi[$ij][$ih]['jenis_layanan']; } // for Email PUSH
- else return redirect()->back()->with('alert_warning', 'Service Category Not Available. Please Check Service Category !!! ');
- if ($division_name == null || $division_name == '' || $division_name == "" || $division_name == "eof") break;
- $client_coas = $arrClient['client_coa'];
- $client_code = $arrClient['client_code'];
- $client_names = $arrClient['client_name'];
- $client_domicile_address = $arrClient['client_domicile_address'];
- $materai_client = $arrClient['materai'];
- $lmbg = $arrClient['lmbnegara'];
- $max_amount = $arrClient['max_amount'];
- $invoice_rule = $arrClient['invoice_rule'];
- $countDatas = count($datasDivisi[$ij][$ih]);
- if (isset($datasDivisi[$ij][$ih]['international'])) {
- $countDatasHeader = $countDatas;
- } else {
- $countDatasHeader = $countDatas-1;
- }
- dd($countDatasHeader);
- if ($countDatasHeader == 9) $countDatasHeader++;
- // dd($countDatasHeader);
- // if ($countDatasHeader == 9) $countDatasHeader--;
- for ($ik = 3; $ik < $countDatasHeader -1; $ik++)
- {
- $headers = [ucfirst($header[$ik])];
- $heads = $headers[0];
- $qtty = explode("_",$heads);
- $itemsName = ucwords(join(" ", $qtty));
- $headsEmail = explode(" ", $itemsName);
- $email_blast = $headsEmail[0];
- $email_lower = lcfirst($email_blast);
- $heads_lowers = strtolower($headers[0]);
- if($jenis_service == "SMS Premium" && $heads != 'International') {
- $itemsName = $heads . " Premium";
- } else {
- $itemsName = $itemsName;
- }
- $qtys = $datasDivisi[$ij][$ih][$heads_lowers];
- $contains = str_contains($qtys, '-');
- if($contains == true) {
- $check = "true";
- } else {
- $check = "false";
- }
- if($check == "false")
- {
- $unitprice = 0;
- if ($service_category == '430000001') {
- $getClientsPrice = $conn_am->select("Select a.*, b.service_name
- FROM db_sprint_account.client_price AS a
- LEFT JOIN `services` AS b ON a.service_code = b.service_code
- WHERE a.client_code = '".$client_code."' AND b.service_name = '".$jenis_service."' AND a.provider_code = '".$itemsName."' LIMIT 1");
- } else if ($service_category == '450000001') {
- $getClientsPrice = $conn_am->select("Select a.*, b.service_name
- FROM db_sprint_account.client_price AS a
- LEFT JOIN `services` AS b ON a.service_code = b.service_code
- WHERE a.client_code = '".$client_code."' AND b.service_name = '".$email_blast."' AND a.provider_code = '".$email_blast."' LIMIT 1");
- } else {
- $getClientsPrice = $conn_am->select("Select a.*, b.service_name
- FROM db_sprint_account.client_price AS a
- LEFT JOIN db_sprint_account.`services` AS b ON a.service_code = b.service_code
- WHERE a.client_code = '".$client_code."' AND b.service_name = '".$jenis_service."' AND a.provider_code = '".$heads."' LIMIT 1");
- }
- if( !empty($getClientsPrice) )
- {
- $prc_type = $getClientsPrice[0]->price_type;
- $hrgPrc = $getClientsPrice[0]->price;
- $arryPrice = json_decode($hrgPrc);
- $countPrice = count($arryPrice);
- $vats = $getClientsPrice[0]->vat;
- } else {
- $prc_type = 1;
- $arryPrice = [0];
- $countPrice = count($arryPrice);
- $vats = 'exclude';
- }
- if ($prc_type == 1) {
- $unitprice = $arryPrice[0];
- } else if ($prc_type == 2) {
- $unitprice = round(($arryPrice[0] * $arryPrice[1] ));
- } else if ($prc_type == 3) {
- for ($p = 0; $p < $countPrice ; $p++)
- {
- $trfct = intval($tot_traffict);
- $tr1 = intval($arryPrice[$p][0]);
- $tr2 = intval($arryPrice[$p][1]);
- $hrg = intval($arryPrice[$p][2]);
- if ($trfct >= $tr1 && $trfct <= $tr2 ) {
- $unitprice = $hrg;
- } else {
- if ($unitprice > 0 ) {
- $unitprice = $unitprice;
- } else {
- $unitprice = 0;
- }
- }
- }
- }
- $tot_hrg = $unitprice * $qtys;
- $item_desc_temp[$ij][$ih][] = [
- "item_name" => $itemsName,
- "quantity" => $qtys,
- "unitprice" => $unitprice,
- "total" => $tot_hrg,
- ];
- if($vats == 'exclude') {
- $new_ppns = floor($tot_hrg * 0.11);
- } else {
- $new_ppns = 0;
- }
- $sum_quantity = $sum_quantity + $qtys;
- $sum_uprice = $sum_uprice + $unitprice;
- $sum_total = $sum_total + $tot_hrg;
- $new_ppn = $new_ppn + $new_ppns;
- } else {
- continue;
- }
- }
- $data_items[$ij][] = [
- "item" => $produk,
- "item_desc" => $item_desc_temp[$ij][$ih]
- ];
- }
- if ($ij > 0) {
- continue;
- }
- $json = [
- "detail" => [
- "info" => [
- "from" => "PT Sprint Asia",
- "recipient" => $client_names,
- "reff_no" => '',
- "cust_id" => '',
- "sales_person" => ''
- ],
- "data" => array($data_items[$ij]),
- "total" => [
- "quantity" => $sum_quantity,
- "unitprice" => $sum_uprice,
- "sub_total" => ceil($sum_total),
- "with_ppn" => floor($new_ppn),
- "with_pph" => 0
- ]
- ],
- ];
- $serialize = json_encode($json);
- $data_div = $this->get_data_division_by_name_and_client_code($division_name, $client_code);
- if ($data_div == null || $data_div == '' || $data_div == "") {
- return redirect()->back()->with('alert_warning', 'Please Check Data Divisi ' . $division_name .' Again. File Cannot be Executed.');;
- }
- //Division
- $division_names = $data_div['division_name'];
- $division_code = $data_div['division_code'];
- $bank_acc_number_sprint = $data_div['division_bank_acc_number_sprint'];
- $bank_acc_name_sprint = $data_div['division_bank_acc_name_sprint'];
- $bank_coa_sprint = $data_div['division_bank_coa_sprint'];
- $zahir_name = $data_div['division_zahir_name'];
- $client_npwp_no = $data_div['division_npwp'];
- $bank_acc_name_client = $data_div['division_bank_account_name'];
- $bank_acc_number_client = $data_div['division_bank_account_number'];
- $bank_name = $data_div['division_bank_name_sprint'];
- $client_coa = $data_div['division_bank_name_sprint'];
- $division_address = $data_div['division_address'];
- $division_invoice_rule = $data_div['division_invoice_rule'];
- $division_max_amount = $data_div['division_max_amount'];
- $division_description = $data_div['division_description'];
- $ba = $data_div['berita_acara'];
- if($ba == 1){$ba = "Yes";}else{$ba = "No";}
- $fp = $data_div['faktur_pajak'];
- if($fp == 1){$fp = "Yes";}else{$fp = "No";}
- $softcopy = $data_div['soft_copy'];
- if($softcopy == 1){$softcopy = "Yes";}else{$softcopy = "No";}
- $hardcopy = $data_div['hard_copy'];
- if($hardcopy == 1){$hardcopy = "Yes";}else{$hardcopy = "No";}
- $dept_code = "$division_code-00";
- $data_dept = $this->get_data_dept_by_id($dept_code);
- if ($data_dept == null || $data_dept == '' || $data_dept == "") {
- return redirect()->back()->with('alert_warning', 'Please Check Data Department '.$dept_code.' Again. File Cannot be Executed.');
- }
- $dept_code = $data_dept['dept_code'];
- $dept_names = $data_dept['dept_name'];
- //PIC
- $data_pic = $this->get_data_pics_by_id($division_code);
- if ($data_pic == null || $data_pic == '' || $data_pic == "" || $data_pic == []) {
- return redirect()->back()->with('alert_warning', 'Please Check Data PIC from Division '.$division_code.'. File Cannot be Executed.');
- }
- $pic_id = $data_pic['pic_id'];
- $pic_name = $data_pic['pic_name'];
- $email_client = $data_pic['pic_email'];
- $pic_position = $data_pic['pic_position'];
- $data_pic_collection = $this->get_data_pic_collection($division_code);
- if ($data_pic_collection == null || $data_pic_collection == '' || $data_pic_collection == "") {
- $pic_collection_name = "";
- $email_pic_collection = $email_client;
- }
- else {
- if( !empty ($data_pic_collection['pic_name']) ) $pic_collection_name = $data_pic_collection['pic_name'];
- else return redirect()->back()->with('alert_warning', 'Please Check pic_type_id at Pic Name ' . $division_name .' Again. File Cannot be Executed.');;
- $email_pic_collection = $data_pic_collection['pic_email'];
- }
- $data_pic_pph23 = $this->get_data_pic_pph23($division_code);
- // echo "</br></br> \n ~~~~~ data_pic_pph23 : "; print_r($data_pic_pph23) ; echo "~~~~~ </br> \n ";
- if ($data_pic_pph23 == null || $data_pic_pph23 == '' || $data_pic_pph23 == "") {
- $pic_pph23_name = "";
- $email_pic_pph23 = $email_client;
- }
- else {
- $pic_pph23_name = $data_pic_pph23['pic_name'];
- $email_pic_pph23 = $data_pic_pph23['pic_email'];
- }
- $sub_total = ceil($sum_total);
- $amount_invoice_rule = $sub_total + $new_ppn;
- if($new_ppn > 0){
- $vats = "exclude";
- }else if($new_ppn <= 0){
- $vats = "include";
- }
- //cek BUMN/Lembaga
- $real = $this->real_field($lmbg, $invoice_rule, $max_amount, $amount_invoice_rule, $sub_total, $vats);
- $sub_total_now = $real[0];
- $sub_total_real = $real[1];
- $new_ppn_now = $real[2];
- $new_ppn_real = $real[3];
- $new_materai = 0;
- if ($materai_client == 1) $new_materai = $this->check_materai($sub_total_now, $new_ppn_now);
- else if ($materai_client == 0) $new_materai = 0;
- $pph23 = $this->check_pph23($client_code, $sub_total_now);
- $Total = round($sub_total_now + $new_ppn_now + $new_materai - $pph23);
- $Total_real = round($sub_total_real + $new_ppn_real + $new_materai - $pph23);
- $now = \Carbon\Carbon::now();
- $descManual = "-";
- if($materai_client == 1 ) $materai = "yes"; else $materai = "no";
- $invXls[] = array(
- "client_code" => $client_code,
- "client_name" => $client_names,
- "division_code" => $division_code,
- "division_name" => $division_names,
- "division_description" => $division_description,
- "dept_code" => $dept_code,
- "dept_name" => $dept_names,
- "pic_id" => $pic_id,
- "pic_name" => $pic_name,
- "pic_position" => $pic_position,
- "inv_month" => $month, //date("m"),
- "inv_year" => $year, //date("yy"),
- "unitprice" => $sum_uprice,
- "quantity" => $sum_quantity,
- "sub_total" => ceil($sub_total_now),
- "ppn" => floor($new_ppn_now),
- "sub_total_real" => ceil($sub_total_real),
- "ppn_real" => floor($new_ppn_real),
- "materai" => $new_materai,
- "pph23" => $pph23,
- "total" => $Total,
- "total_real" => $Total_real,
- "serialize_data" => $serialize,
- "selisih" => 0,
- "status" => 0,
- "addmanual" => 2,
- "division_address" => $division_address,
- "bank_acc_number_sprint" => $bank_acc_number_sprint,
- "bank_acc_name_sprint" => $bank_acc_name_sprint,
- "bank_acc_number_client" => $bank_acc_number_client,
- "bank_acc_name_client" => $bank_acc_name_client,
- "bank_coa_sprint" => $bank_coa_sprint,
- "zahir_name" => $zahir_name,
- "client_npwp_no" => $client_npwp_no,
- "bank_name" => $bank_name,
- "client_coa" => $client_coas,
- "revenue_coa" => $revenue_coa,
- "email_client" => $email_client,
- "email_collection" => $email_pic_collection,
- "email_pph23" => $email_pic_pph23,
- "description" => $produk,
- "created_at" => $now,
- "created_by" => $username ." - Upload Manual Invoice",
- "id_collection" =>'[""]',
- "ba" => $ba,
- "fp" => $fp,
- "softcopy" => $softcopy,
- "hardcopy" => $hardcopy
- );
- }
- //// END Men Serialize Data
- // return $invXls;
- if (!empty($invXls)) {
- DB::table('db_sprint_ar.invoice')->insert($invXls);
- $username = session()->get('profile')['name'];
- $now = Carbon\Carbon::now('Asia/Jakarta');
- $saved_log_datas = preg_replace( "/\r|\n/", " ", json_encode($invXls) );
- $saved_log_datas = str_replace("\\", "", $saved_log_datas);
- DB::table('history')->insert([ 'client_name'=> $client_names, 'division_name'=> $division_names, 'dept_name'=> $dept_names, 'inp_desc2' => "Upload Manual Invoice, Clients Name : ".$client_names." , Divisions Name : ".$division_names." , Quantity : ".$sum_quantity. " , Description : ". $produk , 'inp_desc'=> $produk, 'activity'=> "Upload Manual Invoice", 'description'=> "Upload values : ". $saved_log_datas , 'created_by' => $username , 'created_at' => $now ]);
- }
- DB::commit();
- $up_manualInvoice = [
- "path_name" => $path_name,
- "file_name" => $nameFileUpload,
- "size" => $size,
- "created_at" => now()
- ];
- $insert_upload_ = DB::table('upload_manual_invoice')->insert($up_manualInvoice);
- return redirect()->back()->with('alert_import', 'Import file success');
- }
- else
- {
- return redirect()->back()->with('alert_warning', 'Something wrong, excel only');
- }
- }
- public function upload_tes(Request $request)
- {
- try {
- if ($request->input('sc_upload_manual') == "" || $request->input('sc_upload_manual') == "-" || $request->input('sc_upload_manual') == null || $request->input('sc_upload_manual') == '') {
- //return redirect()->back()->with('alert', 'Service Category Tidak Dapat Dipilih. Silahkan Periksa di Account Management. Data Tidak Tersimpan.');
- return redirect('/upload-manual-invoice')->with('error', 'Service Category Tidak Dapat Dipilih. Silahkan Periksa di Account Management. Data Tidak Tersimpan.');
- }
- $File = $request->file('file_upload_manual');
- $revenue_coa = $request->input('sc_upload_manual');
- $nameFileUpload = $File->getClientOriginalName();
- $path_name = Storage::put('/upload_manual_invoice', $File);
- $size = $File->getSize();
- $nameFile = explode("_", $nameFileUpload);
- // return $nameFile;
- $client_code = $nameFile[0];
- $month = $nameFile[1];
- $fake_year = $nameFile[2];
- $fake = explode(".", $fake_year);
- $year = $fake[0];
- $results = Excel::selectSheetsByIndex(0)->load($File)->get();
- $header = $results->getHeading(); //get xls's header
- $extension = $File->getClientOriginalExtension();
- $size = $File->getSize();
- $path = $File->getRealPath();
- // return $path ;
- if ($extension == "xlsx" || $extension == "xls") {
- $datas = Excel::load($path)->get(); //load all of the data in sheet excel file
- $index = 0;
- // return $datas;
- if ($datas->count() != 0) {
- DB::beginTransaction();
- $invXls = array();
- foreach ($datas as $data) {
- // try {
- $division_name = $data['divisi'];
- $item_name = $data['produk'];
- $service_name = $data['jenis_sms'];
- $qty_Hutchinson = $data[$header[3]];
- $qty_Indosat = $data[$header[4]];
- $qty_Telkomsel = $data[$header[5]];
- $qty_Smartfren = $data[$header[6]];
- $qty_Xl = $data[$header[7]];
- // $qty_Inter = $data[$header[8]];
- // $qty_Satelindo = $data[$header[9]];
- if ($division_name == null || $division_name == '' || $division_name == "" || $division_name == "eof") {
- break;
- }
- // if ($end_of_per == "eof" || $channel_1 == "eof" || $channel_2 == "eof" || $channel_4 == "eof") {
- // continue;
- // }
- $temp_item_desc = [];
- for ($q = 3; $q < 8; $q++) {
- if ($data[$header[$q]] != null) {
- $uppercased = Str::ucfirst($header[$q]); //set the first alfabet as an uppercase
- $temp_item_desc[] = [$uppercased, $data[$header[$q]]];
- }
- }
- $arrClient = $this->get_data_client_by_id($client_code);
- if ($arrClient == null || $arrClient == '' || $arrClient == "") {
- return redirect()->back()->with('alert', 'Please Check Client Code Again. File Cannot be Executed.');;
- }
- // return $arrClient;
- $client_coas = $arrClient['client_coa'];
- $client_code = $arrClient['client_code'];
- $client_names = $arrClient['client_name'];
- $client_domicile_address = $arrClient['client_domicile_address'];
- $materai_client = $arrClient['materai'];
- $lmbg = $arrClient['lmbnegara'];
- $max_amount = $arrClient['max_amount'];
- $invoice_rule = $arrClient['invoice_rule'];
- $sum_quantity = 0;
- $sum_uprice = 0;
- $sum_total = 0;
- $new_ppn = 0;
- $item_d = [];
- foreach ($temp_item_desc as $temp_id) {
- $arrServiceSMS = $this->get_data_service_sms($service_name);
- if ($arrServiceSMS == null || $arrServiceSMS == '' || $arrServiceSMS == "") {
- return redirect()->back()->with('alert', 'Please Check Data Jenis SMS Again. File Cannot be Executed.');;
- }
- $service_code = $arrServiceSMS['service_code'];
- if($temp_id[0] == "Hutchinson" && $service_code == "S101"){ //s101 premium - s102 reguler
- $service_code = "S102";
- }else if($temp_id[0] == "Smartfren" && $service_code == "S101"){
- $service_code = "S102";
- }
- else if($temp_id[0] == "Hutchinson" && $service_code == "S102"){
- $service_code = "S102";
- }else if($temp_id[0] == "Smartfren" && $service_code == "S102"){
- $service_code = "S102";
- }
- $arrPrice = $this->get_data_price($client_code, $temp_id[0], $service_code);
- if ($arrPrice == null || $arrPrice == '' || $arrPrice == "") {
- return redirect()->back()->with('alert', 'Please Check Data Provider '.$temp_id[0].' Again. File Cannot be Executed.');;
- }
- // return $arrPrice;
- $price_type = $arrPrice['price_type'];
- $vat = $arrPrice['vat'];
- $tmp_uprice = $arrPrice['price'];
- $price = json_decode($tmp_uprice);
- if ($price_type == 1) {
- $p = $price[0];
- $real_price = (int)$p;
- } else if ($price_type == 2) {
- $p = $price[0];
- $amount = 0;
- $real_price = (int)$p * $amount;
- } else if ($price_type == 3) {
- $traffict = $temp_id[1];
- for($p = 0; $p < count($price); $p++){
- $from = $price[$p][0];
- $to = $price[$p][1];
- // $price = $price[$p][2];
- if($traffict > $from && $traffict <= $to){
- $real_price = $price[$p][2];
- }else{
- continue;
- }
- }
- }else if($price_type == 4){
- $traffict = $temp_id[1];
- for($p = 0; $p < count($price); $p++){
- $from = $price[$p][0];
- $to = $price[$p][1];
- // $price = $price[$p][2];
- if($traffict > $from && $traffict <= $to){
- $real_price = $traffict * $price[$p][2];
- }else{
- continue;
- }
- }
- }
- $tot = $temp_id[1] * $real_price;
- $item_d[] = [
- "item_name" => $temp_id[0],
- "quantity" => $temp_id[1],
- "unitprice" => $real_price,
- "total" => $tot
- ];
- $sum_quantity += $temp_id[1];
- $sum_uprice += $real_price;
- $sum_total += $tot;
- $new_ppns = $this->check_ppn($vat, $tot);
- $new_ppn += $new_ppns;
- }
- $it = [
- "item" => $data['produk'],
- "item_desc" => $item_d
- ];
- $json = [
- "detail" => [
- "info" => [
- "from" => "PT Sprint Asia",
- "recipient" => $client_names,
- "reff_no" => '',
- "cust_id" => '',
- "sales_person" => ''
- ],
- "data" => array(array($it)),
- "total" => [
- "quantity" => $sum_quantity,
- "unitprice" => $sum_uprice,
- "sub_total" => ceil($sum_total),
- "with_ppn" => floor($new_ppn),
- "with_pph" => 0
- ]
- ],
- ];
- $serialize = json_encode($json);
- $data_div = $this->get_data_division_by_name_and_client_code($division_name, $client_code);
- if ($data_div == null || $data_div == '' || $data_div == "") {
- return redirect()->back()->with('alert', 'Please Check Data Divisi ' . $division_name .' Again. File Cannot be Executed.');;
- }
- //Division
- $division_names = $data_div['division_name'];
- $division_code = $data_div['division_code'];
- $bank_acc_number_sprint = $data_div['division_bank_acc_number_sprint'];
- $bank_acc_name_sprint = $data_div['division_bank_acc_name_sprint'];
- $bank_coa_sprint = $data_div['division_bank_coa_sprint'];
- $zahir_name = $data_div['division_zahir_name'];
- $client_npwp_no = $data_div['division_npwp'];
- $bank_acc_name_client = $data_div['division_bank_account_name'];
- $bank_acc_number_client = $data_div['division_bank_account_number'];
- $bank_name = $data_div['division_bank_name_sprint'];
- $client_coa = $data_div['division_bank_name_sprint'];
- $division_address = $data_div['division_address'];
- $division_invoice_rule = $data_div['division_invoice_rule'];
- $division_max_amount = $data_div['division_max_amount'];
- $division_description = $data_div['division_description'];
- $ba = $data_div['berita_acara'];
- if($ba == 1){$ba = "Yes";}else{$ba = "No";}
- $fp = $data_div['faktur_pajak'];
- if($fp == 1){$fp = "Yes";}else{$fp = "No";}
- $softcopy = $data_div['soft_copy'];
- if($softcopy == 1){$softcopy = "Yes";}else{$softcopy = "No";}
- $hardcopy = $data_div['hard_copy'];
- if($hardcopy == 1){$hardcopy = "Yes";}else{$hardcopy = "No";}
- $dept_code = "$division_code-00";
- $data_dept = $this->get_data_dept_by_id($dept_code);
- if ($data_dept == null || $data_dept == '' || $data_dept == "") {
- return redirect()->back()->with('alert', 'Please Check Data Department '.$dept_code.' Again. File Cannot be Executed.');
- }
- $dept_code = $data_dept['dept_code'];
- $dept_names = $data_dept['dept_name'];
- //PIC
- $data_pic = $this->get_data_pics_by_id($division_code);
- if ($data_pic == null || $data_pic == '' || $data_pic == "") {
- return redirect()->back()->with('alert', 'Please Check Data PIC from Division '.$division_code.'. File Cannot be Executed.');
- }
- $pic_id = $data_pic['pic_id'];
- $pic_name = $data_pic['pic_name'];
- $email_client = $data_pic['pic_email'];
- $pic_position = $data_pic['pic_position'];
- $data_pic_collection = $this->get_data_pic_collection($division_code);
- if ($data_pic_collection == null || $data_pic_collection == '' || $data_pic_collection == "") {
- $pic_collection_name = "";
- $email_pic_collection = $email_client;
- }
- $pic_collection_name = $data_pic_collection['pic_name'];
- $email_pic_collection = $data_pic_collection['pic_email'];
- $data_pic_pph23 = $this->get_data_pic_pph23($division_code);
- if ($data_pic_pph23 == null || $data_pic_pph23 == '' || $data_pic_pph23 == "") {
- $pic_pph23_name = "";
- $email_pic_pph23 = $email_client;
- }
- $pic_pph23_name = $data_pic_pph23['pic_name'];
- $email_pic_pph23 = $data_pic_pph23['pic_email'];
- $sub_total = ceil($sum_total);
- $amount_invoice_rule = $sub_total + $new_ppn;
- if($new_ppn > 0){
- $vats = "exclude";
- }else if($new_ppn <= 0){
- $vats = "include";
- }
- //cek BUMN/Lembaga
- $real = $this->real_field($lmbg, $invoice_rule, $max_amount, $amount_invoice_rule, $sub_total, $vats);
- $sub_total_now = $real[0];
- $sub_total_real = $real[1];
- $new_ppn_now = $real[2];
- $new_ppn_real = $real[3];
- $new_materai = 0;
- if ($materai_client == 1) {
- $new_materai = $this->check_materai($sub_total_now, $new_ppn_now);
- } else if ($materai_client == 0) {
- $new_materai = 0;
- }
- $pph23 = $this->check_pph23($client_code, $sub_total_now);
- $Total = round($sub_total_now + $new_ppn_now + $new_materai - $pph23);
- $Total_real = round($sub_total_real + $new_ppn_real + $new_materai - $pph23);
- $now = \Carbon\Carbon::now();
- $descManual = "-";
- if($materai_client == 1 ){
- $materai = "yes";
- }else{
- $materai = "no";
- }
- $manual_invoice = [
- "client_code" => $client_code,
- "dept_code" => $dept_code,
- "division_code" => $division_code,
- "desc" => $descManual,
- "vat" => $vat, //?
- "materai" => $materai, //?
- "total" => $Total
- ];
- $last_id = DB::table("db_sprint_ar.manual_invoice")->insertGetId($manual_invoice);
- $invXls[] = array(
- "client_code" => $client_code,
- "client_name" => $client_names,
- "division_code" => $division_code,
- "division_name" => $division_names,
- "division_description" => $division_description,
- "dept_code" => $dept_code,
- "dept_name" => $dept_names,
- "pic_id" => $pic_id,
- "pic_name" => $pic_name,
- "pic_position" => $pic_position,
- "inv_month" => $month, //date("m"),
- "inv_year" => $year, //date("yy"),
- "unitprice" => $sum_uprice,
- "quantity" => $sum_quantity,
- "sub_total" => ceil($sub_total_now),
- "ppn" => floor($new_ppn_now),
- "sub_total_real" => ceil($sub_total_real),
- "ppn_real" => floor($new_ppn_real),
- "materai" => $new_materai,
- "pph23" => $pph23,
- "total" => $Total,
- "total_real" => $Total_real,
- "serialize_data" => $serialize,
- "selisih" => 0,
- "status" => 0,
- "addmanual" => 1,
- "id_manual" => $last_id,
- "division_address" => $division_address,
- "bank_acc_number_sprint" => $bank_acc_number_sprint,
- "bank_acc_name_sprint" => $bank_acc_name_sprint,
- "bank_acc_number_client" => $bank_acc_number_client,
- "bank_acc_name_client" => $bank_acc_name_client,
- "bank_coa_sprint" => $bank_coa_sprint,
- "zahir_name" => $zahir_name,
- "client_npwp_no" => $client_npwp_no,
- "bank_name" => $bank_name,
- "client_coa" => $client_coas,
- "revenue_coa" => $revenue_coa,
- "email_client" => $email_client,
- "email_collection" => $email_pic_collection,
- "email_pph23" => $email_pic_pph23,
- "description" => $item_name,
- "created_at" => $now,
- "id_collection" =>'[""]',
- "ba" => $ba,
- "fp" => $fp,
- "softcopy" => $softcopy,
- "hardcopy" => $hardcopy
- );
- // return $invXls;
- $manual_detail = [];
- for($f = 0; $f < count($item_d); $f++){
- if($f != 0){
- $item_name = null;
- }
- $manual_detail[] = [
- "id_manual" => $last_id,
- "service" => $item_d[$f]['item_name'] ,
- "quantity" => $item_d[$f]['quantity'],
- "unit_price" => $item_d[$f]['unitprice'],
- "desc" => $item_name,
- "total" => $item_d[$f]['total']
- ];
- }
- $last_id = DB::table("db_sprint_ar.manual_detail")->insert($manual_detail);
- // } catch (Exception $e) {
- // return redirect()->back()->with('alert', 'Please Check Your Data Again. File Cannot be Executed.');
- // }
- }
- }
- // return $invXls;
- if (!empty($invXls)) {
- DB::table('db_sprint_ar.invoice')->insert($invXls);
- }
- DB::commit();
- $up_manualInvoice = [
- "path_name" => $path_name,
- "file_name" => $nameFileUpload,
- "size" => $size,
- "created_at" => now()
- ];
- $insert_upload_ = DB::table('upload_manual_invoice')->insert($up_manualInvoice);
- return redirect()->back()->with('alert', 'Import File Success.');
- } else {
- return redirect()->back()->with('alert', 'Something Wrong. Excel Only.');
- }
- } catch (Exception $e) {
- DB::rollback();
- }
- }
- public function upload_manual_invoice_load_data(){
- try {
- $datas = [];
- // return $invoices = DB::table('invoice')->select('id', 'no_inv', 'client_name', 'division_name', 'total')->where('inv_month', date('m'))->where('inv_year', date('Y'))->where('status', $this->status)->get();
- $file_upload = DB::table('upload_manual_invoice')->select('file_name', 'size', DB::raw('IF(created_at IS NULL, "", DATE_FORMAT(DATE(created_at), "%d/%m/%Y")) AS created_at'))->orderBy('created_at', 'desc')->get();
- foreach ($file_upload as $key => $fu) {
- $datas[] = [
- "file_name" => $fu->file_name,
- "size" => $fu->size,
- "created_at" => date($fu->created_at),
- ];
- }
- return $datas;
- } catch (Exception $e) {
- return [];
- }
- }
- public function get_data_manual_invoice($id)
- {
- $top = DB::table('db_sprint_ar.manual_invoice AS a')
- ->where('a.id', $id)
- ->join('db_sprint_ar.invoice AS b', 'b.id_manual', 'a.id')
- ->select('a.id', 'a.client_code', 'b.client_name', 'a.dept_code', 'a.division_code', 'a.total', 'a.desc', 'a.materai', 'a.bhp', 'a.uso', 'b.revenue_coa', 'a.vat')
- ->get();
- $details = DB::table('db_sprint_ar.manual_detail')
- ->where('id_manual', $id)
- ->select('id_manual', 'service', 'quantity', 'unit_price', 'total', 'desc')
- ->get()
- ->groupBy('id_manual');
- foreach ($top as $d) {
- foreach ($details[$d->id] as $dt) {
- $id_desc = $this->get_id_desc($dt->service);
- $datas[] = [
- "id_service" => $id_desc,
- "service" => $dt->service,
- "quantity" => $dt->quantity,
- "unit_price" => $dt->unit_price,
- "total" => $dt->total,
- "desc" => $dt->desc
- ];
- }
- return $data = [
- "id" => $d->id,
- "client_code" => $d->client_code,
- "client_name" => $d->client_name,
- "dept_code" => $d->dept_code,
- "division_code" => $d->division_code,
- "desc" => $d->desc,
- "vat" => $d->vat,
- "materai" => $d->materai,
- "coa_of_category" => $d->revenue_coa,
- "bhp" => $d->bhp,
- "uso" => $d->uso,
- "details" => $datas
- ];
- }
- }
- public function real_field($lmbg, $invoice_rule, $max_amount, $amount_invoice_rule, $sub_total, $vat){
- $sub_total_now = 0; $sub_total_real = 0; $new_ppn_now = 0; $new_ppn_real = 0;
- if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 1 && $vat == 'exclude' ){ //exclude
- if($sub_total > $max_amount){
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = floor($sub_total * 0.11);
- $new_ppn_real = 0; //ke sprint
- }else{
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = floor($sub_total * 0.11);
- $new_ppn_real = floor($sub_total_real * 0.11);
- }
- }else if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 1 && $vat == 'include' ){ //include
- if($sub_total > $max_amount){
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total / 1.11);
- $new_ppn_now = 0; //$sub_total * 0.1;
- $new_ppn_real = 0; //$sub_total * 0.1;
- }else{
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total / 1.11);
- $new_ppn_now = 0;
- $new_ppn_real = floor($sub_total_real * 0.11);
- }
- }else if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 2 && $vat == 'exclude'){ //exclude
- if($amount_invoice_rule > $max_amount){
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = floor($sub_total * 0.11);
- $new_ppn_real = 0; //ke sprint
- }else{
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = floor($sub_total * 0.11);
- $new_ppn_real = floor($sub_total_real * 0.11);
- }
- }else if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 2 && $vat == 'include' ){ //include
- if($amount_invoice_rule > $max_amount){
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total / 1.11);
- $new_ppn_now = 0; //$sub_total * 0.1;
- $new_ppn_real = 0; //$sub_total * 0.1;
- }else{
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total / 1.11);
- $new_ppn_now = 0;
- $new_ppn_real = floor($sub_total_real * 0.11);
- }
- }else if(($lmbg == "no" || $lmbg == null || $lmbg == '' || $lmbg == "No") && $vat == 'exclude'){ //exlude
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total); /// 1.1;
- $new_ppn_now = floor($sub_total * 0.11);
- $new_ppn_real = floor($sub_total_real * 0.11);
- }else if(($lmbg == "no" || $lmbg == null || $lmbg == '' || $lmbg == "No") && $vat == 'include'){ //include
- $sub_total_now = ceil($sub_total);
- $sub_total_real = ceil($sub_total / 1.11);
- $new_ppn_now = 0; //$sub_total * 0.1;
- $new_ppn_real = floor($sub_total_real * 0.11);
- }
- $real = [$sub_total_now, $sub_total_real, $new_ppn_now, $new_ppn_real];
- return $real;
- }
- public function get_data_manual_detail($id)
- {
- return $dtdetail = DB::table('manual_detail')
- ->join('db_sprint_account.services', 'db_sprint_account.services.service_code', '=', 'manual_detail.service')
- ->where('manual_detail.id_manual', $id)
- ->get();
- }
- public function get_data_sc(Request $request)
- {
- $sc = new \GuzzleHttp\Client(['base_uri' => env('HTTP_URL_CLIENT') . 'getservice_category']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $sc->request('GET', '', [
- 'headers' => $headers,
- // 'query' => ['client_code' => $code]
- ]);
- $dtsc = json_decode($response->getBody()->getContents(), true)['data'];
- return json_encode($dtsc);
- }
- public function get_data_sc_e($code)
- {
- $sc_e = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/getservice_category_e']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $sc_e->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['revenue_coa' => $code]
- ]);
- $dtsc_e = json_decode($response->getBody()->getContents(), true)['data'];
- return json_encode($dtsc_e);
- }
- public function get_data_division($code)
- {
- $client = new \GuzzleHttp\Client(['base_uri' => env('HTTP_URL_CLIENT') . 'get_data_division']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $client->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['client_code' => $code]
- ]);
- $dtclient = json_decode($response->getBody()->getContents(), true)['data'];
- return json_encode($dtclient);
- }
- public function get_data_dept_name($code)
- {
- $client = new \GuzzleHttp\Client(['base_uri' => env('HTTP_URL_CLIENT') . 'get_data_dept']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $client->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['division_code' => $code]
- ]);
- $dtclient = json_decode($response->getBody()->getContents(), true)['data'];
- return json_encode($dtclient);
- }
- public function get_data_service()
- {
- $dtservs = ServiceCategory::select('service_category_code', 'service_category_name', 'coa_of_category')->get();
- return response()->json($dtservs);
- }
- public function get_client_name($id)
- {
- $nameclient = DB::table('clients')->select('client_code', 'client_name')->where('client_code', '=', $id)->get();
- return response()->json($nameclient);
- }
- public function get_service_category(Request $request)
- {
- $client = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_all_service']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $client->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['client_name' => $request["vclient"]]
- ]);
- $dtclient = json_decode($response->getBody()->getContents(), true)['data'];
- return json_encode($dtclient);
- }
- public function serviceCategoryAutocomplete(Request $request)
- {
- $scategory = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/getservicecategory/']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $scategory->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['service_category' => $request["sc_name"]]
- ]);
- return json_decode($response->getBody()->getContents(), true)['data'];
- }
- public function get_data_division_2($code)
- {
- $client = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_all_division_2']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $client->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['client_code' => $code]
- ]);
- $dtclient = json_decode($response->getBody()->getContents(), true)['data'];
- return json_encode($dtclient);
- }
- public function get_data_dept_2($code)
- {
- $client = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_all_dept_2']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $client->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['division_code' => $code]
- ]);
- $dtclient = json_decode($response->getBody()->getContents(), true)['data'];
- return json_encode($dtclient);
- }
- public function ServiceAutocomplete(Request $request)
- {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/getcustomerautocomplete/']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['client_name' => $request["vclient"]]
- ]);
- $data = json_decode($response->getBody()->getContents(), true)['data'];
- return json_encode($dtclient);
- }
- public function get_data_division_by_id($division_code)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_division_by_id']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['division_code' => $division_code]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_pics_by_id($division_code)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => env('HTTP_URL_CLIENT') . 'get_data_pics_by_id']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['division_code' => $division_code]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_client_by_id($client_code)
- {
- // return $_COOKIE["token"];
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => env('HTTP_URL_CLIENT') . 'get_data_client_by_id']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['client_code' => $client_code]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_dept_by_id($dept_code)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => env('HTTP_URL_CLIENT') . 'get_data_dept_by_id']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['dept_code' => $dept_code]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- }
- public function check_ppn($vat, $sub_total)
- {
- if ($vat == 'exclude') {
- return $ppn = $sub_total * 0.11;
- } else {
- return $ppn = 0;
- } // End PPN
- }
- public function check_materai($sub_total, $ppn)
- {
- $math = $sub_total + $ppn;
- if ($math < 5000000) {
- return $materai = 0;
- }else if ($math >= 5000000) {
- return $materai = 10000;
- } // end if
- }
- public function check_materai_old($sub_total, $ppn)
- {
- $math = $sub_total + $ppn;
- if ($math < 250000) {
- return $materai = 0;
- } else if ($math < 1000000) {
- return $materai = 3000;
- } else if ($math >= 1000000) {
- return $materai = 6000;
- } // end if
- } // end function
- public function check_pph23($client_code, $sub_total)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => env('HTTP_URL_CLIENT') . 'get_pph23']); // Get Template Invoice from Account Management, Parameter id Template Invoice
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['client_code' => $client_code]
- ]);
- $incomeTaxData = json_decode($response->getBody()->getContents(), true)['data'][0];
- $incomeTax = $incomeTaxData['income_tax_23'];
- } catch (Exception $e) {
- // Log::error("Function Error",["name"=>__FUNCTION__, "message"=>$e->getMessage()]);
- $incomeTax = 0;
- }
- if ($incomeTax !== null) {
- return $sub_total * ($incomeTaxData['income_tax_23'] / 100);
- } else {
- return 0;
- }
- }// end f
- public function get_revenue_coa($service_code)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_service_category_2']); // Get Template Invoice from Account Management, Parameter id Template Invoice
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['service_code ' => $service_code]
- ]);
- return json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return '';
- }
- } // end f
- public function get_data_dept_by_name($dept_name)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_dept_by_name_2']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['dept_name' => $dept_name]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_division_by_name($division_name)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_division_by_name']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['division_name' => $division_name]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_division_by_name_and_client_code($division_name, $client_code)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => env('HTTP_URL_CLIENT') . 'get_data_division_by_name_and_client_code']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['division_name' => $division_name, 'client_code' => $client_code]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_client_by_name($client_name)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_client_by_name']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['client_name' => $client_name]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_service_category_by_name($service_category_name)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_service_category_by_name']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['service_category_name' => $service_category_name]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_dept_by_client_code_division_code($division_code, $client_code)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_dept_by_client_code']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['division_code' => $division_code, 'client_code' => $client_code]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_price($client_code, $provider_code, $service_code)
- {
- // return $service_code;
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/check_vat']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['client_code' => $client_code, 'provider_code' => $provider_code, 'service_code' => $service_code]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_service_sms($service_name)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_service_sms']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['service_name' => $service_name]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_pic_collection($division_code)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => 'https://backoffice.sprintasia.net:82/sprint-sysadmin/public/api-master/get_data_pic_collection']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['division_code' => $division_code]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function get_data_pic_pph23($division_code)
- {
- try {
- $Uri = new \GuzzleHttp\Client(['base_uri' => env('HTTP_URL_CLIENT') . 'get_data_pic_pph23']);
- $headers = [
- 'Authorization' => 'Bearer ' . $_COOKIE["token"],
- 'Accept' => 'application/json',
- ];
- $response = $Uri->request('GET', '', [
- 'headers' => $headers,
- 'query' => ['division_code' => $division_code]
- ]);
- return $data = json_decode($response->getBody()->getContents(), true)['data'][0];
- } catch (Exception $e) {
- return [];
- }
- } // end f
- public function zek_view(Request $request)
- {
- if (empty($_COOKIE["token"])) {
- return redirect("https://backoffice.sprintasia.net:82/sprint-sysadmin/public/login");
- } else {
- $title = "Invoice";
- $gen = "Cek Paydate Invoice";
- $content = "Cek Paydate Invoice";
- $data = DB::table('db_sprint_ar.manual_invoice AS m')
- ->join('db_sprint_ar.invoice AS i', 'i.id_manual', 'm.id')
- ->select('i.*', 'm.*', 'i.created_at AS tanggal')
- ->get();
- $dtdepts = DB::table('invoice')->select('dept_code', 'dept_name')->get();
- $dtclients = DB::table('invoice')->select('client_code', 'client_name')->get();
- $dtdivs = DB::table('invoice')->select('division_code', 'division_name')->get();
- $dtservs = ServiceCategory::select('service_category_code', 'service_category_name')->get();
- // return view('manual_invoice.index', compact('title','content','gen','data','dtdepts', 'dtclients', 'dtdivs', 'dtservs'));
- return view('manual_invoice.index_paydate', compact('title', 'content', 'gen', 'data', 'dtdepts', 'dtclients', 'dtdivs', 'dtservs'));
- }
- }
- public function cek_paydate(Request $request)
- {
- try {
- $File = $request->file('file_cek'); //file_upload
- $nameFileUpload = $File->getClientOriginalName();
- $nameFile = explode("_", $nameFileUpload);
- $dataFile = Excel::selectSheetsByIndex(0)->load($File, function ($reader) {
- $reader->setHeaderRow(0);
- $reader->select(['invoice_no', 'total','paid_date'])->get();
- })->get();
- $extension = $File->getClientOriginalExtension();
- $size = $File->getSize();
- $path = $File->getRealPath();
- return $dataFile;
- if ($extension == "xlsx" || $extension == "xls") {
- // $datas = Excel::load($path)->get(); //load all of the data in sheet excel file
- $index = 0;
- // return $datas;
- if ($dataFile->count() != 0) {
- DB::beginTransaction();
- $invXls = array();
- foreach ($dataFile as $data) {
- try {
- $invoice_no = $data['invoice_no'];
- $total = $data['total'];
- $pay_date = $data['paid_date'];
- // return $invoice_no;
- $cekInv = DB::table("db_sprint_ar.invoice")->where('no_inv', $invoice_no)->get();
- // return $cekInv;
- // return count($cekInv);
- if(count($cekInv) == 0){
- continue;
- // return "null";
- }
- DB::table("db_sprint_ar.invoice")->where('no_inv', $invoice_no)->update(["paydate" => $pay_date]);
- $invXls[] = array(
- "no_inv" => $invoice_no,
- "paydate" => $pay_date,
- );
- } catch (Exception $e) {
- return redirect()->back()->with('alert', 'Please Check Your Data Again. File Cannot be Executed.');
- }
- }
- }
- // return $invXls;
- DB::commit();
- return redirect()->back()->with('alert', 'Paydate Success.');
- } else {
- return redirect()->back()->with('alert', 'Something Wrong. Excel Only.');
- }
- } catch (Exception $e) {
- DB::rollback();
- }
- }
- public function updateInvoice(Request $request)
- {
- $title = "Invoice";
- $gen = "Manual Invoice";
- $content = "Manual Invoice";
- return view('manual_invoice.update_invoice', compact('title', 'content', 'gen'));//, 'data', 'dtdepts', 'dtclients', 'dtdivs', 'dtservs'));
- } // end f
- public function updateInvoiceNum_real(Request $request)
- {
- try{
- $jlh_invoice = DB::select( "SELECT count(id) from invoice");
- $inv = DB::select( "SELECT * from invoice");
- // return $inv;
- $tes = [];
- for($c = 0; $c < count($inv); $c++){
- $dClient = $this->get_data_client_by_name($inv[$c]->client_name);
- if($dClient == null || $dClient == '' || $dClient == ""){
- // $client_name = $dClient['client_name'];
- $lmbg = null;
- $invoice_rule = null;
- $max_amount = null;
- }else{
- $lmbg = $dClient['lmbnegara'];
- $invoice_rule = $dClient['invoice_rule'];
- $max_amount = $dClient['max_amount'];
- }
- $idInv = $inv[$c]->id;
- $sub_total = $inv[$c]->sub_total;
- $ppn = $inv[$c]->ppn;
- $total = $inv[$c]->total;
- $materai = $inv[$c]->materai;
- $pph23 = $inv[$c]->pph23;
- $amount_invoice_rule = $sub_total + $ppn;
- $serialize_datas = json_decode($inv[$c]->serialize_data);
- if($serialize_datas == null){
- $bhp = 0;
- $uso = 0;
- }else{
- $total = $serialize_datas->detail->total;
- if(array_key_exists('bhp', $total)){
- $bhp = $total->bhp;
- $uso = $total->uso;
- }else{
- $bhp = 0;
- $uso = 0;
- }
- }
- // return $uso;
- if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 1 && $ppn != 0 ){ //exclude
- if($sub_total > $max_amount){
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = $sub_total * 0.1;
- $new_ppn_real = 0; //ke sprint
- }else{
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = $sub_total * 0.1;
- $new_ppn_real = floor($sub_total_real * 0.1);
- }
- }else if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 1 && $ppn == 0 ){ //include
- if($sub_total > $max_amount){
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0; //$sub_total * 0.1;
- $new_ppn_real = 0;//$sub_total * 0.1;
- }else{
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0;
- $new_ppn_real = floor($sub_total_real * 0.1);
- }
- }else if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 2 && $ppn != 0 ){ //exclude
- if($amount_invoice_rule > $max_amount){
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = $sub_total * 0.1;
- $new_ppn_real = 0; //ke sprint
- }else{
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = $sub_total * 0.1;
- $new_ppn_real = floor($sub_total_real * 0.1);
- }
- }else if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 2 && $ppn == 0 ){ //include
- if($amount_invoice_rule > $max_amount){
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0; //$sub_total * 0.1;
- $new_ppn_real = 0; //$sub_total * 0.1;
- }else{
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0;
- $new_ppn_real = floor($sub_total_real * 0.1);
- }
- }else if(($lmbg == "no" || $lmbg == null) && $ppn != 0 ){ //exclude
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total); /// 1.1;
- $new_ppn_now = $sub_total * 0.1;
- $new_ppn_real = floor($sub_total_real * 0.1);
- }else if(($lmbg == "no" || $lmbg == null) && $ppn == 0 ){ //include
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0; //$sub_total * 0.1;
- $new_ppn_real = floor($sub_total_real * 0.1);
- } //
- $Total_now = $sub_total_now + $new_ppn_now + $materai - $pph23 - $bhp - $uso;
- $Total_real = round($sub_total_real + $new_ppn_real + $materai - $pph23 - $bhp - $uso); //subtotal real dan total real bulat atas, ppn real bulat ke bawah
- // return $Total_real;
- \DB::table('invoice')->where('id', $idInv)
- ->update(['total_real' => $Total_real, 'sub_total_real' => $sub_total_real, 'ppn_real' => $new_ppn_real ]);
- }
- return "suksses";
- } catch (Exception $e) {
- return ["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- }
- } // end f
- public function updateInvoiceNum(Request $request)
- {
- try{
- //$jlh_invoice = DB::select( "SELECT * FROM invoice WHERE client_name LIKE '%PT. Bank Rakyat Indonesia,Tbk. (BRI)%' AND created_at LIKE '%2020-11-04%' AND sub_total_real IS NULL");
- //$inv = DB::select("SELECT * FROM invoice WHERE client_name LIKE '%PT. Bank Rakyat Indonesia,Tbk. (BRI)%' AND created_at LIKE '%2020-11-04%' AND sub_total_real IS NULL");
- //$inv = DB::select("SELECT count(*) FROM invoice WHERE sub_total_real IS NULL AND no_inv IS NOT NULL");
- $inv = DB::select("SELECT * FROM invoice WHERE sub_total_real IS NULL AND status = 2");
- //return $inv;
- $tes = [];
- for($c = 0; $c < count($inv); $c++){
- $dClient = $this->get_data_client_by_name($inv[$c]->client_name);
- if($dClient == null || $dClient == '' || $dClient == ""){
- // $client_name = $dClient['client_name'];
- $lmbg = null;
- $invoice_rule = null;
- $max_amount = null;
- }else{
- $lmbg = $dClient['lmbnegara'];
- $invoice_rule = $dClient['invoice_rule'];
- $max_amount = $dClient['max_amount'];
- }
- $idInv = $inv[$c]->id;
- $sub_total = $inv[$c]->sub_total;
- $ppn = $inv[$c]->ppn;
- $total = $inv[$c]->total;
- $materai = $inv[$c]->materai;
- $pph23 = $inv[$c]->pph23;
- $amount_invoice_rule = $sub_total + $ppn;
- $serialize_datas = json_decode($inv[$c]->serialize_data);
- if($serialize_datas == null){
- $bhp = 0;
- $uso = 0;
- }else{
- $total = $serialize_datas->detail->total;
- if(array_key_exists('bhp', $total)){
- $bhp = $total->bhp;
- $uso = $total->uso;
- }else{
- $bhp = 0;
- $uso = 0;
- }
- }
- // return $uso;
- if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 1 && $ppn != 0 ){ //exclude
- if($sub_total > $max_amount){
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = $sub_total * 0.11;
- $new_ppn_real = 0; //ke sprint
- }else{
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = $sub_total * 0.11;
- $new_ppn_real = floor($sub_total_real * 0.11);
- }
- }else if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 1 && $ppn == 0 ){ //include
- if($sub_total > $max_amount){
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0; //$sub_total * 0.1;
- $new_ppn_real = 0;//$sub_total * 0.1;
- }else{
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0;
- $new_ppn_real = floor($sub_total_real * 0.11);
- }
- }else if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 2 && $ppn != 0 ){ //exclude
- if($amount_invoice_rule > $max_amount){
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = $sub_total * 0.11;
- $new_ppn_real = 0; //ke sprint
- }else{
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total);
- $new_ppn_now = $sub_total * 0.11;
- $new_ppn_real = floor($sub_total_real * 0.11);
- }
- }else if(($lmbg == "yes" || $lmbg == "Yes" ) && $invoice_rule == 2 && $ppn == 0 ){ //include
- if($amount_invoice_rule > $max_amount){
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0; //$sub_total * 0.1;
- $new_ppn_real = 0; //$sub_total * 0.1;
- }else{
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0;
- $new_ppn_real = floor($sub_total_real * 0.11);
- }
- }else if(($lmbg == "no" || $lmbg == null) && $ppn != 0 ){ //exclude
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total); /// 1.1;
- $new_ppn_now = $sub_total * 0.1;
- $new_ppn_real = floor($sub_total_real * 0.11);
- }else if(($lmbg == "no" || $lmbg == null) && $ppn == 0 ){ //include
- $sub_total_now = $sub_total;
- $sub_total_real = ceil($sub_total / 1.1);
- $new_ppn_now = 0; //$sub_total * 0.1;
- $new_ppn_real = floor($sub_total_real * 0.11);
- } //
- $Total_now = $sub_total_now + $new_ppn_now + $materai - $pph23 - $bhp - $uso;
- $Total_real = round($sub_total_real + $new_ppn_real + $materai - $pph23 - $bhp - $uso); //subtotal real dan total real bulat atas, ppn real bulat ke bawah
- $now = \Carbon\Carbon::now(); //
- // return $Total_real;
- \DB::table('invoice')->where('id', $idInv)
- ->update(['total_real' => $Total_real, 'sub_total_real' => $sub_total_real, 'ppn_real' => $new_ppn_real, 'updated_at' => $now ]);
- }
- return "suksses";
- } catch (Exception $e) {
- return ["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- }
- } // end f
- public function updateInv(Request $request)
- {
- try{
- // $jlh_invoice = DB::select( "SELECT count(id) from invoice");
- $inv = DB::select( "SELECT * FROM invoice");
- // return $inv;
- for($c = 0; $c < count($inv); $c++){
- $idInv = $inv[$c]->id;
- $no_inv = $inv[$c]->no_inv;
- //return $no_inv;
- $arr_no_inv = explode("/", $no_inv);
- $c_noInv = count($arr_no_inv);
- //return count($arr_no_inv);
- if($no_inv != null || $no_inv != '' || $no_inv != ""){
- if( $c_noInv == 3){
- $no_inv_ = $no_inv;
- $no_inv_real = $no_inv;
- }else if($c_noInv == 4){
- $no_inv_ = $no_inv;
- $no_inv_real = $arr_no_inv[0] . "/" . $arr_no_inv[1] . "/" . $arr_no_inv[3];
- }
- \DB::table('invoice')->where('id', $idInv)
- ->update(['no_inv_real' => $no_inv_real]);
- }
- }
- return "Done";
- } catch (Exception $e) {
- return ["code" => "_ERR_SYSTM", "error" => $e->getMessage()];
- }
- }
- }
Editor
You can edit this paste and save as new: