-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#19 [Hook] add: Priseo field on selling price
- Loading branch information
1 parent
2c5573f
commit 5e2d378
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
/* Copyright (C) 2024 EOXIA <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* \file class/actions_priseo.class.php | ||
* \ingroup priseo | ||
* \brief Priseo hook overload | ||
*/ | ||
|
||
// Load Dolibarr librairies | ||
require_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php'; | ||
|
||
// Load Saturne libraries | ||
require_once DOL_DOCUMENT_ROOT . '/custom/saturne/lib/object.lib.php'; | ||
|
||
require_once 'competitorprice.class.php'; | ||
|
||
/** | ||
* Class ActionsPriseo | ||
*/ | ||
class ActionsPriseo { | ||
/** | ||
* @var DoliDB Database handler | ||
*/ | ||
public $db; | ||
|
||
/** | ||
* @var string Error string | ||
*/ | ||
public $error; | ||
|
||
/** | ||
* @var string[] Array of error strings | ||
*/ | ||
public $errors = []; | ||
|
||
/** | ||
* @var array Hook results. Propagated to $hookmanager->resArray for later reuse | ||
*/ | ||
public $results = []; | ||
|
||
/** | ||
* @var string String displayed by executeHook() immediately after return | ||
*/ | ||
public $resprints; | ||
|
||
/** | ||
* @var string Module name | ||
*/ | ||
public $moduleName = 'Priseo'; | ||
|
||
|
||
/** | ||
* Constructor | ||
* | ||
* @param DoliDB $db Database handler | ||
*/ | ||
public function __construct($db) | ||
{ | ||
$this->db = $db; | ||
} | ||
|
||
/** | ||
* Overloading the printCommonFooter function : replacing the parent's function with the one below | ||
* | ||
* @param array $parameters Hook metadatas (context, etc...) | ||
* @return int < 0 on error, 0 on success, 1 to replace standard code | ||
*/ | ||
public function printCommonFooter($parameters) | ||
{ | ||
global $db, $object; | ||
|
||
if ($parameters['currentcontext'] == 'productpricecard') { | ||
$Priseo = new CompetitorPrice($db); | ||
|
||
$prices = $Priseo->fetchAll('DESC','amount_ht',0,0, ['customsql' => 't.status >= ' . $Priseo::STATUS_DRAFT . ' AND t.fk_product = ' . $object->id]); | ||
if (is_array($prices) && !empty($prices)) { | ||
$maxPrices = array_shift($prices); | ||
$minPrices = end($prices); | ||
|
||
$out = '<tr><td>'; | ||
$out .= $this->moduleName . ' (' . $object->date_creation . ') </td><td>'; | ||
$out .= $object->price < $minPrices->amount_ht ? price($object->price, 0, '', 1, -1, -1, 'auto') : price($minPrices->amount_ht, 0, '', 1, -1, -1, 'auto'); | ||
$out .= ' <= ' . price($object->price, 0, '', 1, -1, -1, 'auto') . ' <= '; | ||
$out .= $maxPrices->amount_ht < $object->price ? price($object->price, 0, '', 1, -1, -1, 'auto') : price($maxPrices->amount_ht, 0, '', 1, -1, -1, 'auto'); | ||
$out .= '</td></tr>'; | ||
?> | ||
<script> | ||
jQuery('.field_min_price').after(<?php echo json_encode($out); ?>); | ||
</script> | ||
<?php | ||
} | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters