CMXX - Pricelists
This commit is contained in:
@@ -15,9 +15,10 @@ $delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],
|
||||
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
|
||||
|
||||
// Default input product values
|
||||
$text_variable = [
|
||||
$pricelists = [
|
||||
'rowID' => '',
|
||||
'variable' => '',
|
||||
'status' => '',
|
||||
'name' => '',
|
||||
'created' => '',
|
||||
'createdby' => '',
|
||||
'updated' => '',
|
||||
@@ -25,6 +26,7 @@ $text_variable = [
|
||||
'accounthierarchy' => ''
|
||||
];
|
||||
|
||||
|
||||
if (isset($_GET['rowID'])) {
|
||||
//CALL TO API
|
||||
$api_url = '/v2/pricelists/rowID='.$_GET['rowID'];
|
||||
@@ -40,6 +42,14 @@ if (isset($_GET['rowID'])) {
|
||||
//Decode Payload
|
||||
if (!empty($pricelists_items)){$pricelists_items = json_decode($pricelists_items,true);}else{$pricelists_items = null;}
|
||||
|
||||
//GET PRODUCTS AND ATTRIBUTES
|
||||
$api_url = '/v2/products/list=price';
|
||||
$responses = ioServer($api_url,'');
|
||||
//Decode Payload
|
||||
if (!empty($responses)){$products = json_decode($responses,true);}else{$products = null;}
|
||||
|
||||
|
||||
|
||||
if ($update_allowed === 1){
|
||||
if (isset($_POST['submit'])) {
|
||||
|
||||
@@ -57,7 +67,6 @@ if (isset($_GET['rowID'])) {
|
||||
}
|
||||
|
||||
if (isset($_POST['add'])) {
|
||||
|
||||
//GET ALL POST DATA
|
||||
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//API call
|
||||
@@ -66,9 +75,8 @@ if (isset($_GET['rowID'])) {
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
generateLanguageFile($_POST['language_key'],$_SESSION['userkey']);
|
||||
header('Location: index.php?page=pricelists_manage&rowID='.$_GET['rowID'].'');
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,11 +102,6 @@ if (isset($_GET['rowID'])) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($NOK_error == 0){
|
||||
//NO errors generatelanguagefile
|
||||
generateLanguageFile($attr_language,$_SESSION['userkey']);
|
||||
}
|
||||
|
||||
header('Location: index.php?page=pricelists_manage&rowID='.$_GET['rowID'].'');
|
||||
exit;
|
||||
}
|
||||
@@ -132,8 +135,8 @@ if (isset($_GET['rowID'])) {
|
||||
|
||||
} else {
|
||||
//GET ROWID OF CREATED ITEM
|
||||
$variable_rowID = json_decode($responses,true);
|
||||
header('Location: index.php?page=pricelists_manage&rowID='.$variable_rowID['rowID'].'');
|
||||
$pricelists_rowID = json_decode($responses,true);
|
||||
header('Location: index.php?page=pricelists_manage&rowID='.$pricelists_rowID['rowID'].'');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -161,7 +164,7 @@ if (isset($success_msg)){
|
||||
$view .='
|
||||
<form action="" method="post">
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100">'.($text_variables_h2 ?? '').'</h2>
|
||||
<h2 class="responsive-width-100">'.($pricelists_h2 ?? '').'</h2>
|
||||
<a href="index.php?page=pricelists" class="btn alt mar-right-2">'.$button_cancel.'</a>
|
||||
';
|
||||
|
||||
@@ -183,24 +186,45 @@ $view .= '<div class="tabs">
|
||||
//Define Service and User enabled
|
||||
$view .= '<div class="content-block tab-content active">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="variable">'.($text_variable_name ?? '').'</label>
|
||||
<input id="variable" type="text" name="variable" placeholder="'.($text_variable_name ?? '').'" value="'.$text_variable['variable'].'" pattern="^\S+$" required">
|
||||
<input type="hidden" name="rowID" value="'.$text_variable['rowID'].'" readonly>
|
||||
';
|
||||
|
||||
$view .= '</div>
|
||||
<label for="">'.($pricelists_status ?? 'Status').'</label>
|
||||
<select name="status">
|
||||
<option value="0" '.($pricelists['status']==0?' selected':'').'>'.$general_status_0.'</option>
|
||||
<option value="1" '.($pricelists['status']==1?' selected':'').'>'.$general_status_1.'</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="name">'.($pricelists_name ?? 'Pricelistname').'</label>
|
||||
<input id="name" type="text" name="name" placeholder="'.($pricelists_name ?? '').'" value="'.$pricelists['name'].'" required">
|
||||
<input type="hidden" name="rowID" value="'.$pricelists['rowID'].'" readonly>
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.($pricelists_currency ?? 'Currency').'</label>
|
||||
<select name="currency">';
|
||||
foreach ($supportedCurrencies as $key => $value){
|
||||
$view .='<option value="'.$key.'" '.(($pricelists['currency'] == $key)?' selected':'').'>'.(${'general_currency_'.$key} ?? $value).'</option>';
|
||||
}
|
||||
$view .='</select>
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="name">'.($pricelists_start_date ?? 'Start date').'</label>
|
||||
<input type="date" name="start_date" placeholder="'.($pricelists_start_date ?? '').'"value="'.$pricelists['start_date'].'" required>
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="name">'.($pricelists_end_date?? 'End date').'</label>
|
||||
<input type="date" name="end_date" placeholder="'.($pricelists_end_date ?? '').'"value="'.$pricelists['end_date'].'" required>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
$view .= '<div class="content-block tab-content">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$general_created.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.getRelativeTime($text_variable['created']).'" readonly>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.getRelativeTime($pricelists['created']).'" readonly>
|
||||
<label for="">'.$general_createdby.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$text_variable['createdby'].'" readonly>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$pricelists['createdby'].'" readonly>
|
||||
<label for="productcode">'.$general_updated.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.getRelativeTime($text_variable['updated']).'" readonly>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.getRelativeTime($pricelists['updated']).'" readonly>
|
||||
<label for="productcode">'.$general_updatedby.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$text_variable['updatedby'].'" readonly>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$pricelists['updatedby'].'" readonly>
|
||||
</div>
|
||||
</div>';
|
||||
$view .= '</form>';
|
||||
@@ -216,8 +240,11 @@ $view .= '
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>'.($text_variable_translation_languagekey ?? '').'</th>
|
||||
<th>'.($text_variable_translation_translation ?? '').'</th>
|
||||
<th>'.($pricelists_item_status ?? 'Status').'</th>
|
||||
<th>'.($pricelists_item_product_id ?? 'Product ID').'</th>
|
||||
<th>'.($pricelists_item_price ?? 'Price').'</th>
|
||||
<th>'.($pricelists_item_rpp ?? 'RPP').'</th>
|
||||
<th>'.($pricelists_item_price_modifier ?? 'Modifier').'</th>
|
||||
<th>'.$general_created.'</th>
|
||||
<th>'.$general_actions.'</th>
|
||||
</tr>
|
||||
@@ -229,23 +256,44 @@ $view .= '
|
||||
$view .= '
|
||||
|
||||
<tr>
|
||||
<td colspan="8" style="text-align:center;">'.($message_no_text_variables ?? '').'</td>
|
||||
<td colspan="8" style="text-align:center;">'.($message_no_pricelists ?? 'There are no pricelist items').'</td>
|
||||
</tr>';
|
||||
}
|
||||
else {
|
||||
foreach ($pricelists_items as $pricelists_item){
|
||||
foreach ($pricelists_items as $pricelist_item){
|
||||
|
||||
$view .= '
|
||||
|
||||
<tr>
|
||||
<td><input form="update" type="text" name="item['.$pricelists_item['rowID'].'][name]" placeholder="'.($text_variable_translation_translation ?? '').'" value="'.$pricelists_item['name'].'"></td>
|
||||
<td>'.getRelativeTime($pricelists_item['created']).'</td>
|
||||
<tr><td>
|
||||
<select form="update" name="item['.$pricelist_item['rowID'].'][status]">
|
||||
<option value="0" '.($pricelist_item['status']==0?' selected':'').'>'.$general_status_0.'</option>
|
||||
<option value="1" '.($pricelist_item['status']==1?' selected':'').'>'.$general_status_1.'</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<select form="update" name="item['.$pricelist_item['rowID'].'][product_id]">';
|
||||
foreach ($products as $product){
|
||||
$view .= '<option value="'.$product['product_id'].'" '.($product['product_id']==$pricelist_item['product_id'] ?' selected':'').'>'.(${$product['product_name']} ?? $product['product_name']).'</option>
|
||||
';}
|
||||
$view .= ' </select>
|
||||
</td>
|
||||
<td><input form="update" type="number" min="0" step="0.01" name="item['.$pricelist_item['rowID'].'][price]" placeholder="'.($pricelists_item_price ?? 'Price').'" value="'.$pricelist_item['price'].'"></td>
|
||||
<td><input form="update" type="number" min="0" step="0.01" name="item['.$pricelist_item['rowID'].'][rrp]" placeholder="'.($pricelists_item_rrp ?? 'Recommended Price').'" value="'.$pricelist_item['rrp'].'"></td>
|
||||
<td>
|
||||
<select form="update" name="item['.$pricelist_item['rowID'].'][price_modifier]">';
|
||||
foreach ($supportedModifiers as $key => $value){
|
||||
$view .='<option value="'.$key.'" '.(($pricelist_item['price_modifier'] == $key)?' selected':'').'>'.(${'general_modifier_'.$key} ?? $value).'</option>';
|
||||
}
|
||||
$view .=' </select>
|
||||
</td>
|
||||
<td>'.getRelativeTime($pricelist_item['created']).'</td>
|
||||
<td><input form="update" type="submit" name="update" value="&" class="btn"></td>
|
||||
<input form="update" type="hidden" name="item['.$pricelists_item['rowID'].'][rowID]" value="'.$pricelists_item['rowID'].'" readonly>
|
||||
<input form="update" type="hidden" name="item['.$pricelists_item['rowID'].'][pricelist_ID]" value="'.$pricelists['rowID'].'" readonly>
|
||||
<input form="update" type="hidden" name="item['.$pricelist_item['rowID'].'][rowID]" value="'.$pricelist_item['rowID'].'" readonly>
|
||||
<input form="update" type="hidden" name="item['.$pricelist_item['rowID'].'][pricelist_ID]" value="'.$pricelist_item['pricelist_ID'].'" readonly>
|
||||
</tr>
|
||||
</form>';
|
||||
}
|
||||
}
|
||||
|
||||
$view .= '
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -259,15 +307,40 @@ $view .= '
|
||||
const newRow = document.createElement(\'tr\');
|
||||
|
||||
newRow.innerHTML = `
|
||||
<td><input form="new" type="text" name="name" placeholder="'.($text_variable_translation_translation ?? '').'" value=""></td>
|
||||
<tr><td>
|
||||
<select form="new" name="status">
|
||||
<option value="0">'.$general_status_0.'</option>
|
||||
<option value="1" selected>'.$general_status_1.'</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<select form="new" name="product_id">';
|
||||
foreach ($products as $product){
|
||||
$view .= '<option value="'.$product['product_id'].'">'.(${$product['product_name']} ?? $product['product_name']).'</option>
|
||||
';}
|
||||
$view .= ' </select>
|
||||
</td>
|
||||
<td><input form="new" type="number" min="0" step="0.01" name="price" placeholder="'.($pricelists_item_price ?? 'Price').'" value=""></td>
|
||||
<td><input form="new" type="number" min="0" step="0.01" name="rrp" placeholder="'.($pricelists_item_rrp ?? 'Recommended Price').'" value=""></td>
|
||||
<td>
|
||||
<select form="new" name="price_modifier">';
|
||||
foreach ($supportedModifiers as $key => $value){
|
||||
$view .='<option value="'.$key.'" '.(($key == 1)?' selected':'').'>'.(${'general_modifier_'.$key} ?? $value).'</option>';
|
||||
}
|
||||
$view .=' </select>
|
||||
</td>
|
||||
<td></td>
|
||||
<td><input form="new" type="submit" name="add" value="+" class="btn"></td>
|
||||
<input form="new" type="hidden" name="rowID" value="" readonly>
|
||||
<input form="new" type="hidden" name="pricelist_ID" value="'.$pricelists_item['rowID'].'" readonly>
|
||||
<input form="new" type="hidden" name="pricelist_ID" value="'.$pricelists['rowID'].'" readonly>
|
||||
</tr>
|
||||
`;
|
||||
|
||||
tbody.appendChild(newRow);
|
||||
}
|
||||
</script>
|
||||
</script>';
|
||||
|
||||
$view .= '
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
Reference in New Issue
Block a user