update bulk download white form

This commit is contained in:
edmondlang
2023-10-12 18:10:32 +08:00
parent 3bbc4346c4
commit 5ec7a4a61f
5 changed files with 75 additions and 41 deletions
@@ -10,6 +10,7 @@ use App\Classes\ValueObjects\Constants\DocumentType;
use App\Models\Company;
use App\Models\Group;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class BulkDownloadSupplierWhiteFormsLogic
{
@@ -20,33 +21,57 @@ class BulkDownloadSupplierWhiteFormsLogic
*/
public function execute(Request $request)
{
$startDate = Carbon::createFromFormat('d-m-Y', $request->input('startDate'))->startOfDay();
$endDate = Carbon::createFromFormat('d-m-Y', $request->input('endDate'))->endOfDay();
$companyReference = Company::find($request->input('supplier'))->reference;
$groups = Group::where('issuer', $request->input('supplier'))
->whereDate('created_at', '>=', $startDate)
->whereDate('created_at', '<=', $endDate)
->orderBy('created_at', 'DESC')
->get();
if (count($groups) > 0) {
$zip_file = "currency_vendor_orders_{$request->input('startDate')}_to_{$request->input('endDate')}_{$companyReference}.zip";
$zip = new ZipArchive();
if ($zip->open($zip_file, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) {
foreach($groups as $group) {
$document = $group->documents()->where('document_type', DocumentType::CURRENCY_VENDOR_ORDER)->whereNull('deleted_at')->first()->files()->first();
$zip->addFile(Storage::disk('documents')->path($document->file->file_info->original->file), $group->reference . '.pdf');
}
try {
$startDate = Carbon::createFromFormat('d-m-Y', $request->input('startDate'))->startOfDay();
$endDate = Carbon::createFromFormat('d-m-Y', $request->input('endDate'))->endOfDay();
$zip->close();
while (ob_get_level()) {
ob_end_clean();
}
$companyReference = Company::find($request->input('supplier'))->reference;
$groups = Group::where('issuer', $request->input('supplier'))
->whereDate('created_at', '>=', $startDate)
->whereDate('created_at', '<=', $endDate)
->orderBy('created_at', 'DESC')
->get();
if (count($groups) > 0) {
return response()->download($zip_file);
}
}
$zipDirectory = storage_path('app/bulk_whiteform'); // Update this with the actual directory path
if (!file_exists($zipDirectory)) {
mkdir($zipDirectory, 0755, true);
}
$zip_file = "{$zipDirectory}/currency_vendor_orders_{$request->input('startDate')}_to_{$request->input('endDate')}_{$companyReference}.zip";
$zip = new ZipArchive();
if ($zip->open($zip_file, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) {
foreach($groups as $group) {
$document = $group->documents()->where('document_type', DocumentType::CURRENCY_VENDOR_ORDER)->whereNull('deleted_at')->first()->files()->first();
$zip->addFile(Storage::disk('documents')->path($document->file->file_info->original->file), $group->reference . '.pdf');
}
$zip->close();
while (ob_get_level()) {
ob_end_clean();
}
return response()->download($zip_file);
}
}
return response()->json([
'status' => 'Failed',
'message' => 'No white form found for this supplier in the given date range.',
]);
} catch (\Exception $e) {
// Log the exception for debugging
Log::error('Error in BulkDownloadSupplierWhiteFormsLogic: ' . $e->getMessage());
return response()->json([
'status' => 'Failed',
'message' => 'An error occurred while processing the request.',
]);
}
}
}
@@ -4,19 +4,19 @@
<div class="row">
<div class="col-12">
<div class="row m-l-0 m-r-0">
<div class="col-3 mb-2 mb-md-0 p-l-3 p-r-3 p-md-0">
<div class="col mb-2 mb-md-0 p-l-3 p-r-3 p-md-0">
<validation-wrapper-component selectable :validator="$v.parameters.supplier">
<label>Supplier</label>
<selectable-component :endpoint="route('api.company.list') + '?filters=' + JSON.stringify({'business_type': 3, 'status_in': [1, 2, 0]})" section="exportSupplierFilterSection" valueColumn="id" :labelColumn="['name']" v-model="parameters.supplier"></selectable-component>
</validation-wrapper-component>
</div>
<div class="col-3 mb-2 mb-md-0 p-l-3 p-r-3 p-md-0">
<div class="col mb-2 mb-md-0 p-l-3 p-r-3 p-md-0">
<validation-wrapper-component :validator="$v.parameters.startDate">
<label class="all-caps">Start Date</label>
<date-picker-component :parameters="parameters" v-model.lazy="parameters.startDate"></date-picker-component>
</validation-wrapper-component>
</div>
<div class="col-3 mb-2 mb-md-0 p-l-3 p-r-3 p-md-0">
<div class="col mb-2 mb-md-0 p-l-3 p-r-3 p-md-0">
<validation-wrapper-component :validator="$v.parameters.endDate">
<label class="all-caps">End Date</label>
<date-picker-component :parameters="parameters" v-model.lazy="parameters.endDate"></date-picker-component>
@@ -25,7 +25,7 @@
<div class="col-auto p-l-3 p-r-3 p-md-0">
<div class="btn btn-lg btn-primary fs-11 w-100 h-100 d-flex justify-content-center align-items-center" @click="bulkDownloadWhiteForm()">
<span>
Export White Form
Export
</span>
</div>
</div>
@@ -65,7 +65,7 @@ export default {
},
methods: {
bulkDownloadWhiteForm(){
window.open(route('suppliers.white_forms') + '?supplier=' + this.parameters.supplier + '&startDate=' + this.parameters.startDate + '&endDate=' + this.parameters.endDate, '_blank');
this.submit(this.route('api.suppliers.white_forms'), 'post', this.section, false, false);
},
},
mixins: [componentHandler]
@@ -2,19 +2,33 @@
<div class="row">
<div class="col">
<div class="row">
<div class="col-12 col-md-6 p-l-0">
<div class="col-8 p-l-0">
<small class="all-caps muted fs-10">Export Payment Transactions CSV</small>
<download-billing-with-dates-component section="paymentsReportSection" ></download-billing-with-dates-component>
</div>
</div>
<div class="row">
<div class="col-8 p-l-0">
<small class="all-caps muted fs-10">Download Zip White Form</small>
<download-supplier-white-form-component section="paymentsReportSection" ></download-supplier-white-form-component>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<div class="row">
<div class="col">
<div class="col p-l-0">
<small class="all-caps muted fs-10">Filter Supplier</small>
</div>
</div>
<div class="row">
<div class="col padding-0">
<validation-wrapper-component selectable :validator="$v.filterSupplier">
<label>Supplier</label>
<selectable-component :endpoint="route('api.company.list') + '?filters=' + JSON.stringify({'business_type': 3, 'status_in': [1, 2, 0]})" section="supplierFilterSection" valueColumn="id" :labelColumn="['name']" v-model="filterSupplier"></selectable-component>
</validation-wrapper-component>
</div>
<div class="col-2">
<button type="button" class="btn btn-lg btn-secondary fs-11 h-100 d-flex justify-content-center align-items-center" @click="reset()">Reset</button>
<div class="col-2 p-l-0">
<button type="button" class="btn btn-lg btn-complete fs-11 h-100 d-flex justify-content-center align-items-center" @click="reset()">Reset</button>
</div>
</div>
</div>
@@ -78,11 +92,6 @@
</div>
</div>
</div>
<div class="row p-t-15">
<div class="col-12 p-l-0">
<download-supplier-white-form-component section="paymentsReportSection" ></download-supplier-white-form-component>
</div>
</div>
</div>
</div>
</template>
+1
View File
@@ -33,6 +33,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
Route::post('/import/upload-import-invoices', 'Imports\ImportStatementInvoiceController@import')->name('import_invoices.upload');
Route::post('/import/upload-import-receipt', 'Imports\ImportStatementReceiptsController@import')->name('import_receipts.upload');
Route::post('/customers/invoices', 'Companies\BulkDownloadCustomerInvoicesController@download')->name('customers.invoices');
Route::post('/supplier/white-form/bulk-download', 'Companies\BulkDownloadSupplierWhiteFormsController@download')->name('suppliers.white_forms');
require __DIR__ . '/company.php';
-1
View File
@@ -261,7 +261,6 @@ Route::get('/export/payment-transactions/f614e339d7058904a831aad742e24d55', 'Exp
Route::get('/export/wallet-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@walletTransactions')->name('walletTransactions.export');
Route::get('/export/booking-transactions', 'Exports\ExportCustomersToExcelController@bookingTransactions')->name('export.transactions.booking');
Route::get('/export/invoice-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@invoiceTransactions')->name('invoiceTransactions.export');
Route::get('/supplier/white-form/bulk-download', 'Companies\BulkDownloadSupplierWhiteFormsController@download')->name('suppliers.white_forms');
Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsProducts $exportsProducts) {
$bookings = Booking::where(function($query){