[php] UploadManualInvoice.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.
- public function upload(Request $request, ManualInvoiceController $manualInvoiceController)
- {
- 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 = $manualInvoiceController->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 = '';
- // batas atas edit 26 april 2024 trace error upload manual invoice
- //$test_datas = $datas->transform(function ($value, $key) {
- /*
- echo $value;
- $rowTest = $value->toArray();
- $newArray = [];
- foreach ($rowTest as $name => $rt) {
- if (!is_string($rt)) {
- continue;
- }
- $newArray[$name] = $rt;
- }
- $value->setItems($newArray);
- return $value;
- */
- //return $value->reject(function ($value1, $key1) {
- //return !is_string($key1);
- //});
- //});
- //$test_datas2 = $datas->getHeading();
- //$test_datas3 = [];
- /*
- foreach ($test_datas2 as $vals) {
- if ($vals == '') {
- continue;
- }
- $test_datas3[] = $vals;
- }
- $datas->setHeading($test_datas3);
- //dd($datas);
- // batas bawah edit 26 april 2024 trace error upload manual invoice
- */
- //// Menggabungkan & mengklasifikasikan dengan values Division
- foreach ($datas as $vals)
- {
- $vals_div = $vals['divisi'];
- if ( in_array($vals_div, $rowsDiv) ) {
- $checkDiv = array_keys($rowsDiv, $vals_div);
- $brsDiv = $checkDiv[0];
- $countdDatasDivisi = count($datasDivisi[$brsDiv]);
- $datasDivisi[$brsDiv][$countdDatasDivisi] = $vals ;
- }
- else {
- array_push($rowsDiv,$vals_div);
- $checkDiv = array_keys($rowsDiv, $vals_div);
- $brsDiv = $checkDiv[0];
- $datasDivisi[$brsDiv][] = $vals ;
- }
- }
- $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;
- $cDataDivisi = count($datasDivisi[$ij]);
- $arrClient = $manualInvoiceController->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 < $cDataDivisi ; $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;
- }
- for ($ik = 3; $ik < $countDatasHeader ; $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
- // For generate itemdesc
- for ($ih = 0; $ih < $cDataDivisi ; $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;
- }
- for ($ik = 3; $ik < $countDatasHeader ; $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 `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]
- ];
- }
- $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);
- echo "division_name";
- // dd($division_name);
- $data_div = $manualInvoiceController->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 = $manualInvoiceController->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 = $manualInvoiceController->get_data_pics_by_id($division_code);
- if ($data_pic == null || $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 = $manualInvoiceController->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 = $manualInvoiceController->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 = $manualInvoiceController->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 = $manualInvoiceController->check_materai($sub_total_now, $new_ppn_now);
- else if ($materai_client == 0) $new_materai = 0;
- $pph23 = $manualInvoiceController->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
- );
- // return $invXls;
- }
- // END Men Serialize Data
- // return $invXls;
- if (!empty($invXls)) {
- DB::table('db_sprint_ar.invoice')->insert($invXls);
- $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');
- }
- }
Editor
You can edit this paste and save as new:
File Description
- UploadManualInvoice.php
- Paste Code
- 10 May-2024
- 29.25 Kb
You can Share it: