upload purchase order

This commit is contained in:
Nazri
2018-05-28 17:24:13 +08:00
parent 5c1a4d28c4
commit 4210cdc19d
9 changed files with 118 additions and 13 deletions
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\PurchaseOrder;
use Illuminate\Http\Request;
use App\Booking;
use App\Rate;
@@ -157,6 +158,31 @@ class BookingController extends Controller
$post->save();;
}
public function uploadPurchaseOrder(Request $request)
{
// Handle File Upload
if($request->hasFile('image_location')){
// Get filename with the extension
$filenameWithExt = $request->file('image_location')->getClientOriginalName();
// Get just filename
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
// Get just ext
$extension = $request->file('image_location')->getClientOriginalExtension();
// Filename to store
$fileNameToStore= $filename.'_'.time().'.'.$extension;
// Upload Image
$path = $request->file('image_location')->storeAs('public/userPurchaseOrder', $fileNameToStore);
} else {
$fileNameToStore = 'hello.jpg';
}
// Create Post
$post = new PurchaseOrder;
$post->amount = $request->input('amount');
$post->book_id = $request->input('book_id');
$post->image_location = $fileNameToStore;
$post->save();;
}
/**
* Display the specified resource.
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class PurchaseOrder extends Model
{
protected $fillable = ['image_location','amount','book_id'];
}
@@ -0,0 +1,9 @@
<?php
use Faker\Generator as Faker;
$factory->define(App\PurchaseOrder::class, function (Faker $faker) {
return [
//
];
});
@@ -15,11 +15,11 @@ class CreateUserBankSlipsTable extends Migration
{
Schema::create('user_bank_slips', function (Blueprint $table) {
$table->increments('id');
$table->string('bank_slip_type');
$table->string('bankslip_url');
$table->double('transfer_amount');
$table->string('cust_marking');
$table->boolean('is_approve');
$table->string('bank_slip_type')->nullable();
$table->string('bankslip_url')->nullable();
$table->double('transfer_amount')->nullable();
$table->string('cust_marking')->nullable();
$table->boolean('is_approve')->nullable();
$table->integer('book_id')->unsigned();
$table->foreign('book_id')->references('id')->on('bookings');
@@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePurchaseOrdersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('purchase_orders', function (Blueprint $table) {
$table->increments('id');
$table->string('image_location');
$table->double('amount');
$table->integer('book_id')->unsigned();
$table->foreign('book_id')->references('id')->on('bookings');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('purchase_orders');
}
}
+1
View File
@@ -82,3 +82,4 @@ Route::delete('setting-supplier/{supplier}', 'SettingSupplierController@delete')
Route::post('upload-china-bankslip', 'ChinaBankSlipController@store');
Route::post('upload-bs', 'BookingController@uploadbankslip');
Route::post('upload-po', 'BookingController@uploadPurchaseOrder');
+30 -8
View File
@@ -6,6 +6,9 @@ use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Database\Seeder;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\UploadedFile;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Artisan;
use App\User;
@@ -22,17 +25,17 @@ class BookingTest extends TestCase
public function testPost()
{
$response =
$response =
$this->actingAs($this->user)
->postJson('/api/booking/', [
'account_name' => 'johnny',
'account_num' => '1234567',
'bank_name' => 'myabnak',
'bank_branch' => 'banking',
'company_name' => 'besaras',
'company_address' => 'californina',
'bank_address' => 'cyber',
'swift_code' => '123wert',
'account_num' => '1234567',
'bank_name' => 'myabnak',
'bank_branch' => 'banking',
'company_name' => 'besaras',
'company_address' => 'californina',
'bank_address' => 'cyber',
'swift_code' => '123wert',
'cnap' => '2131rew',
'term' => 'x2_cash',
'amount' => '14000'
@@ -40,4 +43,23 @@ class BookingTest extends TestCase
$response->assertStatus(500);
}
public function testImageUpload()
{
Storage::fake('bankslip_url');
$response = $this->json('POST', '/api/upload-bs', [
'bankslip_url' => UploadedFile::fake()->image('comp.jpg'),
'bank_slip_type' => '',
'transfer_amount' => '1000',
'book_id' => '1',
'cust_marking' => '12345',
'is_approve' => '1',
]);
//var_dump($response);
dd($response->getContent());
$response->assertStatus(200);
}
}
+1
View File
@@ -41,6 +41,7 @@ return array(
'App\\Providers\\BroadcastServiceProvider' => $baseDir . '/app/Providers/BroadcastServiceProvider.php',
'App\\Providers\\EventServiceProvider' => $baseDir . '/app/Providers/EventServiceProvider.php',
'App\\Providers\\RouteServiceProvider' => $baseDir . '/app/Providers/RouteServiceProvider.php',
'App\\PurchaseOrder' => $baseDir . '/app/PurchaseOrder.php',
'App\\Rate' => $baseDir . '/app/Rate.php',
'App\\Role' => $baseDir . '/app/Role.php',
'App\\SettingBeneficiary' => $baseDir . '/app/SettingBeneficiary.php',
+1
View File
@@ -440,6 +440,7 @@ class ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc
'App\\Providers\\BroadcastServiceProvider' => __DIR__ . '/../..' . '/app/Providers/BroadcastServiceProvider.php',
'App\\Providers\\EventServiceProvider' => __DIR__ . '/../..' . '/app/Providers/EventServiceProvider.php',
'App\\Providers\\RouteServiceProvider' => __DIR__ . '/../..' . '/app/Providers/RouteServiceProvider.php',
'App\\PurchaseOrder' => __DIR__ . '/../..' . '/app/PurchaseOrder.php',
'App\\Rate' => __DIR__ . '/../..' . '/app/Rate.php',
'App\\Role' => __DIR__ . '/../..' . '/app/Role.php',
'App\\SettingBeneficiary' => __DIR__ . '/../..' . '/app/SettingBeneficiary.php',