Skip to content

Commit

Permalink
added minimum stock in stock report and on product
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapjansma committed Feb 22, 2023
1 parent db71edf commit 313310d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description":"Isotope Stock.",
"type": "contao-bundle",
"license":"AGPL-3.0-or-later",
"version": "1.0.14",
"version": "1.0.15",
"require": {
"contao/core-bundle": "^4.9",
"isotope/isotope-core": "^2.6",
Expand Down
23 changes: 19 additions & 4 deletions src/Controller/OverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Krabo\IsotopeStockBundle\Model\AccountModel;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -72,6 +73,7 @@ public function overviewAll(Request $request): Response {
public function overview(Request $request, bool $onlyActive=true): Response
{
\Contao\System::loadLanguageFile('default');
\Contao\System::loadLanguageFile('tl_iso_product');
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', $GLOBALS['TL_LANG']['IstotopeStockProductInfo']['Product']);
Expand All @@ -90,9 +92,13 @@ public function overview(Request $request, bool $onlyActive=true): Response
$sheet->getColumnDimension('D')->setAutoSize(TRUE);
$sheet->getStyle('D1')->getFont()->setBold(TRUE);
$sheet->getStyle('D1')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT);
$sheet->setCellValue('E1', $GLOBALS['TL_LANG']['tl_iso_product']['isostock_minimun_stock'][0]);
$sheet->getColumnDimension('E')->setAutoSize(TRUE);
$sheet->getStyle('E1')->getFont()->setBold(TRUE);
$sheet->getStyle('E1')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT);

$accounts = AccountModel::findAll(['order' => 'title ASC']);
$column = 'E';
$column = 'F';
foreach($accounts as $account) {
$sheet->setCellValue($column.'1', html_entity_decode($account->title));
$sheet->getColumnDimension($column)->setAutoSize(TRUE);
Expand All @@ -102,7 +108,7 @@ public function overview(Request $request, bool $onlyActive=true): Response
}
$sheet->freezePane('A2');

$sql = "SELECT id, name, sku FROM tl_iso_product WHERE `pid` = '0'";
$sql = "SELECT id, name, sku, isostock_minimun_stock FROM tl_iso_product WHERE `pid` = '0'";
if ($onlyActive) {
$sql .= " AND `published` = '1'";
}
Expand All @@ -115,7 +121,7 @@ public function overview(Request $request, bool $onlyActive=true): Response
continue;
}

$sheet->setCellValue('A'.$i, html_entity_decode($product['name']));
$sheet->setCellValue('A'.$i, html_entity_decode($product['name'], ENT_QUOTES));
$sheet->getStyle('A'.$i)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT);
$sheet->setCellValue('B'.$i, $product['sku']);
$sheet->getStyle('B'.$i)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT);
Expand All @@ -124,8 +130,17 @@ public function overview(Request $request, bool $onlyActive=true): Response
$sheet->getStyle('C'.$i)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER);
$sheet->setCellValue('D'.$i, $stock[AccountModel::PRE_ORDER_TYPE]['balance']);
$sheet->getStyle('D'.$i)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER);
$sheet->setCellValue('E'.$i, $product['isostock_minimun_stock']);
$sheet->getStyle('E'.$i)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER);
if ($stock[AccountModel::STOCK_TYPE]['balance'] < $product['isostock_minimun_stock'] && $product['isostock_minimun_stock'] > 0) {
$sheet->getStyle('A'.$i)->getFont()->setColor(new Color(Color::COLOR_RED));
$sheet->getStyle('B'.$i)->getFont()->setColor(new Color(Color::COLOR_RED));
$sheet->getStyle('C'.$i)->getFont()->setColor(new Color(Color::COLOR_RED));
$sheet->getStyle('D'.$i)->getFont()->setColor(new Color(Color::COLOR_RED));
$sheet->getStyle('E'.$i)->getFont()->setColor(new Color(Color::COLOR_RED));
}

$column = 'E';
$column = 'F';
$stockPerAccount = ProductHelper::getProductStockPerAccount($product['id']);
foreach($accounts as $account) {
if (isset($stockPerAccount[$account->id]) && isset ($stockPerAccount[$account->id]['balance'])) {
Expand Down
10 changes: 10 additions & 0 deletions src/Resources/contao/dca/tl_iso_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@
'eval' => array('tl_class'=>'w50', 'submitOnChange' => true),
'attributes' => array( 'legend'=>'isostock_legend' ),
'sql' => "char(1) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_iso_product']['fields']['isostock_minimun_stock'] = [
'inputType' => 'text',
'eval' => array('doNotCopy'=>true, 'rgxp' => 'natural', 'tl_class' => 'w50' ),
'attributes' => array( 'legend'=>'isostock_legend' ),
'sql' => "int(10) unsigned NOT NULL default 0",
'flag' => 11,
'default' => '0',
'filter' => true,
];
1 change: 1 addition & 0 deletions src/Resources/contao/languages/en/tl_iso_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
$GLOBALS['TL_LANG']['tl_iso_product']['stock'] = 'View Stock';
$GLOBALS['TL_LANG']['tl_iso_product']['isostock_legend'] = 'Isotope Stock';
$GLOBALS['TL_LANG']['tl_iso_product']['isostock_preorder'] = ['Product Pre-Order', 'The Product is available for pre-order.'];
$GLOBALS['TL_LANG']['tl_iso_product']['isostock_minimun_stock'] = ['Minimum Stock', ''];
$GLOBALS['TL_LANG']['tl_isotope_prodocut']['stock_report'] ='Stock Report';
$GLOBALS['TL_LANG']['tl_isotope_prodocut']['stock_report_all'] ='Stock Report (include inactive)';
1 change: 1 addition & 0 deletions src/Resources/contao/languages/nl/tl_iso_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
$GLOBALS['TL_LANG']['tl_iso_product']['stock'] = 'Bekijk voorraad';
$GLOBALS['TL_LANG']['tl_iso_product']['isostock_legend'] = 'Isotope Voorraad';
$GLOBALS['TL_LANG']['tl_iso_product']['isostock_preorder'] = ['Product Pre-Order', 'Is beschikbaar voor Pre-Order.'];
$GLOBALS['TL_LANG']['tl_iso_product']['isostock_minimun_stock'] = ['Minimale Voorraad', ''];
$GLOBALS['TL_LANG']['tl_isotope_prodocut']['stock_report'] ='Voorraad rapport';
$GLOBALS['TL_LANG']['tl_isotope_prodocut']['stock_report_all'] ='Voorraad rapport (inclusief inactieve)';

0 comments on commit 313310d

Please sign in to comment.