Merge branch 'develop' of gitlab.antadis.net:dev-antadis/bebeboutik into develop
This commit is contained in:
commit
28d05025da
@ -178,6 +178,27 @@ class AdminOrders extends AdminTab
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif(Tools::isSubmit('submitSupplierDemand')) {
|
||||||
|
$id_order = (int) Tools::getValue('id_order');
|
||||||
|
$id_order_detail = (int) Tools::getValue('id_order_detail');
|
||||||
|
$qty = (int) Tools::getValue('qty');
|
||||||
|
if($qty!==0 && $id_order_detail && $id_order) {
|
||||||
|
if(!class_exists('SupplierDemand')){
|
||||||
|
require_once(_PS_MODULE_DIR_.'ant_supplierdemand/models/SupplierDemand.php');
|
||||||
|
}
|
||||||
|
$supplierDemand = new SupplierDemand();
|
||||||
|
$supplierDemand->id_order = $id_order;
|
||||||
|
$supplierDemand->id_order_detail = $id_order_detail;
|
||||||
|
$supplierDemand->qty = $qty;
|
||||||
|
$supplierDemand->id_state = 1;
|
||||||
|
$supplierDemand->comment = Tools::getValue('demand_comment');
|
||||||
|
if($supplierDemand->save()){
|
||||||
|
SupplierDemand::addHistoryStatic($supplierDemand->id,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
header('Location: '.$_SERVER['REQUEST_URI']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
elseif(Tools::isSubmit('submitCreateReturn')) {
|
elseif(Tools::isSubmit('submitCreateReturn')) {
|
||||||
$id_order = (int) Tools::getValue('id_order');
|
$id_order = (int) Tools::getValue('id_order');
|
||||||
if(Validate::isLoadedObject($order = new Order($id_order)) && ($address_delivery = Db::getInstance()->getRow('
|
if(Validate::isLoadedObject($order = new Order($id_order)) && ($address_delivery = Db::getInstance()->getRow('
|
||||||
@ -1677,6 +1698,59 @@ class AdminOrders extends AdminTab
|
|||||||
}
|
}
|
||||||
echo '</fieldset>';
|
echo '</fieldset>';
|
||||||
|
|
||||||
|
// @Override Antadis - Supplier demand
|
||||||
|
if(!class_exists('SupplierDemand')){
|
||||||
|
require_once(_PS_MODULE_DIR_.'ant_supplierdemand/models/SupplierDemand.php');
|
||||||
|
}
|
||||||
|
$supplierDemands = SupplierDemand::getDemands(array(),'sd.id_order='.$order->id);
|
||||||
|
echo '<br/>
|
||||||
|
<fieldset style="width: 400px;">
|
||||||
|
<legend><img src="../img/admin/return.gif" alt="'.$this->l('Supplier demands').'" />'.$this->l('Supplier demands').'</legend>';
|
||||||
|
if (!sizeof($supplierDemands)) {
|
||||||
|
echo $this->l('No Supplier demands for this order.');
|
||||||
|
} else {
|
||||||
|
$alreadyDemand = array();
|
||||||
|
$demand_product = 0;
|
||||||
|
foreach ($supplierDemands as $demand) {
|
||||||
|
$alreadyDemand[] = $demand['id_order_detail'];
|
||||||
|
$demandStates = SupplierDemand::$states;
|
||||||
|
echo '('.Tools::displayDate($demand['date_upd'], $cookie->id_lang).') :
|
||||||
|
<b><a href="index.php?tab=AdminAntSupplierDemand&id='.$demand['id_supplier_demand'].'&updateSupplierDemand=1&token='.Tools::getAdminToken('AdminAntSupplierDemand'.(int)(Tab::getIdFromClassName('AdminAntSupplierDemand')).(int)($cookie->id_employee)).'">'.$this->l('#').sprintf('%06d', $demand['id_supplier_demand']).'</a></b> -
|
||||||
|
'.$demandStates[$demand['id_state']]['name'].'<br />';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo '<br /><br />
|
||||||
|
<h4>'.$this->l('Make a supplier demand').'</h4>
|
||||||
|
<form id="new_supplier_demand" action="" method="post">
|
||||||
|
<p>
|
||||||
|
<label style="width: auto; margin-bottom: 5px;">'.$this->l('Product').'</label>
|
||||||
|
<select name="id_order_detail">';
|
||||||
|
foreach($products as $product) {
|
||||||
|
if(in_array($product['id_order_detail'],$alreadyDemand)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$demand_product++;
|
||||||
|
echo '<option value="'.$product['id_order_detail'].'">'.$product['product_name'].'</option>';
|
||||||
|
}
|
||||||
|
echo '</select>
|
||||||
|
</p>';
|
||||||
|
if($demand_product==0){
|
||||||
|
echo '<p class="warning">'.$this->l('All products are in demand').'</p>';
|
||||||
|
} else {
|
||||||
|
echo '<p>
|
||||||
|
<label style="width: auto; margin-bottom: 5px;">'.$this->l('Quantity').'</label>
|
||||||
|
<input type="number" name="qty" value="0"/>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label style="width: auto; margin-bottom: 5px;">'.$this->l('Insert a comment (optional):').'</label>
|
||||||
|
<textarea name="demand_comment" rows="5" cols="50" style="resize: vertical"></textarea>
|
||||||
|
</p>
|
||||||
|
<input type="hidden" value="'.$order->id.'" name="id_order/>
|
||||||
|
<p class="submit"><input type="submit" value="'.$this->l('Confirm').'" name="submitSupplierDemand" class="button" /></p>';
|
||||||
|
}
|
||||||
|
echo '</form>
|
||||||
|
</fieldset>';
|
||||||
|
|
||||||
/* Display credit slip */
|
/* Display credit slip */
|
||||||
echo '
|
echo '
|
||||||
<br />
|
<br />
|
||||||
|
384
modules/ant_supplierdemand/AdminAntSupplierDemand.php
Normal file
384
modules/ant_supplierdemand/AdminAntSupplierDemand.php
Normal file
@ -0,0 +1,384 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once(_PS_MODULE_DIR_.'/ant_supplierdemand/models/SupplierDemand.php');
|
||||||
|
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
|
||||||
|
|
||||||
|
class AdminAntSupplierDemand extends AdminTab
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $_html;
|
||||||
|
public $module_name;
|
||||||
|
public $config_tab;
|
||||||
|
public $controller;
|
||||||
|
public $helperForm;
|
||||||
|
public $_object;
|
||||||
|
|
||||||
|
public function __construct($config_tab = true)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->_object = false;
|
||||||
|
$this->controller = 'AdminModules';
|
||||||
|
$this->module_name = 'ant_supplierdemand';
|
||||||
|
$this->config_tab = (bool)$config_tab;
|
||||||
|
if ($config_tab) {
|
||||||
|
$this->controller = 'AdminAntSupplierDemand';
|
||||||
|
}
|
||||||
|
$this->helperForm = new HelperFormBootstrap();
|
||||||
|
$this->helperForm->_select2 = true;
|
||||||
|
$this->helperForm->_inputMask = true;
|
||||||
|
$this->helperForm->_dateTimePicker = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function display()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->_html = '';
|
||||||
|
|
||||||
|
$this->_postProcess();
|
||||||
|
|
||||||
|
$this->_addCss();
|
||||||
|
$this->_html .= $this->helperForm->renderStyle();
|
||||||
|
|
||||||
|
if(Validate::isLoadedObject($this->_object)) {
|
||||||
|
$this->_displayView();
|
||||||
|
} else {
|
||||||
|
$this->_displayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_html .='<div class="clearfix"></div>';
|
||||||
|
$this->_addJs();
|
||||||
|
$this->_html .= $this->helperForm->renderScript();
|
||||||
|
|
||||||
|
echo $this->_html;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _addJs()
|
||||||
|
{
|
||||||
|
$this->helperForm->_js .= '<script type="text/javascript">
|
||||||
|
$("#hasDatepicker_1").datetimepicker({
|
||||||
|
format: "DD/MM/YYYY",
|
||||||
|
widgetPositioning : {
|
||||||
|
horizontal: "auto",
|
||||||
|
vertical: "bottom"
|
||||||
|
},
|
||||||
|
locale:"fr"
|
||||||
|
});
|
||||||
|
$("#hasDatepicker_2").datetimepicker({
|
||||||
|
format: "DD/MM/YYYY",
|
||||||
|
widgetPositioning : {
|
||||||
|
horizontal: "auto",
|
||||||
|
vertical: "bottom"
|
||||||
|
},
|
||||||
|
locale:"fr"
|
||||||
|
});
|
||||||
|
</script>';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _addCss()
|
||||||
|
{
|
||||||
|
$this->helperForm->_css .='
|
||||||
|
#content .bootstrap-datetimepicker-widget tr th {
|
||||||
|
border-radius :0px !important;
|
||||||
|
}
|
||||||
|
.table tr th {
|
||||||
|
background: #565485;
|
||||||
|
background: rgba(86,84,133,0.9);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.table tr:nth-child(even) {
|
||||||
|
background: #F1F1F1;
|
||||||
|
}
|
||||||
|
.table>tbody>tr>td,
|
||||||
|
.table>tbody>tr>th,
|
||||||
|
.table>tfoot>tr>td,
|
||||||
|
.table>tfoot>tr>th,
|
||||||
|
.table>thead>tr>td,
|
||||||
|
.table>thead>tr>th {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
.table .input-group-btn .btn {
|
||||||
|
padding: 4px 5px;
|
||||||
|
color: #504d8b;
|
||||||
|
|
||||||
|
}
|
||||||
|
.table .input-group-btn .btn .anticon{
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.bg-grey{
|
||||||
|
background: #EFEFEF;
|
||||||
|
border-radius:4px;
|
||||||
|
}
|
||||||
|
.bg-grey .div-title {
|
||||||
|
border-bottom: 2px solid #504D8B;
|
||||||
|
}
|
||||||
|
.div-title i.anticon,
|
||||||
|
.div-title i.glyphicon,
|
||||||
|
ul li a{
|
||||||
|
color:#504d8b;
|
||||||
|
}
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _displayList()
|
||||||
|
{
|
||||||
|
global $cookie, $currentIndex;
|
||||||
|
|
||||||
|
$id_lang = (int)$cookie->id_lang;
|
||||||
|
|
||||||
|
if(Tools::getValue('from') && Tools::getValue('to') && Tools::getValue('filter')){
|
||||||
|
$datefrom = DateTime::createFromFormat('d/m/Y', Tools::getValue('from'));
|
||||||
|
$dateto = DateTime::createFromFormat('d/m/Y', Tools::getValue('to'));
|
||||||
|
$supplier_demands = SupplierDemand::getDemands(false,
|
||||||
|
'sd.date_add > "'.$datefrom->format('Y-m-d').' 00:00:00" AND sd.date_add < "'.$dateto->format('Y-m-d').' 23:59:59" ORDER BY sd.date_add DESC'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$supplier_demands = SupplierDemand::getDemands();
|
||||||
|
}
|
||||||
|
$states = SupplierDemand::$states;
|
||||||
|
$_current_index = ($this->config_tab ? $currentIndex . '&token=' . Tools::getAdminTokenLite($this->controller) : $_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
|
$this->_html .='
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-title">
|
||||||
|
<h2><span class="text-rose anticon anticon-list"></span> '.$this->l('Liste des demandes fournisseurs').'</h2>
|
||||||
|
<div class="col-lg-4 pull-right">
|
||||||
|
<form method="POST" action="'.$_current_index.'&filter=1">
|
||||||
|
<div class="input-group input-group-sm">
|
||||||
|
<span class="input-group-addon"><i class="anticon anticon-calendar"></i></span>
|
||||||
|
<input type="text" class="form-control input-sm" id="hasDatepicker_1" name="from" value="'.(Tools::getValue('from')?Tools::getValue('from'):'').'">
|
||||||
|
<span class="input-group-addon">au</span>
|
||||||
|
<input type="text" class="form-control input-sm" id="hasDatepicker_2" name="to" value="'.(Tools::getValue('to')?Tools::getValue('to'):'').'">
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-default" type="sumbit">Go!</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<div class="panel-content">
|
||||||
|
<table class="table table-custombordered" style="width: 100%;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="text-left">'.$this->l('ID').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Order').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Status').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Date').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Renewed').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Action').'</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>';
|
||||||
|
foreach ($supplier_demands as $supplier_demand)
|
||||||
|
{
|
||||||
|
$renews_number = SupplierDemand::getCountRenews((int)$supplier_demand['id_supplier_demand']);
|
||||||
|
$this->_html .='
|
||||||
|
<tr>
|
||||||
|
<td valign="middle" align="left">#'.$supplier_demand['id_supplier_demand'].'</td>
|
||||||
|
<td valign="middle" align="center"><b>N° '.$supplier_demand['id_order'].'</b></td>
|
||||||
|
<td valign="middle" align="center"><span class="'.$states[$supplier_demand['id_state']]['icon'].'"></span> '.$states[$supplier_demand['id_state']]['name'].'</td>
|
||||||
|
<td valign="middle" align="center">'.date('d/m/Y',strtotime($supplier_demand['date_add'])).'</td>
|
||||||
|
<td valign="middle" align="center">'.($renews_number>1?'<span class="label label-danger">'.$renews_number.'</span>':'<span class="label label-default">'.$renews_number.'</span>').'</td>
|
||||||
|
<td valign="middle" align="center">
|
||||||
|
<div class="input-group-btn" role="group" aria-label="...">
|
||||||
|
<a href="'.$_current_index.'&updateSupplierDemand=1&id='.$supplier_demand['id_supplier_demand'].'" class="btn btn-default"><span class="anticon anticon-pencil2"></span></a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>';
|
||||||
|
}
|
||||||
|
$this->_html .='
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _displayView()
|
||||||
|
{
|
||||||
|
global $cookie, $currentIndex;
|
||||||
|
$_current_index = ($this->config_tab ? $currentIndex . '&token=' . Tools::getAdminTokenLite($this->controller) : $_SERVER['REQUEST_URI']);
|
||||||
|
$states = SupplierDemand::$states;
|
||||||
|
$customer = SupplierDemand::getCustomer($this->_object->id);
|
||||||
|
$histories = SupplierDemand::getHistoryStatic($this->_object->id);
|
||||||
|
$product = SupplierDemand::getProductStatic($this->_object->id);
|
||||||
|
$img = Db::getInstance()->getRow('
|
||||||
|
SELECT id_image
|
||||||
|
FROM `'._DB_PREFIX_.'image` i
|
||||||
|
WHERE i.`id_product` = '.(int)$product['product_id'].'
|
||||||
|
AND i.`cover` = 1'
|
||||||
|
);
|
||||||
|
if (isset($img['id_image']) && !empty($img['id_image'])) {
|
||||||
|
$image_obj = new Image((int)$img['id_image']);
|
||||||
|
$img_path = (isset($image_obj)?$image_obj->getExistingImgPath():'');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_html .='
|
||||||
|
<div class="modal fade" tabindex="-1" role="dialog" id="commentModal">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<form action="'.$_current_index.'&updateSupplierDemand=1&id='.$this->_object->id.'" method="post">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
<h4 class="modal-title">Modifier le commentaire</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<input type="hidden" value="'.$this->_object->id.'" id="id_supplier_demand" name="id_supplier_demand">
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<textarea class="form-control" rows="4" name="comment">'.($this->_object->comment!==null?$this->_object->comment:'').'</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
|
||||||
|
<button type="submit" class="btn btn-primary" name="editSupplierDemand">Enregistrer</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-12">
|
||||||
|
<p><a class="btn btn-default" href="'.$_current_index.'"><span class="anticon anticon-arrow-left2"></span> '.$this->l('Back to list').'</a></p>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-title">
|
||||||
|
<h2><i class="text-rose anticon anticon-folder-open"></i> '.$this->l('Demande #').$this->_object->id.'</h2>
|
||||||
|
<span class="pull-right" style="margin-top:5px;"><i class="'.$states[$this->_object->id_state]['icon'].'"></i> '.$states[$this->_object->id_state]['name'].'</span>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<div class="panel-content">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="thumbnail">
|
||||||
|
<img src="'.(isset($img_path)?_THEME_PROD_DIR_.$img_path.'-product_carre.jpg"':'').'" width="200px">
|
||||||
|
<p class="text-center">'.$product['product_name'].'</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="col-md-12 bg-grey">
|
||||||
|
<div class="div-title">
|
||||||
|
<h4><span class="anticon anticon-bubble2"></span> '.$this->l('Comment').'</h4>
|
||||||
|
<a style="cursor:pointer;margin-top: 8px;" class="pull-right" data-toggle="modal" data-target="#commentModal"><i class="glyphicon glyphicon-edit"></i></a>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<p>'.($this->_object->comment!==null?nl2br($this->_object->comment):'No comment').'</p>
|
||||||
|
<p></p>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
<br>
|
||||||
|
<div class="col-md-12 bg-grey">
|
||||||
|
<div class="div-title">
|
||||||
|
<h4><span class="anticon anticon-info"></span> '.$this->l('Informations').'</h4>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<ul class="list-unstyled">
|
||||||
|
<li><i class="anticon anticon-user"></i> <a target="_blank" href="?tab=AdminCustomers&viewcustomer&id_customer='.$customer['id_customer'].'&token='.(Tools::getAdminTokenLite('AdminCustomers')).'">'.$customer['firstname'].' '.$customer['lastname'].'</a></li>
|
||||||
|
<li><i class="anticon anticon-cart"></i> <a target="_blank" href="?tab=AdminOrders&id_order='.(int)$this->_object->id_order.'&vieworder&token='.(Tools::getAdminTokenLite('AdminOrders')).'">N°'.$this->_object->id_order.'</a></li>
|
||||||
|
</ul>
|
||||||
|
<p></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-title">
|
||||||
|
<h2>'.$this->l('Status').'</h2>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<div class="panel-content">';
|
||||||
|
if(isset($histories)){
|
||||||
|
$this->_html .='
|
||||||
|
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">
|
||||||
|
'.$this->l('History').'
|
||||||
|
<a class="pull-right" style="color:#fff;" role="button" data-toggle="collapse" href="#collapseHistory" aria-expanded="false" aria-controls="collapseHistory">
|
||||||
|
<i class="anticon anticon-info"></i>
|
||||||
|
</a>
|
||||||
|
</h5>
|
||||||
|
<p class="text-center">
|
||||||
|
<b>'.$states[$histories[0]['id_state']]['name'].' <span style="font-size:24px;" class="'.$states[$histories[0]['id_state']]['icon'].'"></span></b><br>('.$histories[0]['employee'].' - '.date('d/m/Y H:i',strtotime($histories[0]['date_add'])).')
|
||||||
|
</p>
|
||||||
|
<div class="collapse" id="collapseHistory">
|
||||||
|
<div class="bg-grey">
|
||||||
|
<table class="table">
|
||||||
|
<tbody>';
|
||||||
|
foreach($histories as $history){
|
||||||
|
$this->_html .='
|
||||||
|
<tr>
|
||||||
|
<td style="font-size:11px;">'.date('d/m/Y H:i',strtotime($history['date_add'])).'</td>
|
||||||
|
<td style="font-size:11px;font-weight:bold">'.$states[$history['id_state']]['name'].'</td>
|
||||||
|
<td style="font-size:11px;">'.$history['employee'].'</td>
|
||||||
|
</tr>';
|
||||||
|
}
|
||||||
|
$this->_html .='
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
$this->_html.='
|
||||||
|
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">
|
||||||
|
'.$this->l('Update Status').'
|
||||||
|
</h5>
|
||||||
|
<form style="padding:10px 20px;background:#efefef;" action="'.$_current_index.'&updateSupplierDemand=1&id='.$this->_object->id.'" method="post">
|
||||||
|
<input type="hidden" name="id_supplier_demand" value="'.$this->_object->id.'" />
|
||||||
|
<div class="form-group">
|
||||||
|
<select class="form-control" name="id_state">';
|
||||||
|
foreach ($states as $key => $state) {
|
||||||
|
$this->_html .= '<option value="'.$key.'"'.($this->_object->id_state == $key ? ' selected="selected"' : '').'>'.$state['name'].'</option>';
|
||||||
|
}
|
||||||
|
$this->_html.='</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="submit" class="btn btn-primary btn-block" name="updateStateDemand" value="Mettre à jour">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _postProcess()
|
||||||
|
{
|
||||||
|
if (Tools::isSubmit('addSupplierDemand')) {
|
||||||
|
$this->_html .= $this->_addOrUpdateGroup(false);
|
||||||
|
} elseif (Tools::getValue('id') && Tools::getValue('updateSupplierDemand')) {
|
||||||
|
if (Tools::isSubmit('editSupplierDemand') || Tools::isSubmit('updateStateDemand')) {
|
||||||
|
$this->_html .= $this->_addOrUpdateGroup(true);
|
||||||
|
}
|
||||||
|
$this->_object = new SupplierDemand((int)Tools::getValue('id'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _addOrUpdateGroup($edit = false)
|
||||||
|
{
|
||||||
|
if ($edit && Tools::getValue('id_supplier_demand')) {
|
||||||
|
$supplierDemand = new SupplierDemand((int)Tools::getValue('id_supplier_demand'));
|
||||||
|
if(Tools::getValue('comment')){
|
||||||
|
$supplierDemand->comment = Tools::getValue('comment');
|
||||||
|
}
|
||||||
|
if(Tools::getValue('id_state')){
|
||||||
|
$supplierDemand->id_state = (int)Tools::getValue('id_state');
|
||||||
|
$supplierDemand->addHistory();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$supplierDemand = new SupplierDemand();
|
||||||
|
$supplierDemand->id_order = (int)Tools::getValue('id_order');
|
||||||
|
$supplierDemand->id_order_state = (int)Tools::getValue('id_order_state');
|
||||||
|
$supplierDemand->qty = (int)Tools::getValue('qty');
|
||||||
|
$supplierDemand->comment = Tools::getValue('comment');
|
||||||
|
$supplierDemand->id_state = 1;
|
||||||
|
}
|
||||||
|
if ($supplierDemand->save()) {
|
||||||
|
return HelperFormBootstrap::displaySuccess($this->l('Demand has been created'));
|
||||||
|
} else {
|
||||||
|
return HelperFormBootstrap::displayError($this->l('Error occured while creating demand'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
80
modules/ant_supplierdemand/ant_supplierdemand.php
Normal file
80
modules/ant_supplierdemand/ant_supplierdemand.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('_PS_VERSION_'))
|
||||||
|
exit;
|
||||||
|
|
||||||
|
class Ant_Supplierdemand extends Module
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->name = 'ant_supplierdemand';
|
||||||
|
$this->tab = 'administration';
|
||||||
|
$this->author = 'Antadis';
|
||||||
|
$this->version = '1.0';
|
||||||
|
$this->need_instance = 0;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->displayName = $this->l('Administration of supplier demands');
|
||||||
|
$this->description = $this->l('Track every request made to suppliers.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function install()
|
||||||
|
{
|
||||||
|
if (!$this->installDB()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(parent::install())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function uninstall() {
|
||||||
|
|
||||||
|
if(parent::uninstall() == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function installDB()
|
||||||
|
{
|
||||||
|
$result = true;
|
||||||
|
# Add tables
|
||||||
|
$query = '
|
||||||
|
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'supplier_demand` (
|
||||||
|
`id_supplier_demand` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_order` INTEGER NOT NULL,
|
||||||
|
`id_order_detail` INTEGER NOT NULL,
|
||||||
|
`qty` INTEGER NOT NULL,
|
||||||
|
`id_state` INTEGER NOT NULL DEFAULT 1,
|
||||||
|
`comment` TEXT,
|
||||||
|
`date_add` DATETIME NOT NULL,
|
||||||
|
`date_upd` DATETIME NOT NULL,
|
||||||
|
PRIMARY KEY(`id_supplier_demand`)
|
||||||
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8
|
||||||
|
';
|
||||||
|
|
||||||
|
$result = Db::getInstance()->Execute($query);
|
||||||
|
|
||||||
|
$query = '
|
||||||
|
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'supplier_demand_history` (
|
||||||
|
`id_supplier_demand_history` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_supplier_demand` INTEGER NOT NULL,
|
||||||
|
`id_employee` INTEGER NOT NULL,
|
||||||
|
`id_state` INTEGER NOT NULL,
|
||||||
|
`date_add` DATETIME NOT NULL,
|
||||||
|
PRIMARY KEY(`id_supplier_demand_history`)
|
||||||
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8
|
||||||
|
';
|
||||||
|
|
||||||
|
$result = (Db::getInstance()->Execute($query) and $result);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
171
modules/ant_supplierdemand/models/SupplierDemand.php
Normal file
171
modules/ant_supplierdemand/models/SupplierDemand.php
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class SupplierDemand extends ObjectModel
|
||||||
|
{
|
||||||
|
|
||||||
|
const RENEW_STATE = 2;
|
||||||
|
|
||||||
|
public static $states = array(
|
||||||
|
1 => array(
|
||||||
|
'name' => "Fournisseur contacté",
|
||||||
|
'icon' => 'anticon anticon-phone text-orange',
|
||||||
|
),
|
||||||
|
2 => array(
|
||||||
|
'name' => "Fournisseur relancé",
|
||||||
|
'icon' => 'anticon anticon-spinner11 text-orange',
|
||||||
|
),
|
||||||
|
3 => array(
|
||||||
|
'name' => "En cours",
|
||||||
|
'icon' => 'anticon anticon-hour-glass text-orange',
|
||||||
|
),
|
||||||
|
4 => array(
|
||||||
|
'name' => "Pas de réponse",
|
||||||
|
'icon' => 'anticon anticon-blocked text-rose',
|
||||||
|
),
|
||||||
|
5 => array(
|
||||||
|
'name' => "SAV réglé",
|
||||||
|
'icon' => 'anticon anticon-checkmark text-green',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
public $id_order;
|
||||||
|
public $id_order_detail;
|
||||||
|
public $qty;
|
||||||
|
public $id_state;
|
||||||
|
public $comment;
|
||||||
|
public $date_add;
|
||||||
|
public $date_upd;
|
||||||
|
|
||||||
|
protected $fieldsRequired = array('id_order', 'id_order_detail','qty');
|
||||||
|
protected $fieldsValidate = array(
|
||||||
|
'id_order' => 'isUnsignedId',
|
||||||
|
'id_order_detail' => 'isUnsignedId',
|
||||||
|
'qty' => 'isUnsignedId',
|
||||||
|
'id_state' => 'isUnsignedId',
|
||||||
|
'comment' => 'isString',
|
||||||
|
'date_add' => 'isDate',
|
||||||
|
'date_upd' => 'isDate',
|
||||||
|
);
|
||||||
|
|
||||||
|
protected $table = 'supplier_demand';
|
||||||
|
protected $identifier = 'id_supplier_demand';
|
||||||
|
|
||||||
|
|
||||||
|
public function getFields()
|
||||||
|
{
|
||||||
|
parent::validateFields();
|
||||||
|
|
||||||
|
$fields['id_order'] = (int)$this->id_order;
|
||||||
|
$fields['id_order_detail'] = (int)$this->id_order_detail;
|
||||||
|
$fields['qty'] = (int)$this->qty;
|
||||||
|
$fields['id_state'] = (int)$this->id_state;
|
||||||
|
$fields['comment'] = pSQL($this->comment);
|
||||||
|
$fields['date_add'] = pSQL($this->date_add);
|
||||||
|
$fields['date_upd'] = pSQL($this->date_upd);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get demands
|
||||||
|
* @param $states array get only demands in specific states
|
||||||
|
* @return Array Groups
|
||||||
|
*/
|
||||||
|
public static function getDemands($states = array(), $where = false)
|
||||||
|
{
|
||||||
|
if($where){
|
||||||
|
return Db::getInstance()->executeS('
|
||||||
|
SELECT *
|
||||||
|
FROM `'._DB_PREFIX_.'supplier_demand` sd
|
||||||
|
WHERE '.$where.'
|
||||||
|
');
|
||||||
|
} else {
|
||||||
|
return Db::getInstance()->executeS('
|
||||||
|
SELECT *
|
||||||
|
FROM `'._DB_PREFIX_.'supplier_demand` sd
|
||||||
|
WHERE 1
|
||||||
|
'.(!empty($states) ? 'AND sd.`state` IN ('.implode(',',$states).')' : '').'
|
||||||
|
ORDER BY sd.date_add DESC
|
||||||
|
');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
if (parent::save()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCountRenews($id_supplier_demand)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->getValue("
|
||||||
|
SELECT COUNT(id_supplier_demand_history)
|
||||||
|
FROM `" . _DB_PREFIX_ . "supplier_demand_history`
|
||||||
|
WHERE `id_supplier_demand` = " . (int)$id_supplier_demand."
|
||||||
|
AND `id_state` = ". self::RENEW_STATE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCustomer($id_supplier_demand)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->getRow("
|
||||||
|
SELECT c.*
|
||||||
|
FROM `" . _DB_PREFIX_ . "customer` c
|
||||||
|
LEFT JOIN `" . _DB_PREFIX_ . "orders` o ON (o.id_customer = c.id_customer)
|
||||||
|
LEFT JOIN `" . _DB_PREFIX_ . "supplier_demand` sd ON (sd.id_order = o.id_order)
|
||||||
|
WHERE sd.`id_supplier_demand` = " . (int)$id_supplier_demand
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHistory()
|
||||||
|
{
|
||||||
|
return self::getHistoryStatic($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getHistoryStatic($id_supplier_demand)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->ExecuteS("
|
||||||
|
SELECT h.*, CONCAT(e.firstname,' ',e.lastname) as employee
|
||||||
|
FROM `" . _DB_PREFIX_ . "supplier_demand_history` h
|
||||||
|
LEFT JOIN `" . _DB_PREFIX_ . "employee` e ON (e.id_employee = h.id_employee)
|
||||||
|
WHERE h.`id_supplier_demand` = " . (int)$id_supplier_demand."
|
||||||
|
ORDER BY h.date_add DESC"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addHistory()
|
||||||
|
{
|
||||||
|
return self::addHistoryStatic($this->id, $this->id_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addHistoryStatic($id_supplier_demand, $id_state)
|
||||||
|
{
|
||||||
|
global $cookie;
|
||||||
|
return Db::getInstance()->Execute('
|
||||||
|
INSERT INTO `'._DB_PREFIX_.'supplier_demand_history`
|
||||||
|
VALUES (DEFAULT,'.(int)$id_supplier_demand.','.(int)$cookie->id_employee.','.(int)$id_state.',NOW())'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProduct()
|
||||||
|
{
|
||||||
|
return self::getProductStatic($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getProductStatic($id_supplier_demand)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->getRow("
|
||||||
|
SELECT od.*
|
||||||
|
FROM `" . _DB_PREFIX_ . "supplier_demand` sd
|
||||||
|
LEFT JOIN `" . _DB_PREFIX_ . "order_detail` od ON (od.id_order_detail = sd.id_order_detail)
|
||||||
|
WHERE sd.`id_supplier_demand` = " . (int)$id_supplier_demand
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user