Skip to content

Commit

Permalink
Update after testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapjansma committed Mar 31, 2022
1 parent a25cb57 commit a5269a4
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 33 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.0",
"version": "1.0.1",
"require": {
"contao/core-bundle": "^4.9",
"isotope/isotope-core": "^2.6",
Expand Down
16 changes: 12 additions & 4 deletions src/Controller/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,21 @@ public function massBooking(Request $request): Response
$booking->type = $data['type'];
$booking->save();
$debitBookingLine = new BookingLineModel();
$debitBookingLine->debit = $product_id['quantity'];
$debitBookingLine->account = $data['debit_account']->id;
$debitBookingLine->debit = abs($product_id['quantity']);
if ($product_id['quantity'] >= 0) {
$debitBookingLine->account = $data['debit_account']->id;
} else {
$debitBookingLine->account = $data['credit_account']->id;
}
$debitBookingLine->pid = $booking->id;
$debitBookingLine->save();
$creditBookingLine = new BookingLineModel();
$creditBookingLine->credit = $product_id['quantity'];
$creditBookingLine->account = $data['credit_account']->id;
$creditBookingLine->credit = abs($product_id['quantity']);
if ($product_id['quantity'] >= 0) {
$creditBookingLine->account = $data['credit_account']->id;
} else {
$creditBookingLine->account = $data['debit_account']->id;
}
$creditBookingLine->pid = $booking->id;
$creditBookingLine->save();
BookingHelper::updateBalanceStatusForBooking($booking->id);
Expand Down
12 changes: 0 additions & 12 deletions src/Resources/contao/dca/tl_iso_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,10 @@
'button_callback' => [ProductListener::class, 'stockButtonCallback']
];

$GLOBALS['TL_DCA']['tl_iso_product']['palettes']['__selector__'][] = 'isostock_preorder';
$GLOBALS['TL_DCA']['tl_iso_product']['subpalettes']['isostock_preorder'] = 'isostock_preorder_date';

$GLOBALS['TL_DCA']['tl_iso_product']['fields']['isostock_preorder'] = [
'filter' => true,
'inputType' => 'checkbox',
'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_preorder_date'] = [
'inputType' => 'text',
'flag' => 8,
'default' => time(),
'eval' => array('mandatory'=>true, 'rgxp'=>'date', 'datepicker'=>true, 'tl_class'=>'w50 wizard'),
//'attributes' => array( 'legend'=>'isostock_legend' ),
'sql' => "varchar(10) NOT NULL default ''"
];
41 changes: 34 additions & 7 deletions src/Resources/contao/dca/tl_isotope_stock_booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@
(
'mode' => 1,
'fields' => array('date','tstamp'),
'flag' => 8,
'flag' => 12,
'panelLayout' => 'sort,filter,search,limit'
),
'label' => array
(
'fields' => array('description', 'type'),
'showColumns' => true,
'fields' => array('description', 'type', 'date', 'product_count', 'product_id', 'order_id'),
'label_callback' => array('tl_isotope_stock_booking', 'generateLabel')
),
'global_operations' => array
Expand Down Expand Up @@ -150,10 +151,15 @@
'sql' => "int(10) unsigned NOT NULL default 0",
'default' => '0',
),
'product_count' => array
(
),
'product_id' => array
(
'inputType' => 'tableLookup',
'sql' => "int(10) unsigned NOT NULL default 0",
'filter' => true,
'foreignKey' => \Isotope\Model\Product::getTable().'.CONCAT(name, \' \', sku)',
'eval' => array
(
'mandatory' => true,
Expand Down Expand Up @@ -252,17 +258,38 @@ public function periodOptions() {
*
* @return string
*/
public function generateLabel($arrData, $strLabel, \Contao\DataContainer $dc, $arrColumns) {
public function generateLabel($arrData, string $label, \Contao\DataContainer $dc, $labels) {
$fields = $GLOBALS['TL_DCA'][$dc->table]['list']['label']['fields'];
$description_key = array_search('description', $fields, true);
$product_count_key = array_search('product_count', $fields, true);
$product_id_key = array_search('product_id', $fields, true);
$order_id_key = array_search('order_id', $fields, true);
$balanceLabel = $GLOBALS['TL_LANG']['tl_isotope_stock_booking']['in_balance'];
$balanceIcon = 'ok.gif';
if (empty($arrData['is_in_balance'])) {
$balanceLabel = $GLOBALS['TL_LANG']['tl_isotope_stock_booking']['not_in_balance'];
$balanceIcon = 'error.gif';
}
$strLabel = \Image::getHtml($balanceIcon, $balanceLabel, 'title="'.$balanceLabel.'"') . ' ' . $strLabel;
$type = $arrData['type'];
$strLabel .= ' - '.$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['type_options'][$type];
return $strLabel;
$bookingLines = \Krabo\IsotopeStockBundle\Model\BookingLineModel::findBy('pid', $arrData['id']);
$debit = 0;
if ($bookingLines && $bookingLines->count()) {
foreach ($bookingLines as $bookingLine) {
$debit += $bookingLine->debit;
}
}
$labels[$product_count_key] = $debit;
if ($labels[$product_id_key]) {
$objProduct = \Isotope\Model\Product::findByPk($labels[$product_id_key]);
$labels[$product_id_key] = $objProduct->name;
}
if (!empty($labels[$order_id_key])) {
$objOrder = \Isotope\Model\ProductCollection\Order::findByPk($labels[$order_id_key]);
$labels[$order_id_key] = $objOrder->document_number;
} else {
$labels[$order_id_key] = '';
}
$labels[$description_key] = \Image::getHtml($balanceIcon, $balanceLabel, 'title="'.$balanceLabel.'"') . ' ' . $labels[$description_key];
return $labels;
}

}
6 changes: 3 additions & 3 deletions src/Resources/contao/dca/tl_isotope_stock_booking_line.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ public function listBookingLines($arrRow) {
public function headerFields($arrRow, \Contao\DataContainer $dc) {
\Contao\System::loadLanguageFile(\Isotope\Model\Product::getTable());
$productIdField = $GLOBALS['TL_LANG']['tl_isotope_stock_booking']['product_id'][0];
$objProduct = Product::findByPk($arrRow[$productIdField]);
$booking = \Krabo\IsotopeStockBundle\Model\BookingModel::findByPk($dc->id);
$objProduct = Product::findByPk($booking->product_id);
$stockButton = ProductHelper::genereateStockButtonLink($objProduct->id);
$editUrl = \Contao\DataContainer::addToUrl('do=iso_products&table=tl_iso_product&act=edit&id='.$objProduct->id);
$editIcon = Image::getHtml('edit.gif', $GLOBALS['TL_LANG']['tl_iso_product']['edit'][0]);
$editButton = '<a href="'.$editUrl.'">' . $editIcon . '</a>';
$label = $objProduct->name . ' (' . $objProduct->sku.')';
$arrRow[$productIdField] = $label .'&nbsp;' . $editButton . '&nbsp;' . $stockButton;
$arrRow[$productIdField] .= '&nbsp;' . $editButton . '&nbsp;' . $stockButton;

$balanceLabel = $GLOBALS['TL_LANG']['tl_isotope_stock_booking']['in_balance'];
$balanceIcon = 'ok.gif';
Expand Down
3 changes: 1 addition & 2 deletions src/Resources/contao/languages/en/tl_iso_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@

$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_preorder_date'] = ['Product available at', 'The product will be available at'];
$GLOBALS['TL_LANG']['tl_iso_product']['isostock_preorder'] = ['Product Pre-Order', 'The Product is available for pre-order.'];
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type'] = ['Type', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type_options']['1'] = 'Stock';
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type_options']['2'] = 'Pre-Order';
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type_options']['3'] = 'Balance';
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type_options']['3'] = 'Other';
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['date'] = ['Date', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['period_id'] = ['Period', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['product_legend'] = 'Product';
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['product_count'] = ['Product couunt', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['product_id'] = ['Product', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['order_id'] = ['Order', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['order_legend'] = 'Order';
Expand Down
3 changes: 1 addition & 2 deletions src/Resources/contao/languages/nl/tl_iso_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@

$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_preorder_date'] = ['Product beschikbaar op', 'Wordt geleverd vanaf'];
$GLOBALS['TL_LANG']['tl_iso_product']['isostock_preorder'] = ['Product Pre-Order', 'Is beschikbaar voor Pre-Order.'];
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type'] = ['Type', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type_options']['1'] = 'Voorraad';
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type_options']['2'] = 'Pre-Order';
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type_options']['3'] = 'Balans';
$GLOBALS['TL_LANG']['tl_isotope_stock_account']['type_options']['3'] = 'Overig';
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['date'] = ['Datum', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['period_id'] = ['Periode', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['product_legend'] = 'Product';
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['product_count'] = ['Aantal', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['product_id'] = ['Product', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['order_id'] = ['Bestelling', ''];
$GLOBALS['TL_LANG']['tl_isotope_stock_booking']['order_legend'] = 'Bestelling';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div class="clear"></div>
<br />
{% set index = 0 %}
{% set balance = 0 %}
<table class="tl_listing showColumns">
<tr>
<th class="tl_folder_tlist">
Expand Down Expand Up @@ -45,12 +46,18 @@
{% endif %}
{% endfor %}
{% set index = index + 1 %}
{% set balance = balance + type.balance %}
<tr class="{% if index is odd %}odd{% endif %}">
<td class="tl_file_list">&nbsp;</td>
<td class="tl_file_list tl_right_nowrap" colspan="2"><strong>{{ type.label }}</strong></td>
<td class="tl_file_list tl_right_nowrap"><strong>{{ type.balance }}</strong></td>
</tr>
{% endfor %}
<tr class="{% if index is odd %}odd{% endif %}">
<td class="tl_file_list">&nbsp;</td>
<td class="tl_file_list tl_right_nowrap" colspan="2"><strong>{{ 'IstotopeStockProductInfo.Balance'|trans({}, 'contao_default') }}</strong></td>
<td class="tl_file_list tl_right_nowrap"><strong>{{ balance }}</strong></td>
</tr>
</table>
</div>
<div class="tl_formbody_submit">
Expand Down

0 comments on commit a5269a4

Please sign in to comment.