diff --git a/app/Http/Controllers/Admin/Shop/ArticleController.php b/app/Http/Controllers/Admin/Shop/ArticleController.php index a6564364..35eee78b 100644 --- a/app/Http/Controllers/Admin/Shop/ArticleController.php +++ b/app/Http/Controllers/Admin/Shop/ArticleController.php @@ -6,6 +6,7 @@ use App\Datatables\Admin\Shop\ArticlesDataTable; use App\Http\Requests\Admin\Shop\StoreArticlePost; use App\Repositories\Shop\ArticleNatures; use App\Repositories\Shop\Articles; +use App\Repositories\Shop\ArticleInherited; use App\Repositories\Shop\Categories; use App\Repositories\Shop\Tags; use Illuminate\Http\Request; @@ -71,7 +72,7 @@ class ArticleController extends Controller { $data = [ 'article' => [ - 'inherited' => Articles::getInheritedByProduct($productId, base64_decode($model)), + 'inherited' => ArticleInherited::getInheritedByProduct($productId, base64_decode($model)), ], ]; @@ -80,7 +81,7 @@ class ArticleController extends Controller public function getProductTags($productId, $model) { - $data = Articles::getInheritedByProduct($productId, base64_decode($model)); + $data = ArticleInherited::getInheritedByProduct($productId, base64_decode($model)); return view('Admin.Shop.Articles.partials.product.tags', $data); } diff --git a/app/Http/Controllers/Admin/Shop/ContentController.php b/app/Http/Controllers/Admin/Shop/ContentController.php index 40b97051..7b20945a 100644 --- a/app/Http/Controllers/Admin/Shop/ContentController.php +++ b/app/Http/Controllers/Admin/Shop/ContentController.php @@ -28,7 +28,7 @@ class ContentController extends Controller public function edit($id) { $data = [ - 'homepage' => Contents::get($id), + 'content' => Contents::get($id), ]; return view('Admin.Shop.Contents.edit', $data); diff --git a/app/Http/Controllers/Admin/Shop/CustomerAddressController.php b/app/Http/Controllers/Admin/Shop/CustomerAddressController.php index 43900b93..9ec9f730 100644 --- a/app/Http/Controllers/Admin/Shop/CustomerAddressController.php +++ b/app/Http/Controllers/Admin/Shop/CustomerAddressController.php @@ -10,19 +10,17 @@ class CustomerAddressController extends Controller { public function index(CustomerAddressesDataTable $dataTable) { - $data = []; - - return $dataTable->render('Admin.Shop.Customers.list', $data); + return $dataTable->render('Admin.Shop.Customers.list'); } public function create() { - return view('Admin.Shop.CustomerAddresses.create', $data); + return view('Admin.Shop.CustomerAddresses.create'); } public function store(Request $request) { - $ret = CustomerAddresses::storeFull($request->all()); + $ret = CustomerAddresses::store($request->all()); return redirect()->route('Admin.Shop.CustomerAddresses.index'); } diff --git a/app/Http/Controllers/Shop/ArticleController.php b/app/Http/Controllers/Shop/ArticleController.php index 8fdafd28..fd8fbbd0 100644 --- a/app/Http/Controllers/Shop/ArticleController.php +++ b/app/Http/Controllers/Shop/ArticleController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Shop; use App\Http\Controllers\Controller; use App\Repositories\Shop\Articles; +use App\Repositories\Shop\ArticleSiblings; class ArticleController extends Controller { @@ -11,7 +12,7 @@ class ArticleController extends Controller { $data = [ 'article' => Articles::getArticleToSell($id), - 'offers2' => Articles::getSiblings($id)->toArray(), + 'offers2' => ArticleSiblings::getSiblings($id)->toArray(), ]; return view('Shop.Articles.show', $data); diff --git a/app/Http/Controllers/Shop/InvoiceController.php b/app/Http/Controllers/Shop/InvoiceController.php index 5330e199..58827921 100644 --- a/app/Http/Controllers/Shop/InvoiceController.php +++ b/app/Http/Controllers/Shop/InvoiceController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Shop; use App\Http\Controllers\Controller; -use App\Repositories\Core\PDF; +use App\Repositories\Shop\InvoicePDF; use App\Repositories\Shop\Invoices; class InvoiceController extends Controller @@ -24,11 +24,6 @@ class InvoiceController extends Controller { \Debugbar::disable(); - $data = [ - 'invoice' => Invoices::getByUUID($uuid), - ]; - $filename = 'invoice-'.$uuid.'.pdf'; - - return PDF::view('Shop.Invoices.pdf', $data, $filename); + return InvoicePDF::getByUUID($uuid); } } diff --git a/app/Models/Shop/Tax.php b/app/Models/Shop/Tax.php index 1825059a..7332dbf9 100644 --- a/app/Models/Shop/Tax.php +++ b/app/Models/Shop/Tax.php @@ -12,6 +12,6 @@ class Tax extends Model public function price() { - return $this->hasMany(ArticlePrice::class, 'id', 'tax_id'); + return $this->hasMany(PriceListValue::class, 'id', 'tax_id'); } } diff --git a/app/Repositories/Shop/ArticleCategories.php b/app/Repositories/Shop/ArticleCategories.php new file mode 100644 index 00000000..b4927c00 --- /dev/null +++ b/app/Repositories/Shop/ArticleCategories.php @@ -0,0 +1,62 @@ +select('product_type')->distinct()->get(); + } + + public static function countProductTypesByCategory($category_id) + { + return Article::byCategory($category_id)->select('product_type')->distinct()->count(); + } + + public static function getByCategory($category_id) + { + return Article::byCategory($category_id)->with(['prices', 'product', 'image'])->get(); + } + + public static function getCategoriesByArticle($article) + { + return $article->categories->pluck('id')->toArray(); + } + + public static function getCategoriesNameByArticle($article) + { + return $article->categories->pluck('name', 'id')->toArray(); + } + + public static function storeCategories($article, $categories) + { + if (! $categories) { + return false; + } + $categories = collect($categories)->transform( + function ($item, $key) { + return (int) $item; + } + )->toArray(); + + return $article->syncCategories($categories, true); + } +} diff --git a/app/Repositories/Shop/ArticleImages.php b/app/Repositories/Shop/ArticleImages.php new file mode 100644 index 00000000..3152b269 --- /dev/null +++ b/app/Repositories/Shop/ArticleImages.php @@ -0,0 +1,110 @@ +images) ? $article->images : collect([]); + switch ($article->product_type) { + case 'App\Models\Botanic\Variety': + $variety = $article->product ?? false; + $specie = $variety->specie ?? false; + if ($variety) { + $images = count($variety->images ?? []) ? $images->merge($variety->images) : $images; + } + if ($specie) { + $images = count($specie->images ?? []) ? $images->merge($specie->images) : $images; + } + break; + case 'App\Models\Botanic\Specie': + $specie = $article->product ?? false; + $images = count($specie->images ?? []) ? $specie->images : $images; + break; + case 'App\Models\Shop\Merchandise': + $merchandise = $article->product ?? false; + $images = count($merchandise->images ?? []) ? $merchandise->images : $images; + break; + default: + } + + return $images; + } + + public static function getFullImageById($id) + { + return self::getFullImageByArticle(self::get($id)); + } + + public static function getFullImageByArticle($article) + { + $image = $article->image; + if ($image) { + return $image; + } + switch ($article->product_type) { + case 'App\Models\Botanic\Variety': + $image = $article->product->image ?? ($article->product->specie->image ?? false); + break; + case 'App\Models\Botanic\Specie': + $image = $article->product->image ?? false; + break; + case 'App\Models\Shop\Merchandise': + $image = $article->product->image ?? false; + break; + default: + } + + return $image; + } + + public static function getInheritedImagesByProduct($product_id, $product_type) + { + switch ($product_type) { + case 'App\Models\Botanic\Variety': + $images = Varieties::getImages($product_id); + break; + case 'App\Models\Botanic\Specie': + $images = Species::getImages($product_id); + break; + case 'App\Models\Shop\Merchandise': + $images = Merchandises::getImages($product_id); + break; + default: + } + + return $images ?? false ? ['images' => $images] : false; + } +} diff --git a/app/Repositories/Shop/ArticleInherited.php b/app/Repositories/Shop/ArticleInherited.php new file mode 100644 index 00000000..b0246a0a --- /dev/null +++ b/app/Repositories/Shop/ArticleInherited.php @@ -0,0 +1,65 @@ +findOrFail($id); + + return self::getInheritedByProduct($article->product_id, $article->product_type); + } + + public static function getInheritedByProduct($product_id, $product_type) + { + $data = []; + switch ($product_type) { + case 'App\Models\Botanic\Variety': + $product = Varieties::get($product_id); + if (! $product) { + break; + } + $data[] = [ + 'name' => 'Espèces', + 'description' => Species::getDescription($product->specie_id), + 'tags' => Species::getTags($product->specie_id), + ]; + $data[] = [ + 'name' => 'Variétés', + 'description' => $product->description, + 'tags' => $product->tags->toArray(), + ]; + break; + case 'App\Models\Botanic\Specie': + $product = Species::get($product_id); + if (! $product) { + break; + } + $data[] = [ + 'name' => 'Espèces', + 'description' => $product->description, + 'tags' => $product->tags->toArray(), + ]; + break; + case 'App\Models\Shop\Merchandise': + $product = Merchandises::get($product_id); + if (! $product) { + break; + } + $data[] = [ + 'name' => 'Marchandise', + 'description' => $product->description, + 'tags' => $product->tags->toArray(), + ]; + break; + default: + } + + return $data ?? false; + } +} diff --git a/app/Repositories/Shop/ArticleSiblings.php b/app/Repositories/Shop/ArticleSiblings.php new file mode 100644 index 00000000..bd9677d0 --- /dev/null +++ b/app/Repositories/Shop/ArticleSiblings.php @@ -0,0 +1,43 @@ +pluck('id')->toArray(); + } + + public static function getSiblingsDescriptions($id) + { + $data = []; + $siblings = self::getSiblings($id); + foreach ($siblings as $sibling) { + if ($sibling->description && ($sibling->article_nature->name ?? false)) { + $data[strtolower($sibling->article_nature->name)] = $sibling->description; + } + } + + return $data ?? false; + } + + public static function getSiblings($id) + { + return Article::with([ + 'siblings' => function ($query) use ($id) { + $query->where('id', '!=', $id); + }, + ])->find($id)->siblings; + } +} diff --git a/app/Repositories/Shop/ArticleTags.php b/app/Repositories/Shop/ArticleTags.php new file mode 100644 index 00000000..db60e233 --- /dev/null +++ b/app/Repositories/Shop/ArticleTags.php @@ -0,0 +1,67 @@ +tags->pluck('id')->toArray(); + } + + public static function getTagsNameByArticle($article) + { + return $article->tags->pluck('name', 'id')->toArray(); + } + + public static function getTagsSlugByArticle($article) + { + return $article->tags->pluck('slug', 'id')->toArray(); + } + + public static function getFullTagsSlugByArticle($article) + { + $data = []; + + switch ($article->product_type) { + case 'App\Models\Botanic\Variety': + $data += $article->product->tags->toArray(); + if ($article->product->specie ?? false) { + $data += $article->product->specie->tags->toArray(); + } + break; + case 'App\Models\Botanic\Specie': + $data += $article->product->tags->toArray(); + break; + case 'App\Models\Shop\Merchandise': + $data += $article->product->tags->toArray(); + $data += $article->product->producer->tags->toArray(); + break; + default: + } + $data += $article->tags->toArray(); + + foreach ($data as $tag) { + if (! isset($tags[$tag['group']][$tag['name']])) { + $tags[$tag['group']][] = $tag['name']; + } + } + + return $tags ?? null; + } + + public static function storeTags($article, $tags) + { + return Tag::storeTags($article, $tags); + } +} diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 73939c72..3a1de02c 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -29,7 +29,7 @@ class Articles public static function getOffersGroupedByNature($id, $saleChannelId = false) { - $articleIds = self::getSiblingsIds($id); + $articleIds = ArticleSiblings::getSiblingsIds($id); $articleIds[] = $id; $offers = Offers::getOffersByArticles($articleIds, $saleChannelId); foreach ($offers as $offer) { @@ -43,33 +43,6 @@ class Articles return $data ?? false; } - public static function getSiblingsIDs($id) - { - return self::getSiblings($id)->pluck('id')->toArray(); - } - - public static function getSiblingsDescriptions($id) - { - $data = []; - $siblings = self::getSiblings($id); - foreach ($siblings as $sibling) { - if ($sibling->description && ($sibling->article_nature->name ?? false)) { - $data[strtolower($sibling->article_nature->name)] = $sibling->description; - } - } - - return $data ?? false; - } - - public static function getSiblings($id) - { - return Article::with([ - 'siblings' => function ($query) use ($id) { - $query->where('id', '!=', $id); - }, - ])->find($id)->siblings; - } - public static function getOffersById($id) { return Offers::getOffersByArticle($id); @@ -105,13 +78,13 @@ class Articles $article = self::get($id); $data = $article->toArray(); $data['description'] = self::getFullDescriptionByArticle($article); - $images = self::getFullImagesByArticle($article); + $images = ArticleImages::getFullImagesByArticle($article); $data['image'] = self::getPreviewSrc($images[0] ?? false); $data['images'] = count($images) ? $images : false; $data['image_big'] = self::getImageSrc($images[0] ?? false); - $data['inherited'] = self::getInherited($id); - $data['categories'] = self::getCategoriesNameByArticle($article); - $data['tags'] = self::getFullTagsSlugByArticle($article); + $data['inherited'] = ArticleInherited::getInherited($id); + $data['categories'] = ArticleCategories::getCategoriesNameByArticle($article); + $data['tags'] = ArticleTags::getFullTagsSlugByArticle($article); $data['comments'] = Comments::getByModel($article); return $data; @@ -140,7 +113,7 @@ class Articles if ($article->description) { $data[strtolower($article->article_nature->name ?? '')] = $article->description; } - $siblings = self::getSiblingsDescriptions($article->id); + $siblings = ArticleSiblings::getSiblingsDescriptions($article->id); if ($siblings) { array_push($data, $siblings); } @@ -195,7 +168,7 @@ class Articles 'id' => $article->id, 'article_nature_id' => $article->article_nature_id, 'description' => $article->description ? $article->description : $article->product->description, - 'image' => self::getFullImageByArticle($article), + 'image' => ArticleImages::getFullImageByArticle($article), 'product_type' => $article->product_type, 'product_id' => $article->product_id, 'product_name' => $article->product->name, @@ -315,87 +288,14 @@ class Articles { $article = self::get($id); $data = $article->toArray(); - $data['inherited'] = self::getInherited($id); - $data['categories'] = self::getCategoriesByArticle($article); - $data['tags'] = self::getTagsByArticle($article); + $data['inherited'] = ArticleInherited::getInherited($id); + $data['categories'] = ArticleCategories::getCategoriesByArticle($article); + $data['tags'] = ArticleTags::getTagsByArticle($article); $data['comments'] = Comments::getByModel($article); return $data; } - public static function getInherited($id) - { - $article = Article::with('product.tags.tag_group')->findOrFail($id); - - return self::getInheritedByProduct($article->product_id, $article->product_type); - } - - public static function getInheritedByProduct($product_id, $product_type) - { - $data = []; - switch ($product_type) { - case 'App\Models\Botanic\Variety': - $product = Varieties::get($product_id); - if (! $product) { - break; - } - $data[] = [ - 'name' => 'Espèces', - 'description' => Species::getDescription($product->specie_id), - 'tags' => Species::getTags($product->specie_id), - ]; - $data[] = [ - 'name' => 'Variétés', - 'description' => $product->description, - 'tags' => $product->tags->toArray(), - ]; - break; - case 'App\Models\Botanic\Specie': - $product = Species::get($product_id); - if (! $product) { - break; - } - $data[] = [ - 'name' => 'Espèces', - 'description' => $product->description, - 'tags' => $product->tags->toArray(), - ]; - break; - case 'App\Models\Shop\Merchandise': - $product = Merchandises::get($product_id); - if (! $product) { - break; - } - $data[] = [ - 'name' => 'Marchandise', - 'description' => $product->description, - 'tags' => $product->tags->toArray(), - ]; - break; - default: - } - - return $data ?? false; - } - - public static function getInheritedImagesByProduct($product_id, $product_type) - { - switch ($product_type) { - case 'App\Models\Botanic\Variety': - $images = Varieties::getImages($product_id); - break; - case 'App\Models\Botanic\Specie': - $images = Species::getImages($product_id); - break; - case 'App\Models\Shop\Merchandise': - $images = Merchandises::getImages($product_id); - break; - default: - } - - return $images ?? false ? ['images' => $images] : false; - } - public static function getMeta(&$data = []) { switch ($data['article']['product_type'] ?? false) { @@ -424,163 +324,11 @@ class Articles return $data; } - public static function getByCategory($category_id) - { - return Article::byCategory($category_id)->with(['prices', 'product', 'image'])->get(); - } - - public static function getCategoriesByArticle($article) - { - return $article->categories->pluck('id')->toArray(); - } - - public static function getProductTypeByCategory($category_id) - { - $models = self::getProductTypesModelsByCategory($category_id); - - return ($models[0] ?? false) === Merchandise::class ? 'merchandise' : 'botanic'; - } - - public static function getProductTypesModelsByCategory($category_id) - { - return Article::byCategory($category_id)->select('product_type')->distinct()->get(); - } - - public static function countProductTypesByCategory($category_id) - { - return Article::byCategory($category_id)->select('product_type')->distinct()->count(); - } - - public static function getCategoriesNameByArticle($article) - { - return $article->categories->pluck('name', 'id')->toArray(); - } - - public static function getTagsByArticle($article) - { - return $article->tags->pluck('id')->toArray(); - } - - public static function getTagsNameByArticle($article) - { - return $article->tags->pluck('name', 'id')->toArray(); - } - - public static function getTagsSlugByArticle($article) - { - return $article->tags->pluck('slug', 'id')->toArray(); - } - - public static function getFullTagsSlugByArticle($article) - { - $data = []; - - switch ($article->product_type) { - case 'App\Models\Botanic\Variety': - $data += $article->product->tags->toArray(); - if ($article->product->specie ?? false) { - $data += $article->product->specie->tags->toArray(); - } - break; - case 'App\Models\Botanic\Specie': - $data += $article->product->tags->toArray(); - break; - case 'App\Models\Shop\Merchandise': - $data += $article->product->tags->toArray(); - $data += $article->product->producer->tags->toArray(); - break; - default: - } - $data += $article->tags->toArray(); - - foreach ($data as $tag) { - if (! isset($tags[$tag['group']][$tag['name']])) { - $tags[$tag['group']][] = $tag['name']; - } - } - - return $tags ?? null; - } - public static function getPricesByArticle($article) { return Prices::getByArticle($article->id); } - public static function getFullImagesByArticleId($id) - { - $article = self::get($id); - - return $article ? self::getFullImagesByArticle($article) : false; - } - - public static function countFullImagesByArticleId($id) - { - $article = self::get($id); - - return $article ? self::countFullImagesByArticle($article) : 0; - } - - public static function countFullImagesByArticle($article) - { - return count(self::getFullImagesByArticle($article)); - } - - public static function getFullImagesByArticle($article) - { - $images = count($article->images) ? $article->images : collect([]); - switch ($article->product_type) { - case 'App\Models\Botanic\Variety': - $variety = $article->product ?? false; - $specie = $variety->specie ?? false; - if ($variety) { - $images = count($variety->images ?? []) ? $images->merge($variety->images) : $images; - } - if ($specie) { - $images = count($specie->images ?? []) ? $images->merge($specie->images) : $images; - } - break; - case 'App\Models\Botanic\Specie': - $specie = $article->product ?? false; - $images = count($specie->images ?? []) ? $specie->images : $images; - break; - case 'App\Models\Shop\Merchandise': - $merchandise = $article->product ?? false; - $images = count($merchandise->images ?? []) ? $merchandise->images : $images; - break; - default: - } - - return $images; - } - - public static function getFullImageById($id) - { - return self::getFullImageByArticle(self::get($id)); - } - - public static function getFullImageByArticle($article) - { - $image = $article->image; - if ($image) { - return $image; - } - switch ($article->product_type) { - case 'App\Models\Botanic\Variety': - $image = $article->product->image ?? ($article->product->specie->image ?? false); - break; - case 'App\Models\Botanic\Specie': - $image = $article->product->image ?? false; - break; - case 'App\Models\Shop\Merchandise': - $image = $article->product->image ?? false; - break; - default: - } - - return $image; - } - public static function storeFull($data) { $images = $data['images'] ?? false; @@ -594,31 +342,12 @@ class Articles $article = self::store($data); self::storeImages($article, $images); - self::storeCategories($article, $categories); - self::storeTags($article, $tags); + ArticleCategories::storeCategories($article, $categories); + ArticleTags::storeTags($article, $tags); return $article->id; } - public static function storeCategories($article, $categories) - { - if (! $categories) { - return false; - } - $categories = collect($categories)->transform( - function ($item, $key) { - return (int) $item; - } - )->toArray(); - - return $article->syncCategories($categories, true); - } - - public static function storeTags($article, $tags) - { - return Tag::storeTags($article, $tags); - } - public static function toggleVisible($id, $visible) { return self::update(['visible' => $visible], $id); diff --git a/app/Repositories/Shop/Baskets.php b/app/Repositories/Shop/Baskets.php index 824fd28b..96b962f6 100644 --- a/app/Repositories/Shop/Baskets.php +++ b/app/Repositories/Shop/Baskets.php @@ -107,7 +107,7 @@ class Baskets 'quantity' => (int) $item->quantity, 'price' => $item->price, 'variation' => $offer->variation->name, - 'image' => Articles::getPreviewSrc(Articles::getFullImageByArticle($offer->article)), + 'image' => Articles::getPreviewSrc(ArticleImages::getFullImageByArticle($offer->article)), 'latin' => $offer->article->product->specie->latin ?? false, ]; } diff --git a/app/Repositories/Shop/InvoicePDF.php b/app/Repositories/Shop/InvoicePDF.php index 4e79186a..80d1f208 100644 --- a/app/Repositories/Shop/InvoicePDF.php +++ b/app/Repositories/Shop/InvoicePDF.php @@ -2,66 +2,41 @@ namespace App\Repositories\Shop; -use App\Models\Shop\Invoice; +use Carbon\Carbon; use LaravelDaily\Invoices\Invoice; use LaravelDaily\Invoices\Classes\Party; use LaravelDaily\Invoices\Classes\InvoiceItem; class InvoicePDF { + public static function getByUUID($uuid) + { + return self::get(Invoices::getIdByUUID($uuid)); + } + public static function get($id) { $invoice = Invoices::getFull($id); - - $client = new Party([ - 'name' => 'Roosevelt Lloyd', - 'phone' => '(520) 318-9486', - 'custom_fields' => [ - 'note' => 'IDDQD', - 'business id' => '365#GG', - ], - ]); - $customer = new Party([ - 'name' => 'Ashley Medina', - 'address' => 'The Green Street 12', - 'code' => '#22663214', + 'name' => $invoice->customer->name, + 'address' => self::makeAddress($invoice->address), 'custom_fields' => [ - 'order number' => '> 654321 <', + 'order number' => $invoice->order->ref, ], ]); - $items = self::makeItems($order->details); + $items = self::makeItems($invoice->order->detail); - $notes = [ - 'your multiline', - 'additional notes', - 'in regards of delivery or something else', - ]; - $notes = implode("
", $notes); - - $invoice = Invoice::make('receipt') - ->series('BIG') - // ability to include translated invoice status - // in case it was paid - ->status(__('invoices::invoice.paid')) - ->sequence(667) - ->serialNumberFormat('{SEQUENCE}/{SERIES}') - ->seller($client) + $invoice = Invoice::make(__('invoices::invoice.invoice') . ' ' .$invoice->ref) + ->status(Invoices::getStatus($invoice->status)) ->buyer($customer) - ->date(now()->subWeeks(3)) - ->dateFormat('m/d/Y') + ->shipping($invoice->shipping) + ->date(Carbon::parse($invoice->date_invoice)) ->payUntilDays(14) - ->currencySymbol('$') - ->currencyCode('USD') - ->currencyFormat('{SYMBOL}{VALUE}') - ->currencyThousandsSeparator('.') - ->currencyDecimalPoint(',') - ->filename($client->name . ' ' . $customer->name) + ->filename('invoice-' . $invoice->ref . '-' . $invoice->uuid) ->addItems($items) - ->notes($notes) - ->logo(public_path('vendor/invoices/sample-logo.png')) - // You can additionally save generated invoice to configured disk + ->notes($invoice->comment ?? '') + ->logo(public_path('img/logo.png')) ->save('public'); $link = $invoice->url(); @@ -71,12 +46,20 @@ class InvoicePDF return $invoice->stream(); } + public static function makeAddress($address) + { + return $address->address . '
' . $address->zipcode . ' ' . $address->city; + } + public static function makeItems($details) { $items = []; foreach ($details as $detail) { - $items[] = InvoiceItem::make($detail->name)->pricePerUnit($detail->price)->quantity($detail->quantity); + $items[] = InvoiceItem::make($detail->name) + ->pricePerUnit($detail->price) + ->taxByPercent($detail->vat) + ->quantity($detail->quantity); } return $items; diff --git a/app/Repositories/Shop/OfferStocks.php b/app/Repositories/Shop/OfferStocks.php new file mode 100644 index 00000000..d03992f1 --- /dev/null +++ b/app/Repositories/Shop/OfferStocks.php @@ -0,0 +1,25 @@ +stock_current = $offer->stock_current - $item['quantity']; + if ($offer->stock_current <= 0) { + $offer->stock_current = 0; + } + + return $offer->save(); + } + + public static function getStockCurrent($id) + { + return Offers::getField($id, 'stock_current'); + } +} diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php index 85fd15bf..87795fe5 100644 --- a/app/Repositories/Shop/Offers.php +++ b/app/Repositories/Shop/Offers.php @@ -18,6 +18,22 @@ class Offers ]; } + public static function decreaseStock($item) + { + $offer = self::get($item['offer_id']); + $offer->stock_current = $offer->stock_current - $item['quantity']; + if ($offer->stock_current <= 0) { + $offer->stock_current = 0; + } + + return $offer->save(); + } + + public static function getStockCurrent($id) + { + return self::getField($id, 'stock_current'); + } + public static function getWeight($id, $quantity = 1) { $offer = self::get($id); @@ -58,7 +74,7 @@ class Offers 'tariff.price_lists.price_list_values', 'variation', ])->find($id); - $images = Articles::getFullImagesByArticle($offer->article); + $images = ArticleImages::getFullImagesByArticle($offer->article); $offer->article->image = Articles::getPreviewSrc($images[0] ?? false); return $offer; @@ -111,7 +127,7 @@ class Offers public static function getThumbSrc(Offer $offer) { - $image = $offer->article ? Articles::getFullImageByArticle($offer->article) : false; + $image = $offer->article ? ArticleImages::getFullImageByArticle($offer->article) : false; return $image ? Articles::getThumbSrc($image) : false; } diff --git a/app/Repositories/Shop/OrderDetails.php b/app/Repositories/Shop/OrderDetails.php index ef4edc8d..6a68fb85 100644 --- a/app/Repositories/Shop/OrderDetails.php +++ b/app/Repositories/Shop/OrderDetails.php @@ -14,6 +14,9 @@ class OrderDetails foreach ($data as $item) { $item['order_id'] = $order_id; $detail = self::store($item); + if ($detail) { + OfferStocks::decreaseStock($item); + } } return true; diff --git a/config/invoices.php b/config/invoices.php index 9bdf1d69..37911a2a 100644 --- a/config/invoices.php +++ b/config/invoices.php @@ -6,12 +6,12 @@ return [ /* * Carbon date format */ - 'format' => 'Y-m-d', + 'format' => 'd/m/Y', /* * Due date for payment since invoice's date. */ - 'pay_until_days' => 7, + 'pay_until_days' => 30, ], 'serial_number' => [ @@ -87,7 +87,7 @@ return [ * Default attributes for Seller::class */ 'attributes' => [ - 'name' => 'Towne, Smith and Ebert', + 'name' => 'Jardin\'Envie', 'address' => '89982 Pfeffer Falls Damianstad, CO 66972-8160', 'code' => '41-1985581', 'vat' => '123456789', diff --git a/resources/views/Shop/Articles/show.blade.php b/resources/views/Shop/Articles/show.blade.php index c3127275..647e2cc7 100644 --- a/resources/views/Shop/Articles/show.blade.php +++ b/resources/views/Shop/Articles/show.blade.php @@ -9,9 +9,12 @@
-
-
- @include('components.multi-images', ['image' => $article['image'], 'images' => $article['images']]) +
+
+ @include('components.multi-images', [ + 'image' => $article['image'], + 'images' => $article['images'], + ])
diff --git a/resources/views/Shop/Orders/order.blade.php b/resources/views/Shop/Orders/order.blade.php index cddcc760..cd071070 100644 --- a/resources/views/Shop/Orders/order.blade.php +++ b/resources/views/Shop/Orders/order.blade.php @@ -4,7 +4,7 @@ @section('content')
-
+
@if (App\Repositories\Shop\Customers::isNotConnected())

Déja client ? @@ -27,7 +27,7 @@

@if ($basket['count']) -
+
@include('Shop.Baskets.partials.basketTotal', ['basket' => $basket]) diff --git a/resources/views/Shop/layout/partials/header-nav.blade.php b/resources/views/Shop/layout/partials/header-nav.blade.php index ef62860f..1321638d 100644 --- a/resources/views/Shop/layout/partials/header-nav.blade.php +++ b/resources/views/Shop/layout/partials/header-nav.blade.php @@ -1,19 +1,18 @@
-
- - Variétés Paysannes de la Semence à l'Assiette -
+
+ Jardin'Envie + Variétés Paysannes de la Semence à l'Assiette +
-
- @include("Shop.layout.partials.search") -
+
+ @include('Shop.layout.partials.search') +
-
- @include('Shop.layout.partials.header-catalog') - @include("Shop.layout.partials.header-profile") - @include("Shop.layout.partials.header-basket") -
+
+ @include('Shop.layout.partials.header-catalog') + @include('Shop.layout.partials.header-profile') + @include('Shop.layout.partials.header-basket') +
-