setProps($data);
$this->approveFormView($data);
} catch (Exception $e) {
UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
}
UI::dol();
}
public function approveOrderAction() {
UI::gora();
try {
$data = array();
$data['id_order'] = V::get('id_order', 0, $_REQUEST, 'int');
$data = $this->setProps($data);
$sqlObj = array();
$sqlObj['ID'] = $data['id_order'];
$sqlObj['APPROVE_STATUS'] = 'OCZEKUJE_OSTATECZNEGO_ZATWIERDZENIA';
$sqlObj['APPROVED_BY'] = User::getFullName();
$affected = DB::getDB()->UPDATE_OBJ('CRM_LISTA_ZASOBOW_ORDERS', (object)$sqlObj);
UI::startContainer();
if ($affected >= 0) {
UI::alert('success', "Przekazano do ostatecznego zatwierdzenia");
// TODO: show link to final approve if has access?
} else {
UI::alert('danger', "Wystąpiły błędy podczas zmieniania statusu zamówienia");
}
echo UI::h('div', ['style'=>"text-align:center"], [
UI::h('a', ['href'=>"index.php?_route=UrlAction_ProjektyProNetMediaZamZlec&ID_PROJECT={$data['id_project']}", 'class'=>"btn btn-primary"], "Wróć")
]);
UI::endContainer();
} catch (Exception $e) {
UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
}
UI::dol();
}
public function rejectOrderAction() {
UI::gora();
try {
$data = array();
$data['id_order'] = V::get('id_order', 0, $_REQUEST, 'int');
$data = $this->setProps($data);
$sqlObj = array();
$sqlObj['ID'] = $data['id_order'];
$sqlObj['APPROVE_STATUS'] = 'ODRZUCONE';
$sqlObj['APPROVED_BY'] = User::getFullName();
$affected = DB::getDB()->UPDATE_OBJ('CRM_LISTA_ZASOBOW_ORDERS', (object)$sqlObj);
UI::startContainer();
if ($affected >= 0) {
UI::alert('success', "Zmieniono status zamówienia na ODRZUCONE");
} else {
UI::alert('danger', "Wystąpiły błędy podczas zmieniania statusu zamówienia");
}
echo UI::h('div', ['style'=>"text-align:center"], [
UI::h('a', ['href'=>"index.php?_route=UrlAction_ProjektyProNetMediaZamZlec&ID_PROJECT={$data['id_project']}", 'class'=>"btn btn-primary"], "Wróć")
]);
UI::endContainer();
} catch (Exception $e) {
UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
}
UI::dol();
}
public function setProps($data) {
$idOrder = V::get('id_order', 0, $data, 'int');
if (!$idOrder) throw new Exception("Error: Brak nr zamówienia!");
$data['id_order'] = $idOrder;
$data['zamowienie_label'] = '';
$data['orderRaw'] = DB::getPDO()->fetchAll("
select r.ID
, r.ORDER_LABEL
, r.ORDER_TYPE
, r.ID_PROJECT
, sum(o.OFFER_PRICE_PER_UNIT * o.OFFER_QUANTITY) as SUM_NETTO
, p.M_DIST_DESC
, r.A_RECORD_CREATE_AUTHOR
, r.A_RECORD_CREATE_DATE
from CRM_LISTA_ZASOBOW_ORDERS r
join IN7_MK_BAZA_DYSTRYBUCJI p on(p.ID = r.ID_PROJECT)
left join CRM_LISTA_ZASOBOW_OFFERS o on(
o.ID_ORDER = r.ID
and (o.A_STATUS is null or o.A_STATUS not in('DELETED'))
)
where (r.A_STATUS is null or r.A_STATUS not in('DELETED'))
and r.ID = {$idOrder}
");
if (empty($data['orderRaw'])) throw new Exception("Error: Brak danych dla zamówienia {$idOrder}!");
$data['orderRaw'] = $data['orderRaw'][0];
$data['zamowienie_label'] = $data['orderRaw']['ORDER_LABEL'];
$data['zamowienie_suma'] = number_format($data['orderRaw']['SUM_NETTO'], 2, ',', ' ');
$data['id_project'] = $data['orderRaw']['ID_PROJECT'];
$data['project_label'] = $data['orderRaw']['M_DIST_DESC'];
$data['ORDER_TYPE'] = $data['orderRaw']['ORDER_TYPE'];
return $data;
}
public function approveFormView($data) {
UI::startContainer();
echo UI::h('h1', [], [
('zlecenie' == $data['ORDER_TYPE']) ? "Zlecenie" : "Zamówienie",
" " . $data['zamowienie_label'],
'
' . "Dotyczy projektu: {$data['project_label']}"
]);
echo UI::h('div', ['class'=>"alert alert-info"], "Suma netto zamówienia: {$data['zamowienie_suma']}");
echo UI::h('form', ['style'=>"text-align:center"], [
UI::h('h3', [], "Przekazanie do ostatecznego zatwierdzenia"),
UI::h('input', ['type'=>"hidden", 'name'=>"_route", 'value'=>"UrlAction_ProjektyProNetMediaApproveZam"]),
UI::h('input', ['type'=>"hidden", 'name'=>"_task", 'value'=>""]),
UI::h('input', ['type'=>"hidden", 'name'=>"id_order", 'value'=>$data['id_order']]),
UI::h('button', ['onClick'=>"return approveOrder(this);", 'class'=>"btn btn-lg btn-primary"], "Zatwierdzam"),
UI::h('button', ['onClick'=>"return rejectOrder(this);", 'class'=>"btn btn-lg btn-danger", 'style'=>"margin-left:30px"], "Nie zatwierdzam"),
UI::h('a', [
'href' => $this->getLink('msgs') . "&id_order={$data['id_order']}",
'class'=>"btn btn-lg btn-warning",
'style'=>"margin-left:30px"
], "Do wyjaśnienia"),
]);
echo UI::h('hr');
Router::getRoute('UrlAction_ProjektyProNetMediaZamZlec')->previewOrder($data['id_order']);
UI::endContainer();
echo UI::h('script', [], "
function approveOrder(fld) {
var frm = fld.form;
frm['_task'].value='approveOrder';
}
function rejectOrder(fld) {
var frm = fld.form;
frm['_task'].value='rejectOrder';
}
");
}
public function msgsAction() {
UI::gora();
UI::menu();
try {
$data = $this->setProps([
'id_order' => V::get('id_order', 0, $_GET, 'int')
]);
UI::startContainer();
echo UI::h('h1', [], [
('zlecenie' == $data['ORDER_TYPE']) ? "Zlecenie" : "Zamówienie",
" " . $data['zamowienie_label'],
'
' . "Dotyczy projektu: {$data['project_label']}"
]);
$author = V::get('A_RECORD_CREATE_AUTHOR', '', $data['orderRaw']);
if ($author) echo UI::h('h4', [], "Autor: {$author}");
$idTable = DB::getPDO()->fetchValue("
select z.ID
from CRM_LISTA_ZASOBOW z
where z.`DESC` = 'CRM_LISTA_ZASOBOW_ORDERS'
and z.`TYPE` = 'TABELA'
");
Router::getRoute('TableMsgs')->tableRowMsgs($idTable, $data['id_order']);
} catch (Exception $e) {
UI::alert('danger', $e->getMessage());
}
UI::dol();
}
}