diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php new file mode 100644 index 00000000..e891fddd --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php @@ -0,0 +1,176 @@ + 'Create Supplier Transactions', + 'message' => 'You have successfully created currency supplier transactions' + ]; + } + + /** @var FetchesPackingList */ + private $fetchesPackingList; + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var PDF */ + private $pdf; + + /** + * CreateSupplierTransactionLogic constructor. + * @param FetchesPackingList $fetchesPackingList + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param CreatesTransaction $createsTransaction + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param PDF $pdf + */ + public function __construct( + FetchesPackingList $fetchesPackingList, + + + + FetchesTransaction $fetchesTransaction, + UpdatesTransactionStatus $updatesTransactionStatus, + CreatesTransaction $createsTransaction, + CreatesDocument $createsDocument, + CreatesFiles $createsFile, + GeneratesTransactionBillNumber $generatesTransactionBillNumber, + PDF $pdf + ) + { + + $this->fetchesPackingList = $fetchesPackingList; + + + + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->createsTransaction = $createsTransaction; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->pdf = $pdf; + } + + public function logic(Request $request) : JsonResponse + { + $packing_list = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]); + + $cbm = $packing_list->packages->sum(function($package) { + return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity); + }); + + dd($packages); + + Transaction::select(DB::raw('sum(jumlah * harga) as total'))->get(); + + + price_per_cbm = base_price + customer_rate + warehouse_rate + state_rate + outstation_rate + +price_cbm = 570 myr + +total cbm * price_cbm = 896.61 + +price_cbm, invoice total + +create transaction invoice +create transaction details + +shipping service (570 per cbm * 1.57 cbm) + + // dd($packing_list); + + + // $rate = $request->input('rate'); + + // $transactions = collect(); + + // foreach($request->input('payments') as $payment){ + + // /** @var Transaction $payment */ + // $payment = $this->fetchesTransaction->execute(['id' => $payment['id']]); + // $this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED); + // $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); + // $object = new TransactionObject($billNumber, TransactionType::BILL, $supplier->id, 1, + // $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, + // $payment->original_amount * (1 / $rate), $payment->original_amount, 1, $payment->original_currency_id, + // $rate, 0, 0, null, ApprovalStatus::APPROVED); + + // $transactions[] = $this->createsTransaction->execute($payment->booking, $object); + // } + + // $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $transactions, 'supplier' => $supplier]); + + // $path = Str::studly($supplier->name).'_'.Carbon::now()->format('Y_m_d_h_s_i').'.pdf'; + + // $object = new DocumentObject( + // DocumentType::CURRENCY_VENDOR_ORDER, + // [chunk_split('data:application/pdf;base64,'.base64_encode($pdf->output()))], + // '', + // ApprovalStatus::COMPLETED, + // 'currency_vendor_order' + // ); + + // /** @var Document $document */ + // $document = $this->createsDocument->execute($supplier, $object); + // $this->createsFile->execute($document, $object); + + return $this->response([]); + } +} diff --git a/app/Classes/ValueObjects/Constants/SegmentConstants.php b/app/Classes/ValueObjects/Constants/SegmentConstants.php index 80e9cb71..88be0247 100644 --- a/app/Classes/ValueObjects/Constants/SegmentConstants.php +++ b/app/Classes/ValueObjects/Constants/SegmentConstants.php @@ -5,19 +5,19 @@ namespace App\Classes\ValueObjects\Constants; class SegmentConstants { - public const STANDARD_SEGMENT = 1; public const CUSTOM_SEGMENT = 2; - public const SYSTEM_PRIMARY_CURRENCY = 'SYSTEM_PRIMARY_CURRENCY'; + public const BASE_PRICE = 'BASE_PRICE'; - public const SUPPLIER_CURRENCIES = 'SUPPLIER_CURRENCIES'; + public const WAREHOUSE_RATE = 'WAREHOUSE_RATE'; - public const PAYMENT_ATTEMPT_DURATION_LIMIT = 'PAYMENT_ATTEMPT_DURATION_LIMIT'; + public const STATE_RATE = 'STATE_RATE'; - public const SERVICE_TYPE = 'SERVICE_TYPE'; + public const CENTER_POSTCODE = 'CENTER_POSTCODE'; - public const CUSTOM_SERVICE_TYPE = 'CUSTOM_SERVICE_TYPE'; + public const OUTSTATION_POSTCODE = 'OUTSTATION_POSTCODE'; + public const CUSTOMER_RATE = 'CUSTOMER_RATE'; } \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/TransactionType.php b/app/Classes/ValueObjects/Constants/TransactionType.php index 8a5f1075..d61589fa 100644 --- a/app/Classes/ValueObjects/Constants/TransactionType.php +++ b/app/Classes/ValueObjects/Constants/TransactionType.php @@ -4,24 +4,26 @@ namespace App\Classes\ValueObjects\Constants; final class TransactionType { - public const PAYMENT_ATTEMPT = 0; + public const SHIPPING_INVOICE = 1; + + // public const PAYMENT_ATTEMPT = 0; - public const PAYMENT = 1; + // public const PAYMENT = 1; - public const INVOICE = 2; + // public const INVOICE = 2; - public const BILL = 3; + // public const BILL = 3; - public const PERFORMA = 4; + // public const PERFORMA = 4; - public const TOP_UP = 5; + // public const TOP_UP = 5; - public const REFUND = 6; + // public const REFUND = 6; - public const PURCHASE_ORDER = 7; + // public const PURCHASE_ORDER = 7; - public const SUPPLIER_DELIVER = 8; + // public const SUPPLIER_DELIVER = 8; - public const SHIPPING_COST = 9; + // public const SHIPPING_COST = 9; } diff --git a/app/Http/Controllers/Transactions/CreateShippingInvoiceTransactionController.php b/app/Http/Controllers/Transactions/CreateShippingInvoiceTransactionController.php new file mode 100644 index 00000000..d9f35b7c --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateShippingInvoiceTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/database/seeders/SegmentConstantsTableSeeder.php b/database/seeders/SegmentConstantsTableSeeder.php index 9eb5d50a..f69660cf 100644 --- a/database/seeders/SegmentConstantsTableSeeder.php +++ b/database/seeders/SegmentConstantsTableSeeder.php @@ -1,54 +1,147 @@ fetchesCurrency = $fetchesCurrency; - $this->fetchesSegment = $fetchesSegment; - $this->createsSegmentConstant = $createsSegmentConstant; - } - - - /** - * Run the database seeds. - * - * @return void - * @throws \App\Classes\Exceptions\MalformedRequestException - */ public function run() { + DB::beginTransaction(); - $object = new ConstantObject('System Primary Currency', - SegmentConstants::SYSTEM_PRIMARY_CURRENCY, - ['id' => $this->fetchesCurrency->execute(['name' => country('my')->getName()])->id]); - - $this->createsSegmentConstant->execute($this->fetchesSegment->execute(['Standard Segment']), $object); - + DB::table('segment_constants')->insert( + [ + 'id' => 1, + 'segment_id' => 1, + 'reference' => SegmentConstants::BASE_PRICE, + 'value' => json_encode([ + 'id'=> 1, + 'price' => 500, + ]), + ], + [ + 'id' => 2, + 'segment_id' => 1, + 'reference' => SegmentConstants::WAREHOUSE_RATE, + 'value' => json_encode([ + 'id'=> 1, + 'config' => [ + [ + 'warehouse_name' => WarehouseReferences::VT_GUANG_ZHOU, + 'rate' => 10 + ], + [ + 'warehouse_name' => WarehouseReferences::YD_GUANG_ZHOU, + 'rate' => 10 + ], + [ + 'warehouse_name' => WarehouseReferences::VT_YIWU, + 'rate' => 10 + ], + ] + + ]), + ], + [ + 'id' => 3, + 'segment_id' => 1, + 'reference' => SegmentConstants::STATE_RATE, + 'value' => json_encode([ + 'id'=> 1, + 'config' => [ + [ + 'status_id' => 1, + 'rate' => 10, + ], + [ + 'status_id' => 2, + 'rate' => 10, + ], + [ + 'status_id' => 3, + 'rate' => 10, + ], + [ + 'status_id' => 4, + 'rate' => 10, + ], + [ + 'status_id' => 5, + 'rate' => 10, + ], + [ + 'status_id' => 6, + 'rate' => 10, + ], + [ + 'status_id' => 7, + 'rate' => 10, + ], + [ + 'status_id' => 8, + 'rate' => 10, + ], + [ + 'status_id' => 9, + 'rate' => 10, + ], + [ + 'status_id' => 10, + 'rate' => 10, + ], + [ + 'status_id' => 11, + 'rate' => 10, + ], + [ + 'status_id' => 12, + 'rate' => 10, + ], + [ + 'status_id' => 13, + 'rate' => 20, + ], + [ + 'status_id' => 14, + 'rate' => 20, + ], + [ + 'status_id' => 15, + 'rate' => 10, + ], + [ + 'status_id' => 16, + 'rate' => 10, + ] + ] + ]), + ], + [ + 'id' => 4, + 'segment_id' => 1, + 'reference' => SegmentConstants::CENTER_POSTCODE, + 'value' => json_encode(['80050','80100','80150','80200','80250','80300','80350','80400','80500','80506','80508','80516','80519','80534','80536','80542','80546','80558','80560','80564','80568','80578','80584','80586','80590','80592','80594','80596','80600','80604','80608','80620','80622','80628','80644','80648','80662','80664','80668','80670','80672','80673','80676','80700','80710','80720','80730','80900','80902','80904','80906','80908','80988','80990','81000','81100','81200','81300','81310']), + ], + [ + 'id' => 5, + 'segment_id' => 1, + 'reference' => SegmentConstants::OUTSTATION_POSTCODE, + 'value' => json_encode(['80000']), + ], + [ + 'id' => 6, + 'segment_id' => 2, + 'reference' => SegmentConstants::CUSTOMER_RATE, + 'value' => json_encode([ + 'id'=> 1, + 'price' => 15, + ]), + ], + ); + DB::commit(); } } diff --git a/database/seeders/SegmentsTableSeeder.php b/database/seeders/SegmentsTableSeeder.php index 4c9e19be..e6dd2be2 100644 --- a/database/seeders/SegmentsTableSeeder.php +++ b/database/seeders/SegmentsTableSeeder.php @@ -2,24 +2,24 @@ namespace Database\Seeders; -use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject; -use App\Classes\Modules\Segments\Services\CreatesSegment; -use App\Classes\ValueObjects\Constants\SegmentConstants; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; class SegmentsTableSeeder extends Seeder { - - - /** - */ public function run() { - - DB::table('segments')->insert([ - 'name' => 'Standard Segment', - 'type' => SegmentConstants::STANDARD_SEGMENT - ]); + DB::table('segments')->insert( + [ + 'id' => 1, + 'company_module_id' => 1, + 'name' => 'Default Segment', + ], + [ + 'id' => 2, + 'company_module_id' => 2, + 'name' => 'Normal Member', + ], + ); } } diff --git a/routes/transaction.php b/routes/transaction.php index cab4d241..7b4f7fd0 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -5,11 +5,13 @@ use Illuminate\Support\Facades\Route; Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => 'transaction.'], function () { Route::get('/list', 'ListTransactionsController@list')->name('list'); - Route::delete('/suspend/{id}', 'SuspendTransactionController@suspend')->name('suspend'); + // Route::delete('/suspend/{id}', 'SuspendTransactionController@suspend')->name('suspend'); - route::post('/supplier/{id}/bill/create', 'CreateSupplierTransactionController@create')->name('supplier.create'); - route::post('{id}/bill/verification', 'CreatePaymentProofDocumentController@verify')->name('bill.verification'); + route::post('/shipping-invoice/create', 'CreateShippingInvoiceTransactionController@create')->name('supplier.create'); - Route::post('booking/{id}/details/update', 'CreatePurchaseOrderTransactionController@create')->name('po.create'); + + // route::post('{id}/bill/verification', 'CreatePaymentProofDocumentController@verify')->name('bill.verification'); + + // Route::post('booking/{id}/details/update', 'CreatePurchaseOrderTransactionController@create')->name('po.create'); }); \ No newline at end of file