1. Go to this page and download the library: Download uccello/inventory library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
uccello / inventory example snippets
....
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
}
// ...
}
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();
}
}