2017-07-13 16:46:11 +02:00
< ? 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 "
});
2017-07-28 12:16:24 +02:00
if ( $ ( " select#id_state " ) . val () == 5 ){
$ ( " select#solution " ) . show ();
}
$ ( " select#id_state " ) . change ( function (){
if ( $ ( this ) . val () == 5 ){
$ ( " select#solution " ) . show ();
} else {
$ ( " select#solution " ) . hide ();
}
});
2017-07-13 16:46:11 +02:00
</ script > ' ;
}
protected function _addCss ()
{
$this -> helperForm -> _css .= '
#content .bootstrap-datetimepicker-widget tr th {
border - radius : 0 px ! important ;
}
. table tr th {
background : #565485;
background : rgba ( 86 , 84 , 133 , 0.9 );
color : #fff;
font - size : 12 px ;
}
. 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 : 4 px 5 px ;
color : #504d8b;
}
. table . input - group - btn . btn . anticon {
font - size : 12 px ;
}
. bg - grey {
background : #EFEFEF;
border - radius : 4 px ;
}
. bg - grey . div - title {
border - bottom : 2 px 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 ;
2017-07-18 12:06:50 +02:00
$query_state = array ( 1 , 2 , 3 );
if ( Tools :: getValue ( 'query_state' )){
$wanted_state = Tools :: getValue ( 'query_state' );
$query_state = array (( int ) $wanted_state );
}
2017-07-13 16:46:11 +02:00
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 ,
2017-07-18 12:06:50 +02:00
'sd.date_add > "' . $datefrom -> format ( 'Y-m-d' ) . ' 00:00:00" AND sd.date_add < "' . $dateto -> format ( 'Y-m-d' ) . ' 23:59:59" ' . ( ! empty ( $query_state ) ? 'AND sd.`id_state` IN (' . implode ( ',' , $query_state ) . ')' : '' ) . ' ORDER BY sd.date_add DESC'
2017-07-13 16:46:11 +02:00
);
} else {
2017-07-18 12:06:50 +02:00
$supplier_demands = SupplierDemand :: getDemands ( $query_state );
2017-07-13 16:46:11 +02:00
}
$states = SupplierDemand :: $states ;
2017-07-28 12:16:24 +02:00
$solutions = SupplierDemand :: $solutions ;
2017-07-18 12:06:50 +02:00
$counts = array (
" done " => SupplierDemand :: getCountDemands ( array ( 5 )),
" no_answered " => SupplierDemand :: getCountDemands ( array ( 4 )),
" in_progress " => SupplierDemand :: getCountDemands ( array ( 1 , 2 , 3 ))
);
2017-07-13 16:46:11 +02:00
$_current_index = ( $this -> config_tab ? $currentIndex . '&token=' . Tools :: getAdminTokenLite ( $this -> controller ) : $_SERVER [ 'REQUEST_URI' ]);
$this -> _html .= '
2017-07-18 12:06:50 +02:00
< div class = " col-md-12 " >
< div class = " panel " >
< div class = " panel-content " >
< a href = " '. $_current_index .' " class = " btn btn-warning " role = " button " > En cours < span class = " badge " > '.$counts[' in_progress '].' </ span ></ a >
< a href = " '. $_current_index .'&query_state=5 " class = " btn btn-primary " role = " button " > SAV réglé < span class = " badge " > '.$counts[' done '].' </ span ></ a >
< a href = " '. $_current_index .'&query_state=4 " class = " btn btn-danger " role = " button " > Pas de réponse < span class = " badge " > '.$counts[' no_answered '].' </ span ></ a >
</ div >
</ div >
</ div >
2017-07-13 16:46:11 +02:00
< 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 " >
2017-07-18 12:06:50 +02:00
< form method = " POST " action = " '. $_current_index .'&filter=1'.(Tools::getValue('query_state')?'&query_state='.Tools::getValue('query_state'):'').' " >
2017-07-13 16:46:11 +02:00
< 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 >
2017-07-18 12:06:50 +02:00
< th class = " text-left " > '.$this->l(' Product ').' </ th >
< th class = " text-left " > '.$this->l(' Sale ').' </ th >
2017-07-13 16:46:11 +02:00
< th class = " text-center " > '.$this->l(' Status ').' </ th >
< th class = " text-center " > '.$this->l(' Date ').' </ th >
< th class = " text-center " > '.$this->l(' Renewed ').' </ th >
2017-07-28 12:16:24 +02:00
< th class = " text-center " > '.$this->l(' Solution ').' </ th >
2017-07-13 16:46:11 +02:00
< 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' ]);
2017-07-18 12:06:50 +02:00
$info = SupplierDemand :: getSaleStatic (( int ) $supplier_demand [ 'id_supplier_demand' ], true );
2017-07-13 16:46:11 +02:00
$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 >
2017-07-18 12:12:25 +02:00
< td valign = " middle " align = " left " >< b > '.wordwrap($info[' product_name '], 40, "<br />\n").' </ b ></ td >
2017-07-18 12:06:50 +02:00
< td valign = " middle " align = " left " > '.$info[' category_name '].' </ td >
2017-07-13 16:46:11 +02:00
< 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 >
2017-07-28 12:16:24 +02:00
< td valign = " middle " align = " center " > '.((int)$supplier_demand[' solution ']>0?$solutions[(int)$supplier_demand[' solution ']]:' / ').' </ td >
2017-07-13 16:46:11 +02:00
< 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 ;
2017-07-28 12:16:24 +02:00
$solutions = SupplierDemand :: $solutions ;
2017-07-13 16:46:11 +02:00
$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 " >& times ; </ 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 " >
2017-07-18 12:06:50 +02:00
< a href = " index.php?tab=AdminCatalog&updateproduct&id_product='. $product['product_id'] .'&token=' . Tools::getAdminTokenLite('AdminCatalog').' " target = " _blank " >
< img src = " '.(isset( $img_path )?_THEME_PROD_DIR_. $img_path .'-product_carre.jpg " ':' ').' " width= " 200 px " >
</ a >
< p class = " text-center " >< a href = " index.php?tab=AdminCatalog&updateproduct&id_product='. $product['product_id'] .'&token=' . Tools::getAdminTokenLite('AdminCatalog').' " target = " _blank " > '.$product[' product_name '].' </ a ></ p >
2017-07-13 16:46:11 +02:00
</ 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 >
2017-07-13 17:00:02 +02:00
< li >< i class = " anticon anticon-calculator " ></ i > < span class = " label label-info " > '.$this->_object->qty.' '.$this->l(' quantity ').' </ span ></ li >
2017-07-13 16:46:11 +02:00
</ 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 " >
2017-07-28 12:16:24 +02:00
< select class = " form-control " name = " id_state " id = " id_state " > ' ;
2017-07-13 16:46:11 +02:00
foreach ( $states as $key => $state ) {
$this -> _html .= '<option value="' . $key . '"' . ( $this -> _object -> id_state == $key ? ' selected="selected"' : '' ) . '>' . $state [ 'name' ] . '</option>' ;
}
2017-07-28 12:16:24 +02:00
$this -> _html .= ' </ select >
</ div >
< div class = " form-group " >
< select class = " form-control " name = " solution " id = " solution " style = " display:none; " >
< option value = " 0 " > '.$this->l(' Solution ... ').' </ option > ' ;
foreach ( $solutions as $key => $solution ) {
$this -> _html .= '<option value="' . $key . '"' . ( $this -> _object -> solution == $key ? ' selected="selected"' : '' ) . '>' . $solution . '</option>' ;
}
2017-07-13 16:46:11 +02:00
$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' )){
2017-07-28 12:16:24 +02:00
$id_state = ( int ) Tools :: getValue ( 'id_state' );
if ( $id_state == 5 && ( ! Tools :: getValue ( 'solution' ) || Tools :: getValue ( 'solution' ) == 0 )){
return HelperFormBootstrap :: displayErrors ( $this -> l ( 'You have to choose a solution' ));
}
if ( Tools :: getValue ( 'solution' )){
$supplierDemand -> solution = ( int ) Tools :: getValue ( 'solution' );
}
$supplierDemand -> id_state = $id_state ;
2017-07-13 16:46:11 +02:00
$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 {
2017-07-28 12:16:24 +02:00
return HelperFormBootstrap :: displayErrors ( $this -> l ( 'Error occured while creating demand' ));
2017-07-13 16:46:11 +02:00
}
}
}