From ae392dd052be11d94c2ac7f8d3ca9364fca09ade Mon Sep 17 00:00:00 2001 From: glovetleong Date: Mon, 21 Feb 2022 08:57:39 +0800 Subject: [PATCH 1/4] debtor --- .../UpdateCompanyDebtorLogic.php | 66 +++++++++++++++++++ .../Services/UpdatesCompanyDebtor.php | 23 +++++++ .../UpdateCompanyDebtorController.php | 20 ++++++ ...0_203803_add_debtor_to_companies_table.php | 32 +++++++++ routes/company.php | 2 + 5 files changed, 143 insertions(+) create mode 100644 app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDebtorLogic.php create mode 100644 app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php create mode 100644 app/Http/Controllers/Companies/UpdateCompanyDebtorController.php create mode 100644 database/migrations/2022_02_20_203803_add_debtor_to_companies_table.php diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDebtorLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDebtorLogic.php new file mode 100644 index 00000000..49938efd --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDebtorLogic.php @@ -0,0 +1,66 @@ + 'Updated Company', + 'message' => 'You have successfully updated the Company' + ]; + } + + /** @var CanUpdateCompany */ + private $canUpdateCompany; + + /** @var UpdatesCompanyDebtor */ + private $updatesCompanyDebtor; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** + * UpdateCompanyControllersLogic constructor. + * @param CanUpdateCompany $canUpdateCompany + * @param UpdatesCompanyDebtor $updatesCompanyDebtor + * @param FetchesCompany $fetchesCompany + */ + public function __construct(CanUpdateCompany $canUpdateCompany, UpdatesCompanyDebtor $updatesCompanyDebtor, FetchesCompany $fetchesCompany) + { + $this->canUpdateCompany = $canUpdateCompany; + $this->updatesCompanyDebtor = $updatesCompanyDebtor; + $this->fetchesCompany = $fetchesCompany; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $debtor = $request->input('debtor'); + + $query = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $query = $this->updatesCompanyDebtor->execute($query, $debtor); + + return $this->resourceResponse(new CompanyResource($query)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php b/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php new file mode 100644 index 00000000..4cb43a9f --- /dev/null +++ b/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php @@ -0,0 +1,23 @@ +debtor = $debtor; + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/UpdateCompanyDebtorController.php b/app/Http/Controllers/Companies/UpdateCompanyDebtorController.php new file mode 100644 index 00000000..af62c4f9 --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateCompanyDebtorController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/database/migrations/2022_02_20_203803_add_debtor_to_companies_table.php b/database/migrations/2022_02_20_203803_add_debtor_to_companies_table.php new file mode 100644 index 00000000..2798b9e7 --- /dev/null +++ b/database/migrations/2022_02_20_203803_add_debtor_to_companies_table.php @@ -0,0 +1,32 @@ +string('debtor')->nullable()->after('reference'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('companies', function (Blueprint $table) { + + }); + } +} diff --git a/routes/company.php b/routes/company.php index f5c4dfbc..a0ca19a5 100644 --- a/routes/company.php +++ b/routes/company.php @@ -9,6 +9,8 @@ Route::group(['prefix' => 'company', 'as' => 'company.', 'namespace' => 'Compani Route::put('/update/{id}', 'UpdateCompanyController@update')->name('update'); Route::delete('/delete/{id}', 'DeleteCompanyController@destroy')->name('delete'); + Route::put('/update/debtor/{id}', 'UpdateCompanyDebtorController@update')->name('delete'); + Route::post('/team/create', 'AddNewMemberController@create')->name('team.create'); Route::group(['prefix' => '{id}/segment', 'as' => 'segment.'], function () { From 016de0cd473d6081db10327ac29721106b8ab4f2 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Tue, 1 Mar 2022 16:04:38 +0800 Subject: [PATCH 2/4] Create update refund status api and credit wallet processor --- .../CreateSupplierTransactionLogic.php | 2 +- .../UpdateRefundTransactionStatusLogic.php | 85 ++++++++++++++++++ .../ControllersLogic/CreditWalletLogic.php | 59 ++++++------ .../Processors/CreditWalletProcessor.php | 89 +++++++++++++++++++ ...pdateRefundTransactionStatusController.php | 14 +++ app/Models/Transaction.php | 8 -- routes/transaction.php | 1 + 7 files changed, 215 insertions(+), 43 deletions(-) create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php create mode 100644 app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php create mode 100644 app/Http/Controllers/Transactions/UpdateRefundTransactionStatusController.php diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php index 5a7e76b4..93caf8d1 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -128,7 +128,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); // $constant = $this->fetchesConstant->execute(['service_charge' => $supplier->id]); $constant = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $supplier->id)->first(); - $serviceCharge = $this->calculatesTransactionServiceCharge->execute($payment->original_amount, $rate, $constant ? $constant->detail->service_charge->amount : 0.75); + $serviceCharge = $this->calculatesTransactionServiceCharge->execute($payment->original_amount, $rate, $constant ? $constant->detail->service_charge->amount : 0); $object = new TransactionObject($billNumber, TransactionType::BILL, $supplier->id, 1, $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php new file mode 100644 index 00000000..d760b05d --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php @@ -0,0 +1,85 @@ + 'Updated Transaction', + 'message' => 'You have successfully updated a transaction' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var DeletesDocument */ + private $deletesDocument; + + /** @var CreditWalletProcessor */ + private $creditWalletProcessor; + + /** + * CreatePaymentVerificationDocumentLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param DeletesDocument $deletesDocument + * @param CreditWalletProcessor $creditWalletProcessor + */ + public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, DeletesDocument $deletesDocument, CreditWalletProcessor $creditWalletProcessor) + { + $this->fetchesCompany = $fetchesCompany; + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->deletesDocument = $deletesDocument; + $this->creditWalletProcessor = $creditWalletProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + + $transaction = $this->updatesTransactionStatus->execute($transaction, $request->input('status')); + + $company = $this->fetchesCompany->execute(['id' => $transaction->booking->company_id]); + + $reference = 'Refund for booking reference '.$transaction->booking->marking; + + if ($transaction->status == ApprovalStatus::APPROVED) { + // add to credit wallet + $this->creditWalletProcessor->execute($company, $transaction->type, $transaction->amount, $reference); + } + + return $this->response([]); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php index 1e7b3ceb..3bd908d0 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php @@ -2,25 +2,26 @@ namespace App\Classes\Modules\Wallets\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllerLogic; -use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; -use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; -use App\Classes\Modules\Companies\Services\FetchesCompany; -use App\Classes\Modules\Wallets\Services\CreatesWallet; -use App\Classes\Modules\Wallets\Services\GeneratesWalletCode; -use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; -use App\Classes\Modules\Transactions\Services\CreatesTransaction; -use App\Classes\Modules\Wallets\Services\UpdatesWallet; - -use App\Classes\ValueObjects\Constants\TransactionType; -use App\Classes\ValueObjects\Constants\PaymentMethodType; -use App\Classes\ValueObjects\Constants\ApprovalStatus; -use App\Http\Resources\WalletResource; - use ErrorException; -use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\DB; +use App\Http\Resources\WalletResource; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\Modules\Wallets\Services\CreatesWallet; +use App\Classes\Modules\Wallets\Services\UpdatesWallet; +use App\Classes\ValueObjects\Constants\TransactionType; + +use App\Classes\ValueObjects\Constants\PaymentMethodType; +use App\Classes\General\Abstracts\AbstractControllerLogic; +use App\Classes\Modules\Companies\Services\FetchesCompany; +use App\Classes\Modules\Wallets\Services\GeneratesWalletCode; + +use App\Classes\Modules\Transactions\Services\CreatesTransaction; +use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; +use App\Classes\Modules\Wallets\Processors\CreditWalletProcessor; +use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; +use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; class CreditWalletLogic extends AbstractControllerLogic { @@ -53,6 +54,9 @@ class CreditWalletLogic extends AbstractControllerLogic /** @var UpdatesWallet */ private $updatesWallet; + /** @var CreditWalletProcessor */ + private $creditWalletProcessor; + /** * CreateWalletLogic constructor. * @param FetchesCompany $fetchesCompany @@ -61,6 +65,7 @@ class CreditWalletLogic extends AbstractControllerLogic * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber * @param CreatesTransaction $createsTransaction * @param UpdatesWallet $updatesWallet + * @param CreditWalletProcessor $creditWalletProcessor */ public function __construct( FetchesCompany $fetchesCompany, @@ -68,7 +73,8 @@ class CreditWalletLogic extends AbstractControllerLogic CreatesWallet $createsWallet, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, - UpdatesWallet $updatesWallet + UpdatesWallet $updatesWallet, + CreditWalletProcessor $creditWalletProcessor ) { $this->fetchesCompany = $fetchesCompany; @@ -77,6 +83,7 @@ class CreditWalletLogic extends AbstractControllerLogic $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->createsTransaction = $createsTransaction; $this->updatesWallet = $updatesWallet; + $this->creditWalletProcessor = $creditWalletProcessor; } /** @@ -94,23 +101,7 @@ class CreditWalletLogic extends AbstractControllerLogic $type = $request->input('transaction_type'); - if (!$company->wallets()->first()) { - $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); - $this->createsWallet->execute($object, $company); - } - - $wallet = $company->wallets()->first(); - - $billNumber = $this->generatesTransactionBillNumber->execute($type === 2 ? 'DEBIT-NOTE-' : 'CREDIT-NOTE-'); - - $transaction_object = new TransactionObject($billNumber, $type === 2 ? TransactionType::DEBIT_NOTE : TransactionType::CREDIT_NOTE, 1, $wallet->company->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference); - $transaction = $this->createsTransaction->execute($wallet, $transaction_object); - - $updateWalletAmount = $type === 2 ? ($wallet->amount - $transaction->amount) : ($wallet->amount + $transaction->amount); - - $walletObject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); - - $wallet = $this->updatesWallet->execute($wallet, $walletObject); + $wallet = $this->creditWalletProcessor->execute($company, $type, $amount, $reference); return $this->resourceResponse(new WalletResource($wallet)); } diff --git a/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php b/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php new file mode 100644 index 00000000..2b303938 --- /dev/null +++ b/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php @@ -0,0 +1,89 @@ +generatesWalletCode = $generatesWalletCode; + $this->createsWallet = $createsWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + } + + + /** + * @param Company $company + * @param int $transactionType + * @param float $amount + * @param string $reference + * @return \Illuminate\Database\Eloquent\Model + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(Company $company, int $transactionType, float $amount, string $reference) + { + if (!$company->wallets()->first()) { + $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); + $wallet = $this->createsWallet->execute($object, $company); + } + + $wallet = $company->wallets()->first(); + + $billNumber = $this->generatesTransactionBillNumber->execute($transactionType === 2 ? 'DEBIT-NOTE-' : 'CREDIT-NOTE-'); + + $transaction_object = new TransactionObject($billNumber, $transactionType === 2 ? TransactionType::DEBIT_NOTE : TransactionType::CREDIT_NOTE, 1, $wallet->owner->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference); + $transaction = $this->createsTransaction->execute($wallet, $transaction_object); + + $updateWalletAmount = $transactionType === 2 ? ($wallet->amount - $transaction->amount) : ($wallet->amount + $transaction->amount); + + $walletObject = new WalletObject($wallet->owner->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $wallet = $this->updatesWallet->execute($wallet, $walletObject); + + return $wallet; + } +} diff --git a/app/Http/Controllers/Transactions/UpdateRefundTransactionStatusController.php b/app/Http/Controllers/Transactions/UpdateRefundTransactionStatusController.php new file mode 100644 index 00000000..919fadd1 --- /dev/null +++ b/app/Http/Controllers/Transactions/UpdateRefundTransactionStatusController.php @@ -0,0 +1,14 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index f89ae6ef..2806d782 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -54,14 +54,6 @@ class Transaction extends AbstractModel implements Documentable, Transactionable return $this->BelongsTo(Booking::class, 'owner_id', 'id'); } - /** - * @return MorphMany - */ - public function transactions(): MorphMany - { - return $this->MorphMany(Transaction::class, 'owner'); - } - /** * @return BelongsTo */ diff --git a/routes/transaction.php b/routes/transaction.php index 2012a045..c3402b47 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -11,6 +11,7 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => route::post('{id}/bill/verification', 'CreatePaymentProofDocumentController@verify')->name('bill.verification'); route::post('{id}/bill/pay', 'CreatePaymentProofDocumentController@pay')->name('bill.pay'); Route::put('/{id}/bill/{status}', 'UpdatePaymentTransactionStatusController@update')->where('status', 'pending|complete')->name('bill.status'); + Route::put('/{id}/refund/status/update', 'UpdateRefundTransactionStatusController@update')->name('refund.status.update'); route::delete('{id}/bill/delete', 'DeletePaymentProofDocumentController@delete')->name('bill.delete'); From 6d624d3196a29ea3e9963b8151e7fc9ebf85be81 Mon Sep 17 00:00:00 2001 From: glovetleong Date: Wed, 2 Mar 2022 09:54:12 +0800 Subject: [PATCH 3/4] export and import --- .gitignore | 5 +- app/Classes/General/ExcelHandel.php | 87 +++++++++++++++ .../Exports/Services/ExportsNullDebtors.php | 100 ++++++++++++++++++ .../Imports/Services/ImportsDebtor.php | 44 ++++++++ .../ExportCustomersToExcelController.php | 7 ++ .../Imports/ImportUpdateDebtorController.php | 25 +++++ routes/web.php | 3 + storage/app/public/.gitignore | 2 - 8 files changed, 270 insertions(+), 3 deletions(-) create mode 100644 app/Classes/General/ExcelHandel.php create mode 100644 app/Classes/Modules/Exports/Services/ExportsNullDebtors.php create mode 100644 app/Classes/Modules/Imports/Services/ImportsDebtor.php create mode 100644 app/Http/Controllers/Imports/ImportUpdateDebtorController.php delete mode 100644 storage/app/public/.gitignore diff --git a/.gitignore b/.gitignore index 95d268cf..476bf6a0 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,7 @@ db/* docker-compose.yml package-lock.json public/* -/public/* \ No newline at end of file +/public/* +/storage/app/public +public +/storage/framework/laravel-excel diff --git a/app/Classes/General/ExcelHandel.php b/app/Classes/General/ExcelHandel.php new file mode 100644 index 00000000..3060ed8b --- /dev/null +++ b/app/Classes/General/ExcelHandel.php @@ -0,0 +1,87 @@ +makeDirectory($path); + return $folder; + } + + public static function insertExcel($path = '', $base64Set = []) + { + $file_info = []; + $folder_path = ExcelHandel::generateFolder('excels/' . $path); + + foreach ($base64Set as $key => $row) { + + $exceldata = $row; + $filename = (string) Str::uuid(); + + $f = finfo_open(); + $mime_type = finfo_file($f, $exceldata, FILEINFO_MIME_TYPE); + + $extension = 'xls'; + + switch ($mime_type) { + case 'application/vnd.ms-excel': + $extension = 'xls'; + break; + case 'application/zip': + $extension = 'xlsx'; + break; + } + + if (empty($extension)) { + return false; + } + + $exceldata = explode('base64,', $exceldata); + $exceldata = base64_decode($exceldata[1]); + + $filename_with_ext = $filename . '.' . $extension; + + $file = ExcelHandel::generateExcel($path, $exceldata, $filename, $extension); + + $file_info[] = [ + 'path' => $path, + 'filename' => $filename_with_ext, + 'mime_type' => $mime_type, + 'extension' => $extension, + 'file_info' => empty($file) ? [] : $file, + ]; + } + + return $file_info; + } + + public static function generateExcel($path = '', $exceldata = '', $filename = '', $extension = '') + { + $file_info = []; + $file = \Storage::disk('public')->put('excels/' . $path . '/' . $filename . '.' . $extension, $exceldata); + $file_info['original']['file'] = storage_path('app/public/excels/' . $path . '/' . $filename . '.' . $extension); + + return $file_info; + } + + public static function removeExcel($excel_info = []) + { + $excel_info = json_decode(json_encode($excel_info), true); + foreach ($excel_info as $key => $row) { + if (!empty($row['path'])) { + \File::delete([$row['file_info']['original']['file']]); + } + } + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php b/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php new file mode 100644 index 00000000..e585275c --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php @@ -0,0 +1,100 @@ +reference, //Code + $company->name, //CompanyName + '', //Desc2 + '', //AreaCode + '', //SalesAgent + '', //DebtorType + '', //DisplayTerm + '', //AgingOn + '', //StatementType + 'MYR', //CurrencyCode + $company->reference, //RegisterNo + '', //Address1 + '', //Address2 + '', //Address3 + '', //Address4 + '', //PostCode + '', //DeliverAddr1 + '', //DeliverAddr2 + '', //DeliverAddr3 + '', //DeliverAddr4 + '', //DeliverPostCode + '', //Attention + '', //Phone1 + '', //Phone2 + '', //Fax1 + '', //Fax2 + '', //ExemptNo + '', //ExpiryDate + '', //PriceCategory + ]; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Imports/Services/ImportsDebtor.php b/app/Classes/Modules/Imports/Services/ImportsDebtor.php new file mode 100644 index 00000000..7a44dbb6 --- /dev/null +++ b/app/Classes/Modules/Imports/Services/ImportsDebtor.php @@ -0,0 +1,44 @@ +first(); + + if ($company) { + $company->debtor = $debtor; + $company->update(); + } + + return []; + } + + public function batchSize(): int + { + return 100; + } + + public function rules(): array + { + return [ + + ]; + } +} diff --git a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php index cdd1c49a..366bf0c7 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Exports; use App\Classes\Modules\Exports\Services\ExportsCustomers; use App\Classes\Modules\Exports\Services\ExportsTransactions; +use App\Classes\Modules\Exports\Services\ExportsNullDebtors; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -24,4 +25,10 @@ class ExportCustomersToExcelController $request->headers->set('Authorization', 'Bearer '.$token); return $exportsTransactions->download('transactions.csv', Excel::CSV, ['Content-Type' => 'text/csv']); } + + public function nullDebtor(ExportsNullDebtors $exportsNullDebtors, Request $request){ + $token = Auth::fromUser(User::find(1)); + $request->headers->set('Authorization', 'Bearer '.$token); + return $exportsNullDebtors->download('nullDebtor.csv', Excel::CSV, ['Content-Type' => 'text/csv']); + } } \ No newline at end of file diff --git a/app/Http/Controllers/Imports/ImportUpdateDebtorController.php b/app/Http/Controllers/Imports/ImportUpdateDebtorController.php new file mode 100644 index 00000000..83d1effd --- /dev/null +++ b/app/Http/Controllers/Imports/ImportUpdateDebtorController.php @@ -0,0 +1,25 @@ +headers->set('Authorization', 'Bearer '.$token); + + $excel_file = $request->input('excel_file'); + + $excel_file = ExcelHandel::insertExcel('debtor', $excel_file); + + return $import = Excel::import(new ImportsDebtor(), $excel_file[0]['file_info']['original']['file']); + } +} \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index e26ef4d8..eda5a7c8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -168,6 +168,9 @@ Route::get('billplz/bills/{bill_no}', function($bill_no){ Route::get('/export/customers/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@export'); Route::get('/export/transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@transactions'); +Route::get('/export/null-debtor/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@nullDebtor'); + +Route::get('/import/update-debtor/f614e339d7058904a831aad742e24d55', 'Imports\ImportUpdateDebtorController@import'); Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsProducts $exportsProducts) { return $exportsProducts->download('products.csv', Excel::CSV, ['Content-Type' => 'text/csv']); diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore deleted file mode 100644 index d6b7ef32..00000000 --- a/storage/app/public/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore From ba542c17608334b575a67ced314e2f9399b5282d Mon Sep 17 00:00:00 2001 From: glovetleong Date: Wed, 2 Mar 2022 14:18:52 +0800 Subject: [PATCH 4/4] reference --- app/Classes/Modules/Imports/Services/ImportsDebtor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Imports/Services/ImportsDebtor.php b/app/Classes/Modules/Imports/Services/ImportsDebtor.php index 7a44dbb6..ad91a689 100644 --- a/app/Classes/Modules/Imports/Services/ImportsDebtor.php +++ b/app/Classes/Modules/Imports/Services/ImportsDebtor.php @@ -17,8 +17,8 @@ class ImportsDebtor implements ToModel, WithHeadingRow, WithBatchInserts, WithVa public function model($row = []) { - $reference = str_replace('/CIEF', '', $row['2nd_description']); - + $reference = preg_split('(-|\(|\)|\/)', $row['2nd_description']); + $reference = $reference[array_key_last($reference)]; $debtor = $row['code']; $company = Company::where('reference', $reference)->first();