Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakarialabib committed Nov 10, 2023
2 parents bab04c4 + 60a6709 commit 2805957
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 273 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/update_contributors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Update Contributors

on:
workflow_run:
workflows: ["Build and Deploy"]
types:
- completed

jobs:
update-contributors:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Update Contributors
run: |
CONTRIBUTORS=$(curl -s https://api.github.com/repos/zakarialabib/mystockmaster/contributors | jq -r '.[].login')
sed -i '/## Contributors/q' README.md
echo -e "## Contributors\n\n$(printf -- '- [%s](https://github.com/%s)\n' $CONTRIBUTORS)" >> README.md
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git add README.md
git commit -m "Update Contributors [skip ci]"
git push
41 changes: 18 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
## Author

You may think that's a typical project, i hope that's not, within this project you will find many errors and lot of solutions for your problems,
I experienced retail & ecommerce in electronics (pcs & smartphones), this thing keep my alarmed about some key points, easy to use & robust, we will be the best in our category of open source web apps
Welcome to a unique project that goes beyond the ordinary. I bring to you MystockMaster, a solution born out of my experience in the retail and ecommerce sectors, particularly in electronics such as PCs and smartphones. My continuous vigilance over critical aspects like user-friendliness and robustness aims to position us as the best in the open-source web apps category.

I'm very greatfulll for the contribution in the Laravel community, learned some much in the process, now it's my turn to give.
I extend heartfelt gratitude to the Laravel community for their contributions, which have been a source of immense learning. Now, it's my turn to contribute and give back.

(Peace) سلام
() سلام

## Overview

MystockMaster is a Laravel-based inventory management system that offers an easy and straightforward way to keep track of your inventory, sales, purchases, and more. It features a user-friendly dashboard, intuitive reports, and a wide range of features to help you manage and grow your business.
MystockMaster, a Laravel-based inventory management system, simplifies the tracking of your inventory, sales, purchases, and more. Offering a user-friendly dashboard, intuitive reports, and an array of features, it becomes your partner in efficient business management and growth.

Features:
- Dashboard with key insights and metrics
Expand All @@ -25,9 +24,10 @@ Features:
- Multi-language support
- POS integration
- Notifications and alerts
- Send product promotion to telegram
- Send product promotions to Telegram
and more...

Built with Laravel 9, Livewire, AlpineJs, and Tailwind CSS, ensuring a fast and responsive user experience. Try it out today and see how it can help you manage your inventory and grow your business.
Built with Laravel 9, Livewire, AlpineJs, and Tailwind CSS, ensuring a fast and responsive user experience. Try it out today and witness how it streamlines inventory management, propelling your business forward.

## Demo

Expand Down Expand Up @@ -75,22 +75,17 @@ The Laravel framework is open-sourced software licensed under the [MIT license](

## Screenshots :

- Login
![Login](screens/login.png)
- Dashboard
![Dashboard](screens/dashboard.png)
- Pos
![Pos](screens/pos.png)
- Products
![Products](screens/products.png)
- Product Create
![Product Create](screens/product-modal.png)
- Purchase Create
![Purchase Create](screens/purchase-create.png)
- Sale Create
![Sale Create](screens/sale-create.png)
- Customer Create
![Customer Create](screens/customer-modal.png)
| Login | Dashboard | POS |
| --- | --- | --- |
| ![Login](screens/login.png) | ![Dashboard](screens/dashboard.png) | ![POS](screens/pos.png) |

| Products | Product Create | Purchase Create |
| --- | --- | --- |
| ![Products](screens/products.png) | ![Product Create](screens/product-modal.png) | ![Purchase Create](screens/purchase-create.png) |

| Sale Create | Customer Create |
| --- | --- |
| ![Sale Create](screens/sale-create.png) | ![Customer Create](screens/customer-modal.png) |

## Contact

Expand Down
189 changes: 86 additions & 103 deletions app/Http/Livewire/Reports/ProfitLossReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Http\Livewire\Reports;

use App\Models\Expense;
use App\Models\ProductWarehouse;
use App\Models\Purchase;
use App\Models\PurchasePayment;
use App\Models\PurchaseReturn;
Expand All @@ -13,39 +14,31 @@
use App\Models\SalePayment;
use App\Models\SaleReturn;
use App\Models\SaleReturnPayment;
use App\Models\Warehouse;
use Livewire\Component;

class ProfitLossReport extends Component
{
public $start_date;

public $end_date;

public $total_sales;

public $sales_amount;

public $total_purchases;

public $purchases_amount;

public $total_sale_returns;

public $sale_returns_amount;

public $total_purchase_returns;

public $purchase_returns_amount;

public $expenses_amount;

public $profit_amount;

public $payments_received_amount;

public $payments_sent_amount;

public $payments_net_amount;
public $total_sales = 0;
public $sales_amount = 0;
public $total_purchases = 0;
public $purchases_amount = 0;
public $total_sale_returns = 0;
public $sale_returns_amount = 0;
public $total_purchase_returns = 0;
public $purchase_returns_amount = 0;
public $expenses_amount = 0;
public $profit_amount = 0;
public $payments_received_amount = 0;
public $payments_sent_amount = 0;
public $payments_net_amount = 0;
public $warehouse_id;
public $warehouses;
public $completed_purchases;
public $pending_purchases;
public $top_selling_products;

protected $rules = [
'start_date' => 'required|date|before:end_date',
Expand All @@ -54,19 +47,25 @@ class ProfitLossReport extends Component

public function mount(): void
{
$this->start_date = '';
$this->end_date = '';
$this->total_sales = 0;
$this->sales_amount = 0;
$this->total_sale_returns = 0;
$this->sale_returns_amount = 0;
$this->total_purchases = 0;
$this->purchases_amount = 0;
$this->total_purchase_returns = 0;
$this->purchase_returns_amount = 0;
$this->payments_received_amount = 0;
$this->payments_sent_amount = 0;
$this->payments_net_amount = 0;
$this->setDefaultDates();
$this->warehouses = Warehouse::pluck('name', 'id')->toArray();
}

public function filterByDate($type)
{
$this->setDefaultDates();

switch ($type) {
case 'day':
$this->setDateRange(now()->startOfDay(), now()->endOfDay());
break;
case 'month':
$this->setDateRange(now()->startOfMonth(), now()->endOfMonth());
break;
case 'year':
$this->setDateRange(now()->startOfYear(), now()->endOfYear());
break;
}
}

public function render()
Expand All @@ -84,75 +83,35 @@ public function generateReport()
public function setValues()
{
$this->total_sales = Sale::completed()
->when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
})
->when($this->end_date, function ($query) {
return $query->whereDate('date', '<=', $this->end_date);
})
->whereBetween('date', [$this->start_date, $this->end_date])
->count();

$this->sales_amount = Sale::completed()
->when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
})
->when($this->end_date, function ($query) {
return $query->whereDate('date', '<=', $this->end_date);
})
->whereBetween('date', [$this->start_date, $this->end_date])
->sum('total_amount') / 100;

$this->total_purchases = Purchase::completed()
->when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
})
->when($this->end_date, function ($query) {
return $query->whereDate('date', '<=', $this->end_date);
})
->whereBetween('date', [$this->start_date, $this->end_date])
->count();

$this->purchases_amount = Purchase::completed()
->when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
})
->when($this->end_date, function ($query) {
return $query->whereDate('date', '<=', $this->end_date);
})
->whereBetween('date', [$this->start_date, $this->end_date])
->sum('total_amount') / 100;

$this->total_sale_returns = SaleReturn::completed()
->when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
})
->when($this->end_date, function ($query) {
return $query->whereDate('date', '<=', $this->end_date);
})
->whereBetween('date', [$this->start_date, $this->end_date])
->count();

$this->sale_returns_amount = SaleReturn::completed()
->when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
})
->when($this->end_date, function ($query) {
return $query->whereDate('date', '<=', $this->end_date);
})
->whereBetween('date', [$this->start_date, $this->end_date])
->sum('total_amount') / 100;

$this->total_purchase_returns = PurchaseReturn::completed()
->when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
})
->when($this->end_date, function ($query) {
return $query->whereDate('date', '<=', $this->end_date);
})
->whereBetween('date', [$this->start_date, $this->end_date])
->count();

$this->purchase_returns_amount = PurchaseReturn::completed()
->when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
})
->when($this->end_date, function ($query) {
return $query->whereDate('date', '<=', $this->end_date);
})
->whereBetween('date', [$this->start_date, $this->end_date])
->sum('total_amount') / 100;

$this->expenses_amount = Expense::when($this->start_date, function ($query) {
Expand All @@ -163,41 +122,53 @@ public function setValues()
})
->sum('amount') / 100;

$this->profit_amount = $this->calculateProfit();
$this->completed_purchases = Purchase::completed()
->when($this->start_date, fn ($query) => $query->whereDate('date', '>=', $this->start_date))
->when($this->end_date, fn ($query) => $query->whereDate('date', '<=', $this->end_date))
->count();

$this->payments_received_amount = $this->calculatePaymentsReceived();
$this->pending_purchases = Purchase::pending()
->when($this->start_date, fn ($query) => $query->whereDate('date', '>=', $this->start_date))
->when($this->end_date, fn ($query) => $query->whereDate('date', '<=', $this->end_date))
->count();

$this->profit_amount = $this->calculateProfit();
$this->payments_received_amount = $this->calculatePaymentsReceived();
$this->payments_sent_amount = $this->calculatePaymentsSent();

$this->payments_net_amount = $this->payments_received_amount - $this->payments_sent_amount;
}

public function calculateProfit()
public function calculateProfit(): float
{
$revenue = $this->sales_amount - $this->sale_returns_amount;

$sales = Sale::completed()
->when($this->start_date, fn ($query) => $query->whereDate('date', '>=', $this->start_date))
->when($this->end_date, fn ($query) => $query->whereDate('date', '<=', $this->end_date))
->with('saleDetails')->get();
->whereBetween('date', [$this->start_date, $this->end_date])
->with('saleDetails.product') // Ensure you load related models
->get();

$productCosts = 0;

foreach ($sales as $sale) {
foreach ($sale->saleDetails as $saleDetail) {
// Assuming you have a warehouses relationship defined on the Product model
$productWarehouse = $saleDetail->product->warehouses->where('warehouse_id', $this->warehouse_id)->first();

if ($productWarehouse) {
$productCosts += $productWarehouse->cost * $saleDetail->quantity;
}
$productCosts += $this->getProductCost($saleDetail->product_id, $saleDetail->warehouse_id) * $saleDetail->quantity;
}
}

return $revenue - $productCosts;
}

public function calculatePaymentsReceived()
private function getProductCost($productId, $warehouseId): float
{
// Retrieve the product cost from the ProductWarehouse pivot table
$productWarehouse = ProductWarehouse::where('product_id', $productId)
->where('warehouse_id', $warehouseId)
->first();

return $productWarehouse ? $productWarehouse->cost : 0;
}

public function calculatePaymentsReceived(): float
{
$sale_payments = SalePayment::when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
Expand All @@ -218,7 +189,7 @@ public function calculatePaymentsReceived()
return $sale_payments + $purchase_return_payments;
}

public function calculatePaymentsSent()
public function calculatePaymentsSent(): float
{
$purchase_payments = PurchasePayment::when($this->start_date, function ($query) {
return $query->whereDate('date', '>=', $this->start_date);
Expand All @@ -238,4 +209,16 @@ public function calculatePaymentsSent()

return $purchase_payments + $sale_return_payments + $this->expenses_amount;
}

private function setDefaultDates()
{
$this->start_date = now()->startOfYear()->format('Y-m-d');
$this->end_date = now()->endOfDay()->format('Y-m-d');
}

private function setDateRange($startDate, $endDate)
{
$this->start_date = $startDate->format('Y-m-d');
$this->end_date = $endDate->format('Y-m-d');
}
}
Loading

0 comments on commit 2805957

Please sign in to comment.