uccello / inventory
该软件包允许在Uccello项目中创建库存模块。
v1.0.2
2020-12-04 08:36 UTC
Requires
- uccello/uccello: 1.0.*
This package is auto-updated.
Last update: 2024-09-15 00:44:04 UTC
README
通过此软件包,将现有模块转换为会计模块(例如报价、订单、发票)变得非常容易。
安装软件包
您可以使用以下命令行轻松安装此软件包
$ composer require uccello/inventory $ php artisan vendor:publish --tag inventory-assets $ php artisan vendor:publish --tag inventory-config
您可以修改 config/inventory.php
并适配配置。
将经典模块转换为库存模块
IsInventoryModule 特性
将以下行添加到您想要转换为库存模块的模型中。以下是一个使用 Order
模块的示例
<?php .... use Uccello\Inventory\Support\Traits\IsInventoryModule; class Order { use IsInventoryModule; protected $inventoryMapping = [ 'header' => [ 'total_excl_tax' => 'total_excl_tax', // Replace the value by the name of the field in your module (for automatic update) 'total_incl_tax' => 'total_incl_tax', // Replace the value by the name of the field in your module (for automatic update) 'total_vat' => 'total_vat', // Replace the value by the name of the field in your module (for automatic update) ], // Replace all values by your columns names 'lines' => [ 'related_id' => 'order_id', 'product_uuid' => 'product_uuid', 'label' => 'label', 'description' => 'description', 'vat_rate' => 'vat_rate', 'unit_price' => 'unit_price', 'price_type' => 'price_type', 'quantity' => 'qty', 'unit' => 'unit', 'price_excl_tax' => 'price_excl_tax', 'price_incl_tax' => 'price_incl_tax', 'sequence' => 'sequence', ], ]; public function lines() // This relation must be called "lines" { return $this->hasMany(OrderLine::class)->orderBy('sequence'); // Replace OrderLine by the model class you use for saving the lines } // ... }
创建迁移
创建一个新的迁移并创建包含所有行的表
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; use Uccello\Core\Models\Module; class AlterOrderLinesTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('order_lines', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('order_id')->nullable(); $table->unsignedInteger('product_id')->nullable(); $table->string('product_uuid')->nullable(); $table->string('label')->nullable(); $table->text('description')->nullable(); $table->decimal('vat_rate', 5, 2)->nullable(); $table->decimal('unit_price', 13, 2)->nullable(); $table->string('price_type')->nullable(); $table->decimal('qty', 13, 2)->nullable(); $table->decimal('price', 13, 2)->nullable(); $table->string('unit')->nullable(); $table->decimal('price_excl_tax', 13, 2)->nullable(); $table->decimal('price_incl_tax', 13, 2)->nullable(); $table->timestamps(); $table->foreign('order_id')->references('id')->on('orders'); $table->foreign('product_id')->references('id')->on('crm_products'); }); // Update module data $module = Module::where('name', 'order')->first(); $module->data = [ 'private' => true, 'header' => [ 'total_excl_tax' => 'total_excl_tax', 'total_incl_tax' => 'total_incl_tax', 'total_vat' => 'total_vat', ], 'related_modules' => [ // You can add as many modules as you want 'product' => [ // Name of the related module 'search' => 'name', // The name of the field you want use to search from the inventory line // Replace mapping values with the name of product fields if exist 'mapping' => [ 'unit_price' => 'unit_price', 'label' => 'label', 'description' => 'description', 'vat_rate' => 'vat_rate', 'unit_price' => 'unit_price', 'unit' => 'unit' ], ] ], ]; $module->save(); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('order_lines'); // Update module data $module = Module::where('name', 'order')->first(); $module->data = null; $module->save(); } }
覆盖视图
-
创建或编辑您的模块编辑视图(例如
resources/views/uccello/modules/order/edit/main.blade.php
)@extends('uccello::modules.default.edit.main') @section('other-blocks') @include('inventory::lines.edit') @include('inventory::total.edit') @endsection
-
创建或编辑您的模块详情视图(例如
resources/views/uccello/modules/order/detail/main.blade.php
)@extends('uccello::modules.default.detail.main') @section('other-blocks') @include('inventory::lines.detail') @include('inventory::total.detail') @endsection
许可协议
MIT 许可协议(MIT)。有关更多信息,请参阅许可文件。