This commit is contained in:
2025-09-25 03:03:31 +05:00
commit ae480cf2f6
2768 changed files with 1485826 additions and 0 deletions

View File

@@ -0,0 +1,160 @@
<?php
namespace App\Nova\Resources\Ecommerce\Product\Order\Actions;
use App\Models\Ecommerce\Payouts\Payout;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Http\Requests\NovaRequest;
use PhpOffice\PhpWord\SimpleType\TblWidth;
class ExportEvidenceForProducts extends Action
{
use InteractsWithQueue, Queueable;
/**
* The displayable name of the action.
*
* @var string
*/
public function name(): string
{
return __('Evidence for products');
}
/**
* Perform the action on the given models.
*
* @return mixed
*/
public function handle(ActionFields $fields, Collection $models)
{
$payout = $models->first();
$orderItems = $payout->orderItems;
$channel = $payout->channel;
$user = $channel->user;
exec('rm -rf app-docs/*');
$documentsPath = 'app-docs/'.Str::random();
exec("mkdir {$documentsPath}");
$this->generatePriceNegotiationDocument($user, $payout, $orderItems, $documentsPath);
$this->generateEvidenceForProductsDocument($user, $payout, $orderItems, $documentsPath);
return Action::openInNewTab(route('user.docs', ['folder' => $documentsPath]));
}
protected function generatePriceNegotiationDocument(User $user, Payout $payout, Collection $orderItems, string $folder): void
{
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(resource_path('docs/order/evidence-price-negotiation.docx'));
$templateProcessor->setValues([
'year' => date('Y'),
'product_owner' => $user->companyName(),
]);
$table = new \PhpOffice\PhpWord\Element\Table([
'borderSize' => 2,
'borderColor' => 'black',
'width' => 5000,
'width' => 6000,
'unit' => TblWidth::TWIP,
]);
$table->addRow();
$table->addCell()->addText('');
$table->addCell()->addText('Harydyň ady');
$table->addCell()->addText('Komitentiň satyş bahasy, manat');
$table->addCell()->addText('Komissioneriň satyş bahasy, manat');
$i = 0;
$total_cost_amount = 0;
$total_unit_price_amount = 0;
foreach ($orderItems as $orderItem) {
$i++;
$table->addRow();
$table->addCell()->addText($i);
$table->addCell()->addText($orderItem->product_name);
$table->addCell()->addText($orderItem->unit_cost_amount);
$table->addCell()->addText($orderItem->unit_price_amount);
$total_cost_amount += $orderItem->unit_cost_amount;
$total_unit_price_amount += $orderItem->unit_price_amount;
}
$table->addRow();
$table->addCell()->addText();
$table->addCell()->addText('Jemi');
$table->addCell()->addText($total_cost_amount);
$table->addCell()->addText($total_unit_price_amount);
$templateProcessor->setComplexBlock('products_table', $table);
$documentPath = "{$folder}/hasaplashyk-{$payout->id}-{$user->companyName()}-baha-ylalashyk.docx";
$templateProcessor->saveAs(public_path($documentPath));
}
public function generateEvidenceForProductsDocument(User $user, Payout $payout, Collection $orderItems, string $folder): void
{
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(resource_path('docs/order/evidence.docx'));
$templateProcessor->setValues([
'date' => date('Y'),
'o_date' => $payout->created_at->format('d.m.Y'),
'product_owner' => $user->companyName(),
]);
$table = new \PhpOffice\PhpWord\Element\Table([
'borderSize' => 2,
'borderColor' => 'black',
'width' => 5000,
'width' => 6000,
'unit' => TblWidth::TWIP,
]);
$table->addRow();
$table->addCell()->addText('No');
$table->addCell()->addText('Harydyň ady');
$table->addCell()->addText('Mukdary, san');
$table->addCell()->addText('Biriniň bahasy, manat');
$table->addCell()->addText('Jemi bahasy, manat');
$i = 0;
$total_price = 0;
foreach ($orderItems as $orderItem) {
$i++;
$table->addRow();
$table->addCell()->addText($i);
$table->addCell()->addText($orderItem->product_name);
$table->addCell()->addText($orderItem->quantity);
$table->addCell()->addText($orderItem->unit_cost_amount);
$table->addCell()->addText($orderItem->unit_cost_amount * $orderItem->quantity);
$total_price += $orderItem->unit_cost_amount * $orderItem->quantity;
}
$table->addRow();
$table->addCell()->addText('');
$table->addCell()->addText('Jemi');
$table->addCell()->addText($i);
$table->addCell()->addText();
$table->addCell()->addText($total_price);
$templateProcessor->setComplexBlock('products_table', $table);
$documentPath = "{$folder}/sargyt-{$payout->id}-{$user->companyName()}-delilnama.docx";
$templateProcessor->saveAs(public_path($documentPath));
}
/**
* Get the fields available on the action.
*/
public function fields(NovaRequest $request): array
{
return [];
}
}

View File

@@ -0,0 +1,149 @@
<?php
namespace App\Nova\Resources\Ecommerce\Product\Order\Actions;
use App\Models\Ecommerce\Product\Order\Order;
use App\Models\Ecommerce\Product\Order\Shipping\OrderShipping;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionResponse;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Http\Requests\NovaRequest;
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\SimpleType\TblWidth;
use PhpOffice\PhpWord\TemplateProcessor;
class ExportOrderInvoiceAction extends Action
{
use InteractsWithQueue, Queueable;
/**
* The displayable name of the action.
*
* @var string
*/
public function name(): string
{
return __('Invoice');
}
/**
* Perform the action on the given models.
*/
public function handle(ActionFields $fields, Collection $models): mixed
{
if ($models->count() !== 1) {
return Action::danger(
__('Please run this on only one user resource')
);
}
$order = $models->first();
$products = $order
->items()
->with(['channel', 'product'])
->get();
$documentPath = $this->generateDocument(
order: $order,
products: $products,
templatePath: resource_path('docs/order/invoice.docx'),
productsTotal: $products->sum('total')
);
return ActionResponse::download(
name: sprintf('sargyt-%s.docx', $order->id),
url: url($documentPath)
);
}
private function generateDocument(
Order $order,
Collection $products,
string $templatePath,
float $productsTotal
): string {
$templateProcessor = new TemplateProcessor($templatePath);
$templateProcessor->setValues([
'id' => $order->id,
'payment_type' => $order->formattedPaymentType(),
'created_at' => $order->created_at->format('H:i, d.m.Y'),
'order_shipping_method' => $order->formattedShippingMethod(),
'shipping_price' => $order->shipping_method === OrderShipping::SELF_PICKUP
? 'Özüm baryp aljak'
: (string) $order->shippingPrice().' TMT',
'order_name' => $order->customer_name,
'order_address' => $order->fullAddress(),
'order_phone' => $order->customer_phone,
'p_t' => $productsTotal,
't' => $productsTotal + $order->shippingPrice(),
'notes' => $order->notes,
'adt_tax' => $order->additional_tax ?: '0.0',
]);
$table = $this->generateTable($products);
$templateProcessor->setComplexBlock('products_table', $table);
$documentPath = public_path(
sprintf('app-docs/sargyt-%s.docx', $order->id)
);
$templateProcessor->saveAs($documentPath);
return sprintf('app-docs/sargyt-%s.docx', $order->id);
}
private function generateTable(Collection $products): Table
{
$table = new Table([
'borderSize' => 2,
'borderColor' => 'black',
'width' => 5000,
'unit' => TblWidth::PERCENT,
]);
$table->addRow();
$table->addCell()->addText('№');
$table->addCell()->addText('HARYDYŇ ADY');
$table->addCell()->addText('BAHASY');
$table->addCell()->addText('SATYJY');
$table->addCell()->addText('MUKDARY');
$table->addCell()->addText('ARZANLADYŞ');
$table->addCell()->addText('JEMI BAHASY');
$products->each(function ($product, $index) use ($table) {
$table->addRow();
$table->addCell()->addText($index + 1);
$table->addCell()->addText($product->product->name);
$table->addCell()->addText($product->unit_price_amount);
$table
->addCell()
->addText($product->channel?->name ?? 'Türkmenpoçta PAK');
$table->addCell()->addText($product->quantity);
$table
->addCell()
->addText(
$product->product->caluculateDiscountDifference(
$product->unit_price_amount
)
);
$table
->addCell()
->addText($product->quantity * $product->unit_price_amount);
});
return $table;
}
/**
* Get the fields available on the action.
*/
public function fields(NovaRequest $request): array
{
return [];
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Nova\Resources\Ecommerce\Product\Order\Actions;
use App\Exports\Ecommerce\Product\Order\ExportOrderReport;
use App\Nova\Fields\FieldHelpers;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Http\Requests\NovaRequest;
class ExportOrderReportAction extends Action
{
use InteractsWithQueue, Queueable;
/**
* Get the displayable name of the action.
*/
public function name(): string
{
return __('Export Order Report');
}
/**
* Perform the action on the given models.
*/
public function handle(ActionFields $fields, Collection $models): mixed
{
$start_date = Carbon::createFromFormat('Y-m-d', $fields->start_date)->format('d.m.Y');
$end_date = Carbon::createFromFormat('Y-m-d', $fields->end_date)->format('d.m.Y');
(new ExportOrderReport(
start_date: $fields->start_date,
end_date: $fields->end_date
))->store('order-reports.xlsx', 'order_reports');
return Action::download(
url: Storage::disk('order_reports')->url('order-reports.xlsx'),
name: sprintf('Hasabat %s - %s.xlsx', $start_date, $end_date)
);
}
/**
* Get the fields available on the action.
*
* @return array
*/
public function fields(NovaRequest $request)
{
return [
Date::make(__('Start date'), 'start_date')
->rules('required')
->displayUsing(FieldHelpers::tmDate()),
Date::make(__('End date'), 'end_date')
->rules('required')
->displayUsing(FieldHelpers::tmDate()),
];
}
}