_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 .='
'; $this->_addJs(); $this->_html .= $this->helperForm->renderScript(); echo $this->_html; } protected function _addJs() { $this->helperForm->_js .= ''; } 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; $query_state = array(1,2,3); if(Tools::getValue('query_state')){ $wanted_state = Tools::getValue('query_state'); $query_state = array((int)$wanted_state); } 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" '.(!empty($query_state) ? 'AND sd.`id_state` IN ('.implode(',',$query_state).')' : '').' ORDER BY sd.date_add DESC' ); } else { $supplier_demands = SupplierDemand::getDemands($query_state); } $states = SupplierDemand::$states; $solutions = SupplierDemand::$solutions; $counts = array( "done" => SupplierDemand::getCountDemands(array(5)), "no_answered" => SupplierDemand::getCountDemands(array(4)), "in_progress" => SupplierDemand::getCountDemands(array(1,2,3)) ); $_current_index = ($this->config_tab ? $currentIndex . '&token=' . Tools::getAdminTokenLite($this->controller) : $_SERVER['REQUEST_URI']); $this->_html .='

'.$this->l('Liste des demandes fournisseurs').'

au
'; foreach ($supplier_demands as $supplier_demand) { $renews_number = SupplierDemand::getCountRenews((int)$supplier_demand['id_supplier_demand']); $info = SupplierDemand::getSaleStatic((int)$supplier_demand['id_supplier_demand'], true); $this->_html .=' '; } $this->_html .='
'.$this->l('ID').' '.$this->l('Order').' '.$this->l('Product').' '.$this->l('Sale').' '.$this->l('Status').' '.$this->l('Date').' '.$this->l('Renewed').' '.$this->l('Solution').' '.$this->l('Action').'
#'.$supplier_demand['id_supplier_demand'].' N° '.$supplier_demand['id_order'].' '.wordwrap($info['product_name'], 40, "
\n").'
'.$info['category_name'].' '.$states[$supplier_demand['id_state']]['name'].' '.date('d/m/Y',strtotime($supplier_demand['date_add'])).' '.($renews_number>1?''.$renews_number.'':''.$renews_number.'').' '.((int)$supplier_demand['solution']>0?$solutions[(int)$supplier_demand['solution']]:'/').'
'; } protected function _displayView() { global $cookie, $currentIndex; $_current_index = ($this->config_tab ? $currentIndex . '&token=' . Tools::getAdminTokenLite($this->controller) : $_SERVER['REQUEST_URI']); $states = SupplierDemand::$states; $solutions = SupplierDemand::$solutions; $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 .='

'.$this->l('Back to list').'

'.$this->l('Demande #').$this->_object->id.'

'.$states[$this->_object->id_state]['name'].'

'.$this->l('Comment').'

'.($this->_object->comment!==null?nl2br($this->_object->comment):'No comment').'


'.$this->l('Informations').'

'.$this->l('Status').'

'; if(isset($histories)){ $this->_html .='
'.$this->l('History').'

'.$states[$histories[0]['id_state']]['name'].'
('.$histories[0]['employee'].' - '.date('d/m/Y H:i',strtotime($histories[0]['date_add'])).')

'; foreach($histories as $history){ $this->_html .=' '; } $this->_html .='
'.date('d/m/Y H:i',strtotime($history['date_add'])).' '.$states[$history['id_state']]['name'].' '.$history['employee'].'
'; } $this->_html.='
'.$this->l('Update Status').'
'; } 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')){ $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; $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::displayErrors($this->l('Error occured while creating demand')); } } }