mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 04:14:04 +00:00
Merge branch 'Lingges/fixpoFormat' into 'master'
Lingges/fixpo format See merge request CIEFWorldwideSdnBhd/exchange!142
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace App\Classes\Service;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Base64Uploader
|
||||
{
|
||||
public function execute(string $base64Image, string $path) {
|
||||
|
||||
if($base64Image !== ''){
|
||||
|
||||
$type = $this->getFileType($base64Image);
|
||||
|
||||
$extension = $this->getExtension($base64Image, $type);
|
||||
|
||||
$uniqueName = uniqid('img_').time();
|
||||
|
||||
$imagePath = $path.'/'.$uniqueName.'.'.$extension;
|
||||
|
||||
$encodedExtension = $extension;
|
||||
|
||||
if($extension === 'xlsx'){
|
||||
$encodedExtension = 'vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
||||
}
|
||||
$data = base64_decode(str_replace(' ', '+', str_replace('data:'.$type.'/'.$encodedExtension.';base64,', '', $base64Image)));
|
||||
|
||||
Storage::disk('public')->put($imagePath, $data);
|
||||
|
||||
return $uniqueName.'.'.$extension;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function getFileType(string $base64Image){
|
||||
return explode('/', explode(':', substr($base64Image, 0, strpos($base64Image, ';')))[1])[0];
|
||||
}
|
||||
|
||||
private function getExtension(string $base64Image, string $type) {
|
||||
$extension = explode('/', explode(':', substr($base64Image, 0, strpos($base64Image, ';')))[1])[1];
|
||||
|
||||
if($extension === 'vnd.openxmlformats-officedocument.spreadsheetml.sheet'){
|
||||
return 'xlsx';
|
||||
}
|
||||
|
||||
return $extension;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\PurchaseOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Classes\Service\Base64Uploader;
|
||||
use App\Booking;
|
||||
use App\Rate;
|
||||
use App\UserBankSlip;
|
||||
@@ -608,26 +609,9 @@ class BookingController extends Controller
|
||||
if($bankslip_file = $request->input('slip_image'))
|
||||
|
||||
{
|
||||
$ext = explode('/', explode(':', substr($bankslip_file, 0, strpos($bankslip_file, ';')))[1])[1];
|
||||
$img = str_replace('data:image/'.$ext.';base64,', '', $bankslip_file);
|
||||
$img = str_replace(' ', '+', $img);
|
||||
$data = base64_decode($img);
|
||||
$file_name = 'bank_slip_' . md5(time()).'.'.$ext;
|
||||
if($bankslip_file!=""){
|
||||
// storing image in storage/app/public Folder
|
||||
$upload_path = \Storage::disk('public')->put('user_bankslip'.'/'.$file_name, $data);
|
||||
}
|
||||
// /* End Validation */
|
||||
// // $filename = $bankslip_file->getClientOriginalName();
|
||||
//
|
||||
|
||||
// $unique_name = 'bank_slip_' . md5(time()); // probably not a good idea
|
||||
// $unique_image_path = $unique_name. '.' .'jpg';
|
||||
// $image_parts = explode(";base64,", $bankslip_file);
|
||||
// $upload_path = \Storage::disk('public')->put('user_bankslip'.'/'.$unique_image_path,base64_decode(base64_decode($image_parts[1])));
|
||||
// // $upload_path = Storage::disk('public')->putFileAs(
|
||||
// // 'user_bankslip', base64_decode($image), $unique_image_path
|
||||
// // );
|
||||
$upload_path = (new Base64Uploader())->execute($bankslip_file, 'user_bankslip');
|
||||
|
||||
if($upload_path){
|
||||
$user_bankslip = $booking->userBankSlip()->first();
|
||||
|
||||
@@ -636,7 +620,7 @@ class BookingController extends Controller
|
||||
$user_bankslip = new UserBankSlip;
|
||||
}
|
||||
$user_bankslip->booking_id = $booking->id;
|
||||
$user_bankslip->bankslip_path = 'user_bankslip'.'/'.$file_name;
|
||||
$user_bankslip->bankslip_path = 'user_bankslip'.'/'.$upload_path;
|
||||
$user_bankslip->transfer_amount = null;
|
||||
$user_bankslip->save();
|
||||
|
||||
@@ -678,7 +662,7 @@ class BookingController extends Controller
|
||||
return response()->json(["success"=>true],200);
|
||||
}
|
||||
|
||||
public function uploadPurchaseOrder(Request $request, $id)
|
||||
private function uploadPurchaseOrder(Request $request, $id)
|
||||
{
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
|
||||
@@ -688,44 +672,36 @@ class BookingController extends Controller
|
||||
return response()->json(['message'=>'Access denied'], 403);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'file' => 'mimes:jpg,jpeg,bmp,png,xls,xlsx,doc,docx,pdf'
|
||||
]);
|
||||
// $validator = Validator::make($request->all(), [
|
||||
// 'file' => 'mimes:jpg,jpeg,bmp,png,xls,xlsx,doc,docx,pdf'
|
||||
// ]);
|
||||
|
||||
if($validator->fails())
|
||||
{
|
||||
return response()->json(['message'=>'Incorrect format'],400);
|
||||
}
|
||||
// if($validator->fails())
|
||||
// {
|
||||
// return response()->json(['message'=>'Incorrect format'],400);
|
||||
// }
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'file' => 'max:10000'
|
||||
]);
|
||||
// $validator = Validator::make($request->all(), [
|
||||
// 'file' => 'max:10000'
|
||||
// ]);
|
||||
|
||||
if($validator->fails())
|
||||
{
|
||||
return response()->json(['message'=>'File too large, upload files up to 3 MB'], 400);
|
||||
}
|
||||
// if($validator->fails())
|
||||
// {
|
||||
// return response()->json(['message'=>'File too large, upload files up to 3 MB'], 400);
|
||||
// }
|
||||
|
||||
if(!$user_input_file = $request->file('file'))
|
||||
if(!$user_input_file = $request->input('images'))
|
||||
{
|
||||
return response()->json(['message' => 'No file detected'], 404);
|
||||
}
|
||||
/* End Validation */
|
||||
|
||||
$filename = $user_input_file->getClientOriginalName();
|
||||
$ext = $user_input_file->getClientOriginalExtension();
|
||||
|
||||
$input['file'] = $filename;
|
||||
$unique_name = 'purchase_order_' . md5($filename. time());
|
||||
$unique_image_path = $unique_name. '.' .$ext;
|
||||
$upload_path = Storage::disk('public')->putFileAs(
|
||||
'purchase_order',/*folder name*/ $user_input_file, $unique_image_path, 'public'
|
||||
);
|
||||
|
||||
$user_po = new PurchaseOrder;
|
||||
$user_po->image_path = $upload_path;
|
||||
$user_po->booking_id = $booking->id;
|
||||
$user_po->save();
|
||||
foreach($request->input('images') as $file){
|
||||
$filename = (new Base64Uploader())->execute($file, 'purchase_order');
|
||||
$user_po = new PurchaseOrder;
|
||||
$user_po->image_path = 'purchase_order/'.$filename;
|
||||
$user_po->booking_id = $booking->id;
|
||||
$user_po->save();
|
||||
}
|
||||
|
||||
$booking->status = 6;
|
||||
// $booking->admin_status = 7;
|
||||
@@ -1011,7 +987,8 @@ class BookingController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function confirmPurchaseOrder($id){
|
||||
public function confirmPurchaseOrder($id, Request $request){
|
||||
$this->uploadPurchaseOrder($request, $id);
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
|
||||
$purchase_order = $booking->purchaseOrder()->first();
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
<div class="col-md-7">
|
||||
<input v-model="form.marking" :class="{ 'is-invalid': form.errors.has('marking') }" class="form-control" type="text" name="marking">
|
||||
<has-error :form="form" field="marking"/>
|
||||
<ul class="text-danger list-unstyled" :class="[{hide: !errors.marking}]">
|
||||
<li v-for="(error, index) in errors.marking" v-bind:key="index">{{error}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -20,6 +23,9 @@
|
||||
<el-input v-model="form.email" type="email" name="email" placeholder="Email">
|
||||
</el-input>
|
||||
<has-error :form="form" field="email"/>
|
||||
<ul class="text-danger list-unstyled" :class="[{hide: !errors.email}]">
|
||||
<li v-for="(error, index) in errors.email" v-bind:key="index">{{error}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -38,6 +44,9 @@
|
||||
</template>
|
||||
</el-input>
|
||||
<has-error :form="form" field="password"/>
|
||||
<ul class="text-danger list-unstyled" :class="[{hide: !errors.password}]">
|
||||
<li v-for="(error, index) in errors.password" v-bind:key="index">{{error}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -101,6 +110,11 @@ export default {
|
||||
password: '',
|
||||
password_confirmation: ''
|
||||
}),
|
||||
errors: {
|
||||
marking: '',
|
||||
email: '',
|
||||
password: ''
|
||||
},
|
||||
email : '',
|
||||
password_visible : false,
|
||||
password_confirmation_visible : false
|
||||
@@ -121,13 +135,11 @@ export default {
|
||||
})
|
||||
})
|
||||
.catch( (error) => {
|
||||
console.log(error)
|
||||
this.$message({
|
||||
message: error.response.data.message,
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
)
|
||||
this.errors['marking'] = error.response.data.errors.marking;
|
||||
this.errors['email'] = error.response.data.errors.email;
|
||||
this.errors['password'] = error.response.data.errors.password;
|
||||
|
||||
})
|
||||
|
||||
|
||||
await this.form.post('/api/login')
|
||||
@@ -136,11 +148,7 @@ export default {
|
||||
token = response.data.token
|
||||
})
|
||||
.catch( (error) => {
|
||||
console.log(error)
|
||||
this.$message({
|
||||
message: error.response.data.message,
|
||||
type: 'error'
|
||||
})
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<!-- upload image -->
|
||||
<div class="card-body">
|
||||
|
||||
<el-upload :action="'/api/booking/' + booking_id + '/upload-po'" :on-exceed="handleExceed" :on-preview="handlePreview" :on-remove="handleRemove"
|
||||
<el-upload :action="'/api/booking/' + booking_id + '/upload-po'" :auto-upload="false" :on-change="beforeFileUpload" :on-exceed="handleExceed" :on-preview="handlePreview" :on-remove="handleRemove"
|
||||
:on-error="uploadError" class="upload-demo uploadAreaOne" accept=".jpeg, .jpg, .png, .bmp, .doc, .docx, .xls, .xlsx, .pdf"
|
||||
drag multiple>
|
||||
<i class="el-icon-upload" />
|
||||
@@ -187,6 +187,7 @@
|
||||
import ProgressTrack from '~/components/ProgressTrack'
|
||||
import X2ProgressTrack from '~/components/X2ProgressTrack'
|
||||
import axios from 'axios'
|
||||
import ImageCompressor from 'image-compressor.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@@ -200,6 +201,7 @@ export default {
|
||||
status: 5,
|
||||
term: null
|
||||
},
|
||||
purchaseOrderArray: [],
|
||||
loading_btn: false,
|
||||
booking_details: {
|
||||
id: null,
|
||||
@@ -236,8 +238,9 @@ export default {
|
||||
methods: {
|
||||
uploadPo() {
|
||||
this.loading_btn = true
|
||||
console.log(this.purchaseOrderArray);
|
||||
axios
|
||||
.post('/api/booking/' + this.$route.params.id + '/confirm-po')
|
||||
.post('/api/booking/' + this.$route.params.id + '/confirm-po', { images: this.purchaseOrderArray})
|
||||
.then((response) => {
|
||||
this.$message({
|
||||
showClose: true,
|
||||
@@ -248,7 +251,7 @@ export default {
|
||||
this.$router.push({
|
||||
name: 'home'
|
||||
})
|
||||
this.loading_btn = false
|
||||
this.loading_btn = false
|
||||
}).catch((error) => {
|
||||
this.$message({
|
||||
showClose: true,
|
||||
@@ -259,6 +262,39 @@ export default {
|
||||
this.loading_btn = false
|
||||
})
|
||||
},
|
||||
beforeFileUpload(file, fileList) {
|
||||
this.purchaseOrderArray = [];
|
||||
var vm = this;
|
||||
for (var i in fileList) {
|
||||
var filetype = fileList[i].raw.type.split("/")[0];
|
||||
if(filetype === 'image'){
|
||||
new ImageCompressor(fileList[i].raw, {
|
||||
quality: .4,
|
||||
convertSize: 1500000,
|
||||
success(result) {
|
||||
vm.convertFile(result)
|
||||
},
|
||||
error(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.convertFile(fileList[i].raw)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
convertFile(file){
|
||||
var vm = this,
|
||||
reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onloadend = function() {
|
||||
vm.purchaseOrderArray.push(reader.result);
|
||||
console.log(vm.purchaseOrderArray);
|
||||
}
|
||||
},
|
||||
handleRemove(file, fileList) {
|
||||
console.log(file, fileList)
|
||||
// Should send some reqeust to controller to delete the file
|
||||
|
||||
@@ -154,16 +154,16 @@
|
||||
<el-form-item prop="account_name">
|
||||
<el-input v-model="bookingForm.account_name" placeholder="China Beneficiary Name" style="width: 80%" required="true" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="account_num">
|
||||
<el-input v-model="bookingForm.account_num" type="text" placeholder="Account Number" style="width: 80%"/>
|
||||
</el-form-item>
|
||||
<el-form-item prop="bank_name">
|
||||
<el-input v-model="bookingForm.bank_name" type="text" placeholder="Bank Name" style="width: 80%" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="bank_branch">
|
||||
<el-input v-model="bookingForm.bank_branch" type="text" placeholder="Branch / 分行/支行" style="width: 80%" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="account_num">
|
||||
<el-input v-model="bookingForm.account_num" type="text" placeholder="Account Number" style="width: 80%"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<!-- <el-button @click="dialogFormVisible = false">Cancel</el-button> -->
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -103,26 +103,6 @@ class BookingTest extends TestCase
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function testuploadPO()
|
||||
{
|
||||
Storage::fake('file');
|
||||
$size_in_kb = 3072; // 3072KB = 3MB
|
||||
$image_path = UploadedFile::fake()->image('comp.jpg')->size($size_in_kb);
|
||||
|
||||
$response =
|
||||
$this->actingAs($this->user)
|
||||
->json('POST', '/api/booking/' . $this->booking->id . '/upload-po', [
|
||||
'file' => $image_path,
|
||||
'amount' => '12345'
|
||||
]);
|
||||
|
||||
if(!file_exists($image_path) || $size_in_kb > 3072){
|
||||
$response->assertStatus(400);
|
||||
}
|
||||
else{
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
public function testCancel()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user