Initial commit

This commit is contained in:
Senad Uka
2018-06-11 11:09:35 +02:00
commit ed7df7b11f
1954 changed files with 483354 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
<?php
class ClCustomers{
/**
* get customers list linked to the commercial lead
* @return Array list of customers linked to a commercial lead
*/
public function getComercialLeadCustomers(){
global $database, $user;
$idUser = $user->getUserId();
$data = [];
$sql = "SELECT
rclc.id as idCustomerInstance,
c.name AS customerName,
rclc.idOrderType,
IF(u.idCompany = clCompany.idCompany, 1, 0) AS isSameCompanyAsCl
FROM
".TABLES['customers']." c
INNER JOIN ".TABLES['rel_commercial_lead_customers']." rclc
ON rclc.idCustomer=c.id AND isLinkEnabled=1
INNER JOIN ".TABLES['commercial_leads']." cl
ON cl.id=rclc.idCommercialLead
INNER JOIN ".TABLES['users']." u
ON u.id = c.idUser
INNER JOIN
(SELECT
us.idCompany,
us.id
FROM
".TABLES['users']." us
WHERE us.id = $idUser) clCompany
ON clCompany.id = cl.idUser
WHERE cl.idUser=$idUser
";
return $database->fetchResultArray($sql);
}
public function getClAndCustomers(){
global $database, $user;
$data = [];
$sql = "SELECT
rclc.id as idCustomerInstance,
cl.name as commercialLead,
cl.id as idCommercialLead,
c.id AS idCustomer,
c.name AS customer,
IF(u.idCompany = clCompany.idCompany, 1, 0) AS isSameCompanyAsCl
FROM
".TABLES['customers']." c
INNER JOIN ".TABLES['rel_commercial_lead_customers']." rclc
ON rclc.idCustomer=c.id AND isLinkEnabled=1
INNER JOIN ".TABLES['commercial_leads']." cl
ON cl.id=rclc.idCommercialLead
INNER JOIN ".TABLES['users']." u
ON u.id = c.idUser
INNER JOIN
(SELECT
us.idCompany,
us.id
FROM
".TABLES['users']." us) clCompany
ON clCompany.id = cl.idUser
ORDER BY cl.name
";
$query = $database->query($sql);
while($row = $database->fetchArray($query)){
if(!isset($data[$row['idCommercialLead']])){
$data[$row['idCommercialLead']] = [];
}
$data[$row['idCommercialLead']]['idCommercialLead'] = $row['idCommercialLead'];
$data[$row['idCommercialLead']]['commercialLead'] = $row['commercialLead'];
$data[$row['idCommercialLead']]['customers'][] = $row;
}
$data = (array) $data;
usort($data, function($clA, $clB) {
return strnatcasecmp($clA['commercialLead'], $clB['commercialLead']) > 0 ? 1 : -1;
});
return $data;
}
public function getClCustomerInfo($idCommercialLead){
global $database, $user;
$idUser = $user->getUserId();
$data = [];
$sql = "SELECT
rclc.id as idCustomerInstance,
c.name AS customerName,
c.id AS idCustomer,
rclc.idOrderType,
IF(u.idCompany = clCompany.idCompany, 1, 0) AS isSameCompanyAsCl
FROM
".TABLES['customers']." c
INNER JOIN ".TABLES['rel_commercial_lead_customers']." rclc
ON rclc.idCustomer=c.id AND isLinkEnabled=1
INNER JOIN ".TABLES['commercial_leads']." cl
ON cl.id=rclc.idCommercialLead
INNER JOIN ".TABLES['users']." u
ON u.id = c.idUser
INNER JOIN
(SELECT
us.idCompany,
cl.id
FROM
".TABLES['users']." us
INNER JOIN ".TABLES['commercial_leads']." cl
ON cl.idUser=us.id
WHERE cl.id = $idCommercialLead) clCompany
ON clCompany.id = cl.id
WHERE c.idUser=$idUser AND rclc.idCommercialLead=$idCommercialLead";
$query = $database->query($sql);
$data = $database->fetchArray($query);
return $data;
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Cusotmers controlls the actions for customers
*/
class CustomersController{
private $model;
function __construct(){
$this->model = new CustomersModel();
}
/**
* get all commecrial lead customers linked to package
* @return json list with commercial lead customers
*/
public function getComercialLeadCustomers(){
echo json_encode($this->model->getComercialLeadCustomers());
}
/**
* returns all the order types existing in the application
* @return Array with all order types
*/
public function getOrderTypes() {
echo json_encode($this->model->getOrderTypes());
}
/**
* save default order type for cl
* @return Array update emssage
*/
public function saveDefaultOrderType() {
$defaultIdOrderType = isset($_REQUEST['defaultIdOrderType']) ? $_REQUEST['defaultIdOrderType'] : 0;
echo json_encode($this->model->saveDefaultOrderType($defaultIdOrderType));
}
/**
* dave order type for each custoemr
* @return Array update message
*/
public function saveCustomersOrderTypes() {
$customers = isset($_REQUEST['customers']) ? $_REQUEST['customers'] : '[]';
echo json_encode($this->model->saveCustomersOrderTypes($customers));
}
/**
* include customers template
*/
public function customersTemplate(){
global $user;
require_once('templates/CustomersTemplate.php');
}
/**
* include custoemrs view template
*/
public function customersViewTemplate(){
require_once('templates/CustomersViewTemplate.php');
}
/**
* open custoemrs page
*/
public function showPage(){
require_once('CustomersPage.php');
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Data manipulation for the docuemnts
*/
class CustomersModel{
/**
* returns all the invoice processes existing in the application
* @return Array all the invoice processes from the application
*/
public function getOrderTypes() {
$orderType = new OrderType();
return $orderType->getOrderTypes();
}
/**
* get customers list linked to the commercial lead
* @return Array list of customers linked to a commercial lead
*/
public function getComercialLeadCustomers(){
$data = [];
$clCustomers = new ClCustomers();
$orderType = new OrderType();
$data['customers'] = $clCustomers->getComercialLeadCustomers();
$data['defaultIdOrderType'] = $orderType->getCLDefaultOrderType();
return $data;
}
/**
* save Default Order Type
* @param INT $defaultIdOrderType id for default order type
* @return Array update message
*/
public function saveDefaultOrderType($defaultIdOrderType){
$orderType = new OrderType();
return $orderType->saveDefaultOrderType($defaultIdOrderType);
}
/**
* save Customers Order Types
* @param Object $customers list of customers containg alos the id for order type
* @return Array update message
*/
public function saveCustomersOrderTypes($customers){
$orderType = new OrderType();
return $orderType->saveCustomersOrderTypes($customers);
}
}

View File

@@ -0,0 +1,7 @@
<script src="<?php echo PATH_JS_COMPONENTS.'customers/customers.directive.js?v='.APPLICATION_VERSION;?>" type="text/javascript"></script>
<script src="<?php echo PATH_JS_COMPONENTS.'customers/customers-view.directive.js?v='.APPLICATION_VERSION;?>" type="text/javascript"></script>
<div id="customers-module" class="container-fluid col-md-12">
<h1>{{ 'customers.TITLE' | translate }}</h1>
<customers ng-controller="customersCtrl"></customers>
</div>

View File

@@ -0,0 +1,135 @@
<?php
class OrderType{
/**
* returns all the invoice processes existing in the application
* @return Array all the invoice processes from the application
*/
public function getOrderTypes() {
global $database;
$sql = "SELECT
id AS idOrderType,
name,
details
FROM
".TABLES['order_types'];
return $database->fetchResultArray($sql);
}
/**
* save Default Order Type
* @param INT $defaultIdOrderType id for default order type
* @return Array update message
*/
public function saveDefaultOrderType($defaultIdOrderType){
global $database, $user;
$idUser = $user->getUserId();
$data = [];
$defaultIdOrderType = $database->escapeValue($defaultIdOrderType);
if(!$defaultIdOrderType){
$data['messages'][] = [
'code' => 'error',
'message' => 'DEFAULT_VALUE_REQUIRED'
];
return $data;
}
$sql = "UPDATE ".TABLES['commercial_leads']."
SET defaultIdOrderType=$defaultIdOrderType
WHERE idUser=$idUser";
$query = $database->query($sql);
if($database->affectedRows() > 0){
$data['messages'][] = [
'code' => 'success',
'message' => 'DEFAULT_VALUE_UPDATED'
];
}else{
$data['messages'][] = [
'code' => 'warning',
'message' => 'NO_CHANGES'
];
}
return $data;
}
/**
* save Customers Order Types
* @param Object $customers list of customers containg alos the id for order type
* @return Array update message
*/
public function saveCustomersOrderTypes($customers){
global $database, $user;
$idUser = $user->getUserId();
$data = [];
$customers = json_decode($customers);
$idCustomerInstances = [];
foreach ($customers as $customer) {
if($customer->idOrderType){
$idCustomerInstances[] = $database->escapeValue($customer->idCustomerInstance);
}
}
$totalCustomers = count($idCustomerInstances);
$customerList = $totalCustomers > 0 ? implode($idCustomerInstances, ',') : '0';
$sql = "SELECT COUNT(rclc.id) AS validCustomers
FROM ".TABLES['rel_commercial_lead_customers']." rclc
INNER JOIN ".TABLES['commercial_leads']." cl
ON cl.id=rclc.idCommercialLead
WHERE cl.idUser=$idUser AND rclc.id IN($customerList) ";
$query = $database->query($sql);
$row = $database->fetchArray($query);
if($row['validCustomers'] != $totalCustomers){
$data['messages'][] = [
'code' => 'error',
'message' => 'NOT_AUTHORIZED'
];
return $data;
}
$uppdated = 0;
foreach ($customers as $customer) {
if($customer->idOrderType){
$customer->idOrderType = $database->escapeValue($customer->idOrderType);
$customer->idCustomerInstance = $database->escapeValue($customer->idCustomerInstance);
$sql = "UPDATE ".TABLES['rel_commercial_lead_customers']."
SET idOrderType=".$customer->idOrderType."
WHERE id=".$customer->idCustomerInstance;
$query = $database->query($sql);
$uppdated += $database->affectedRows($query);
}
}
if($uppdated > 0){
$data['messages'][] = [
'code' => 'success',
'message' => 'ORDER_TYPES_UPDATED'
];
}else{
$data['messages'][] = [
'code' => 'warning',
'message' => 'NO_CHANGES'
];
}
return $data;
}
public function getCLDefaultOrderType(){
global $database, $user;
$sql = "SELECT
cl.defaultIdOrderType
FROM ".TABLES['commercial_leads']." cl
WHERE cl.idUser=".$user->getUserId()."
LIMIT 1";
$query = $database->query($sql);
$row = $database->fetchArray($query);
return $row['defaultIdOrderType'];
}
}

View File

@@ -0,0 +1,13 @@
<button type="button"
id="customers-view"
subModule="customersView"
class="btn btn-default"
ng-click="setSubModule($event)">{{ 'customers.buttons.VIEW_CUSTOMERS' | translate }}</button>
<div class="row">
<div class="col-md-12"
id="customers-view-layer"
ng-if="isSubmoduleVisible('customersView')">
<customers-view ng-controller="customersViewCtrl" ng-init="viewCustomersIntit()"></customers-view>
</div>
</div>

View File

@@ -0,0 +1,70 @@
<div class="customers-view-layer row">
<div class="row">
<div class="col-md-6 title-header">
<div class="col-md-6">
{{ 'customers.headers.DEFAULT' | translate }}
</div>
<div class="col-md-6">
{{ 'customers.headers.ORDER_TYPE' | translate }}
</div>
</div>
</div>
<div class="row customer-row">
<div class="col-md-6 custom-border">
<div class="col-md-6">
{{ 'customers.headers.DEFAULT' | translate }}
</div>
<div class="col-md-6">
<div ng-repeat="orderType in orderTypes">
<input type="radio" value="{{orderType.idOrderType}}" ng-model="$parent.defaultIdOrderType" name="defaultOrderType"/>
<label>{{orderType.name}}</label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="btn btn-primary" ng-click="saveDefaultOrderType()">
{{ 'customers.buttons.SAVE' | translate }}
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 title-header">
<div class="col-md-6">
{{ 'customers.headers.CUSTOMERS' | translate }}
</div>
<div class="col-md-6">
{{ 'customers.headers.ORDER_TYPE' | translate }}
</div>
</div>
</div>
<div class="row customer-row" ng-repeat="customer in customers">
<div class="col-md-6 custom-border">
<div class="col-md-6">
{{customer.customerName}}
<span ng-if="isSameCompany(customer.isSameCompanyAsCl)">(same company)</span>
</div>
<div class="col-md-6">
<div ng-repeat="orderType in orderTypes">
<input type="radio"
value="{{orderType.idOrderType}}"
ng-disabled="isSameCompany(customer.isSameCompanyAsCl)"
ng-model="customer.idOrderType"
name="customer-{{customer.idCustomerInstance}}"/>
<label>{{orderType.name}}</label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="btn btn-primary" ng-click="saveCustomerOrderTypes()">
{{ 'customers.buttons.SAVE' | translate }}
</div>
</div>
</div>
</div>