172 lines
5.1 KiB
PHP
172 lines
5.1 KiB
PHP
|
<?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
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|