yonka's avatar

yonka started a new conversation+100 XP

2mos ago

I want to read TakenInventoryInfo and Paginate all by also reading StoreFrom from TakenInventories. This is my database design 1.TakenInventoryInfo

class TakenInventoryInfo extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    protected $fillable = ['tracking_no','taken_date','store_id','reference','description','approve_status','user_id'];

    public function takenInventories()
    {
        return $this->hasMany(TakenInventory::class);
    }

    public function store()
    {
        return $this->belongsTo(Store::class);
    } // store to which is taken From.
}

2.TakenInventory

class TakenInventory extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    protected $fillable = ['taken_inventory_info_id','inventory_in_store_id','quantity','store_id'];

    public function inventoryInStore()
    {
        return $this->belongsTo(InventoryInStore::class);
    }

    public function store()
    {
        return $this->belongsTo(Store::class);
    } // store taken to
    public function takenInventoryInfo()
    {
        return $this->belongsTo(TakenInventoryInfo::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

}
  1. User
class User extends Authenticatable
{
    use HasFactory, Notifiable, HasRoles;

    // user belongs to branch
    public function branch(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Branch::class);
    }

    public function stores()
    {
        return $this->belongsToMany(Store::class);
    }
}

Each User BelongsToMany Store. I want to be able to read (by checking stores to which system user belongsTo ) all these attributes: tracking_no, Store_from(TakenInventoryInfo), Store_to(TakenInventories), taken_date. and has a link to view all TakenInventories related to this TakenInventoryInfo and be able to Print or download as pdf using barryvdh/laravel-dompdf. I am using Livewire and Laravel. I also want to be able to search by tracking_no or taken_date or store_to. Also I want to add pagination to search items

yonka's avatar

yonka started a new conversation+100 XP

2mos ago

I build a database, after finished and start working, there is a problem arise from the seller, the seller is selling items, so the seller required to sell an items as either a set sometimes or as individual item. A set contains specific items with specific Quantities and price that are known for instance: a set has a name like AYZ and it has to have quantities like 1,2,..etc so if the buyer wants to buy AYZ 2sets, the buyer knows how many items each AYZ will have. So instead of mentioning all these items simply the buyer will say "I need AYZ 2sets" and that has even specific price (sum of all item prices it contains). the seller will tell each AYZ price like: $100x2sets = $200total. but the seller knows that $100 will divide to all other items that a set will contain. So I want to be able to make AYZ set and specify how many items it will have with specific quantities like : AYZ One set contains:

  1. A = 2pcs $10

  2. Y = 3pcs $15

  3. Z = 5pcs $7 so if the buyer wants AYZ 2set, it will multiply by 2 and will be like this: AYZ Two set contains:

  4. A = 2pcs*2 = 4pcs

  5. Y = 3pcs*2 = 6pcs

  6. Z = 5pcs*2 = 10pcs This is my database I am using right now, the seller is able to sell each item as an individual only, SO I want to able to add this functionality to my database. I have these tables

  7. SoldInventory Table,

class SoldInventory extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    protected $fillable = ['customer_id','store_id','date_of_sale','tracking_no','reference','reference_no','description','user_id'];

    public function soldInventoryItems()
    {
        return $this->hasMany(SoldInventoryItems::class);
    }

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function salesInvoice()
    {
        return $this->hasOne(SalesInvoice::class);
    }

    public function store()
    {
        return $this->belongsTo(Store::class);
    }
}
  1. SoldInventoryItems Table,
class SoldInventoryItems extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    protected $fillable = ['inventory_in_store_id','quantity','unit_price','sub_total'];


    public function soldInventory()
    {
        return $this->belongsTo(SoldInventory::class);
    }

    public function inventoryInStore() : BelongsTo
    {
        return $this->belongsTo(InventoryInStore::class);
    }
}```
3. InventoryInStore Table.

class InventoryInStore extends Model { use HasFactory, CreatedUpdatedBy, softDeletes;

protected $fillable = ['inventory_item_id','quantity','store_id'];

public function store()
{
    return $this->belongsTo(Store::class);
}

public function inventoryItem()
{
    return $this->belongsTo(InventoryItem::class);
}

public function soldInventoryItems()
{
    return $this->hasMany(SoldInventoryItems::class);
}

}

4. InventoryItem Table

class InventoryItem extends Model { use HasFactory, CreatedUpdatedBy, softDeletes;

public function item()
{
    return $this->belongsTo(Item::class);
}

public function category()
{
    return $this->belongsTo(Category::class);
}


public function inventoryInStores()
{
    return $this->hasMany(InventoryInStore::class);
}

}

I am using laravel and livewire.
yonka's avatar

yonka started a new conversation+100 XP

2mos ago

I build a database, after finished and start working, there is a problem arise from the seller, the seller is selling items, so the seller required to sell an items as a set. A set contains specific items with specific Quantities that are known for instance: a set has a name like AYZ and it has to have quantities like 1,2,..etc so if the buyer wants to buy AYZ 2sets, the buyer knows how many items each AYZ will have. So instead of mentioning all these items simply the buyer will say "I need AYZ 2sets" and that has even specific price not all item price. the seller will tell each AYZ price like: $100x2sets = $200total. but the seller knows that $100 will divide to all other items that a set will contain. So I want to be able to make AYZ set and specify how many items it will have with specific quantities like : AYZ One set contains:

  1. A = 2pcs

  2. Y = 3pcs

  3. Z = 5pcs so if the buyer wants AYZ 2set, it will multiply by 2 and will be like this: AYZ Two set contains:

  4. A = 2pcs*2 = 4pcs

  5. Y = 3pcs*2 = 6pcs

  6. Z = 5pcs*2 = 10pcs This is my database I am using right now, the seller is able to sell each item as an individual, SO I want to able to add this functionality to my database. I have these tables

  7. SoldInventory Table,

class SoldInventory extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    protected $fillable = ['customer_id','store_id','date_of_sale','tracking_no','reference','reference_no','description','user_id'];

    public function soldInventoryItems()
    {
        return $this->hasMany(SoldInventoryItems::class);
    }

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function salesInvoice()
    {
        return $this->hasOne(SalesInvoice::class);
    }

    public function store()
    {
        return $this->belongsTo(Store::class);
    }
}
  1. SoldInventoryItems Table,
class SoldInventoryItems extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    protected $fillable = ['inventory_in_store_id','quantity','unit_price','sub_total'];


    public function soldInventory()
    {
        return $this->belongsTo(SoldInventory::class);
    }

    public function inventoryInStore() : BelongsTo
    {
        return $this->belongsTo(InventoryInStore::class);
    }
}```
3. InventoryInStore Table.

class InventoryInStore extends Model { use HasFactory, CreatedUpdatedBy, softDeletes;

protected $fillable = ['inventory_item_id','quantity','store_id'];

public function store()
{
    return $this->belongsTo(Store::class);
}

public function inventoryItem()
{
    return $this->belongsTo(InventoryItem::class);
}

public function soldInventoryItems()
{
    return $this->hasMany(SoldInventoryItems::class);
}

}

4. InventoryItem Table

class InventoryItem extends Model { use HasFactory, CreatedUpdatedBy, softDeletes;

public function item()
{
    return $this->belongsTo(Item::class);
}

public function category()
{
    return $this->belongsTo(Category::class);
}


public function inventoryInStores()
{
    return $this->hasMany(InventoryInStore::class);
}

}

I am using laravel and livewire.
yonka's avatar

yonka wrote a reply+100 XP

2mos ago

What about if we change database? because this solution will require to change price as a code and that is not suitable

yonka's avatar

yonka started a new conversation+100 XP

2mos ago

I build a database, after finished and start working, there is a problem arise from the seller, the seller is selling items, so the seller required to sell an items as a set. A set contains specific items with specific Quantities that are known for instance: a set has a name like AYZ and it has to have quantities like 1,2,..etc so if the buyer wants to buy AYZ 2sets, the buyer knows how many items each AYZ will have. So instead of mentioning all these items simply the buyer will say "I need AYZ 2sets" and that has even specific price not all item price. the seller will tell each AYZ price like: $100x2sets = $200total. but the seller knows that $100 will divide to all other items that a set will contain. So I want to be able to make AYZ set and specify how many items it will have with specific quantities like : AYZ One set contains:

  1. A = 2pcs

  2. Y = 3pcs

  3. Z = 5pcs so if the buyer wants AYZ 2set, it will multiply by 2 and will be like this: AYZ Two set contains:

  4. A = 2pcs*2 = 4pcs

  5. Y = 3pcs*2 = 6pcs

  6. Z = 5pcs*2 = 10pcs This is my database I am using right now, the seller is able to sell each item as an individual, SO I want to able to add this functionality to my database without changing database tables because the system is working right now (production mode). I have these tables:

  7. SoldInventory Table,

class SoldInventory extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    protected $fillable = ['customer_id','store_id','date_of_sale','tracking_no','reference','reference_no','description','user_id'];

    public function soldInventoryItems()
    {
        return $this->hasMany(SoldInventoryItems::class);
    }

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function salesInvoice()
    {
        return $this->hasOne(SalesInvoice::class);
    }

    public function store()
    {
        return $this->belongsTo(Store::class);
    }
}
  1. SoldInventoryItems Table.
class SoldInventoryItems extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    protected $fillable = ['inventory_in_store_id','quantity','unit_price','sub_total'];


    public function soldInventory()
    {
        return $this->belongsTo(SoldInventory::class);
    }

    public function inventoryInStore() : BelongsTo
    {
        return $this->belongsTo(InventoryInStore::class);
    }
}
  1. InventoryInStore Table.
class InventoryInStore extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    protected $fillable = ['inventory_item_id','quantity','store_id'];

    public function store()
    {
        return $this->belongsTo(Store::class);
    }

    public function inventoryItem()
    {
        return $this->belongsTo(InventoryItem::class);
    }

    public function soldInventoryItems()
    {
        return $this->hasMany(SoldInventoryItems::class);
    }
}
  1. InventoryItem Table
class InventoryItem extends Model
{
    use HasFactory, CreatedUpdatedBy, softDeletes;

    public function item()
    {
        return $this->belongsTo(Item::class);
    }

    public function category()
    {
        return $this->belongsTo(Category::class);
    }


    public function inventoryInStores()
    {
        return $this->hasMany(InventoryInStore::class);
    }
}

I am using laravel and livewire.