Skip to content

Commit

Permalink
Allow add item to a reviewing order
Browse files Browse the repository at this point in the history
Fix:
 * Show *loadSpinner* on order detail an review.
  • Loading branch information
jorix committed Jan 23, 2017
1 parent 8ea3e0e commit 5e403e6
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 7 deletions.
2 changes: 2 additions & 0 deletions local_config/lang/ca-va.php
Expand Up @@ -780,6 +780,8 @@
$Text['msg_confirm_move'] = "Estàs segur que vols fer aquesta comanda disponible per a la venda? Tots els productes disponibles es posaran a les cistelles de la data:";
$Text['alter_date'] = "Tria una data alternativa";
$Text['msg_err_miss_info'] = "Sembla que aquesta comanda prové d'una versió anterior de la plataforma, incompatible amb la nova funcionalitat de revisió. Em sap greu, però no es pot revisar aquesta comanda.";
$Text['title_addToOrder'] = "Afegir ítem a la comanda";
$Text['btn_addToOrder'] = "Afegir ítem";


//added 29.09
Expand Down
2 changes: 2 additions & 0 deletions local_config/lang/en.php
Expand Up @@ -789,6 +789,8 @@
$Text['msg_confirm_move'] = "Are you sure you want to make this order available for shopping? All corresponding products will be placed into the shopping cart for the following date:";
$Text['alter_date'] = "Choose an alternative date";
$Text['msg_err_miss_info'] = "It seems that this order was created with an older version of the platform which is incompatible with the current revision functionality. Sorry, but this order cannot be revised.";
$Text['title_addToOrder'] = "Add item to the Order";
$Text['btn_addToOrder'] = "Add item";


//added 29.09
Expand Down
2 changes: 2 additions & 0 deletions local_config/lang/es.php
Expand Up @@ -789,6 +789,8 @@
$Text['msg_confirm_move'] = "¿Está seguro de que quiere hacer disponible el pedido para la compra? Todos los productos asociados seran distribuidos en las cestas para la fecha:";
$Text['alter_date'] = "Escoja una fecha alternativa";
$Text['msg_err_miss_info'] = "Aparentemente este pedido fue creado con una versión más antigua del software que es incompatible con la funcionalidad de revisión actual. Lo siento, este pedido no puede ser revisado.";
$Text['title_addToOrder'] = "Añadir ítem al pedido";
$Text['btn_addToOrder'] = "Añadir ítem";


//added 29.09
Expand Down
112 changes: 108 additions & 4 deletions manage_orders.php
Expand Up @@ -101,7 +101,8 @@
$('.success_msg').hide();

//loading animation
$('.loadSpinner').attr('src', "img/ajax-loader-<?=$default_theme;?>.gif");
$('.loadSpinner').attr('src', "img/ajax-loader-<?=$default_theme;?>.gif");
$('.loadSpinner_order').attr('src', "img/ajax-loader-<?=$default_theme;?>.gif");


var header = [];
Expand Down Expand Up @@ -287,7 +288,10 @@ function refreshTotalOrder() {
//STEP 2: construct table structure: products and col-cells.
$('#tbl_reviseOrder tbody').xml2html('init',{
url : 'php/ctrl/Orders.php',
loadOnInit : false,
loadOnInit : false,
beforeLoad : function() {
$('.loadSpinner_order').show();
},
rowComplete : function (rowIndex, row){

var product_id = $(row).children(':first').text();
Expand All @@ -314,6 +318,7 @@ function refreshTotalOrder() {
},
complete : function (rowCount){
if (!gSelRow) {
$('.loadSpinner_order').hide();
return;
}
//STEP 3: populate cells with product quantities
Expand All @@ -322,7 +327,7 @@ function refreshTotalOrder() {
url: 'php/ctrl/Orders.php?oper=getProductQuantiesForUfs&order_id='+ gSelRow.attr('orderId')+'&provider_id='+gSelRow.attr("providerId")+'&date_for_order='+gSelRow.attr("dateForOrder"),
dataType:"xml",
success: function(xml){

$('.loadSpinner_order').hide();
var quTotal = 0;
var quShopTotal = 0;
var quShop = 0;
Expand Down Expand Up @@ -414,11 +419,12 @@ function refreshTotalOrder() {
$('#tbl_reviseOrder').show();
},
error : function(XMLHttpRequest, textStatus, errorThrown){
$('.loadSpinner_order').hide();
$.showMsg({
msg:XMLHttpRequest.responseText,
type: 'error'});
}
}); //end ajax
}); //end ajax

}
});
Expand All @@ -436,6 +442,66 @@ function refreshTotalOrder() {
switchTo('overview');
}).hide();

// Add item to order
$("#btn_addToOrder").button({
icons: {
primary: "ui-icon-plus"
}
}).click(function(e) {
$('#dialog_addToOrder').dialog("open");
}).hide();
$('#dialog_addToOrder').dialog({
autoOpen: false,
width: 600,
height: 300,
buttons: {
"<?=i18n_js('btn_addToOrder');?>": function() {
$('#tbl_reviseOrder').hide();
var $this = $(this);
$.ajax({
type: "POST",
url: 'php/ctrl/Orders.php?oper=editQuantity' +
'&order_id=' +gSelRow.attr('orderId') +
'&product_id=' + $('#ordItemAdd_product').val() +
'&uf_id=' + $('#ordItemAdd_uf').val() +
'&quantity=' + $('#ordItemAdd_quantity').val(),
success: function(txt) {
$('#tbl_reviseOrder tbody').xml2html("reload", {
//reload order details for revision
params: 'oper=getOrderedProductsListPrices' +
'&order_id=' + gSelRow.attr("orderId") +
'&provider_id=' + gSelRow.attr("providerId") +
'&date=' + gSelRow.attr("dateForOrder") +
'&page=review'
});
$('#dialog_addToOrder').dialog("close");
},
error: function(XMLHttpRequest, textStatus, errorThrown){
$('#tbl_reviseOrder').show();
$.showMsg({
msg:XMLHttpRequest.responseText,
type: 'error'});

}
});
},
"<?=$Text['btn_close'];?>": function() {
$(this).dialog("close");
}
}
});
$('#ordItemAdd_product').xml2html("init", {
url: "php/ctrl/Orders.php",
offSet: 1,
loadOnInit: false,
complete: function() { }
});
$('#ordItemAdd_uf').xml2html("init", {
url: "php/ctrl/Orders.php",
offSet: 1,
loadOnInit: false,
complete: function() { }
});

/**
* copies order_items after revision into aixada_shop_item only if not already
Expand Down Expand Up @@ -1637,6 +1703,8 @@ function switchTo(page, options){
$('.reviewElements, .viewElements').hide();
$('#btn_setShopDate').hide();
$('#btn_disValidate').hide();
$('#btn_addToOrder').hide();
$('#dialog_addToOrder').dialog("close");
$('.overviewElements').fadeIn(1000);
$('#tbl_orderOverview tbody tr').removeClass('ui-state-highlight');
gSelRow.addClass('ui-state-highlight');
Expand Down Expand Up @@ -1664,6 +1732,16 @@ function switchTo(page, options){
$('#btn_setShopDate').show();
$('#btn_disValidate').show();
}
$('#ordItemAdd_product').xml2html("reload",{
params: 'oper=getAllProductsToOrder&order_id=' +
gSelRow.attr('orderId')

});
$('#ordItemAdd_uf').xml2html("reload",{
params: 'oper=getAllUfsToOrder&order_id=' +
gSelRow.attr('orderId')
});
$('#btn_addToOrder').show();

$('#dialog_orderStatus button').button('enable');
$('#btn_'+gRevStatus[sindex]).button('disable');
Expand Down Expand Up @@ -1764,8 +1842,10 @@ function recalcRowTotal(product_id){

<button id="btn_disValidate" class="btn_right" title="<?=$Text['btn_disValitate'];?>"><?=$Text['btn_disValitate'];?></button>
<button id="btn_setShopDate" class="btn_right" title="<?=$Text['distribute_desc'];?>"><?=$Text['btn_distribute'];?></button>
<button id="btn_addToOrder" class="btn_right" title="<?=i18n('addToOrder_desc');?>"><?=i18n('btn_addToOrder');?></button>
<button id="tblViewOptions" class="overviewElements btn_right"><?=$Text['filter_orders']; ?></button>
<button id="btn_order_export" class="floatRight viewElements" ><?php echo $Text['btn_export']; ?></button>
<span style="float:right; margin-top:0px; margin-right:5px;"><img class="loadSpinner_order hidden" src="img/ajax-loader.gif"/></span>

<div id="tblOptionsItems" class="hidden">
<ul>
Expand Down Expand Up @@ -2108,6 +2188,30 @@ class="ui-button-icon-primary ui-icon ui-icon-gear" ></span></button>
</table>
</div>

<div id="dialog_addToOrder" title="<?php echo i18n('title_addToOrder') ?>">
<table><tr>
<td><?php echo i18n('product_name');?>:</td>
<td><select id="ordItemAdd_product" class="longSelect">
<option value="" selected="selected">(...)</option>
<option value="{id}">{product_name}</option>
</select>
</td>
</tr><tr>
<td><?php echo i18n('uf_long');?>:</td>
<td><select id="ordItemAdd_uf" class="longSelect">
<option value="" selected="selected">(...)</option>
<option value="{id}">{uf_name}</option>
</select>
</td>
</tr><tr>
<td><?php echo i18n('quantity');?>:</td>
<td><input type="text" id="ordItemAdd_quantity"
class="inputTxtMiddle ui-widget-content ui-corner-all"
autocomplete="off"
value=""
></td>
</tr></table>
</div>

<div id="dialog_convertPreorder" title="Convert preorder to order">
<p>&nbsp;</p>
Expand Down
10 changes: 10 additions & 0 deletions php/ctrl/Orders.php
Expand Up @@ -42,6 +42,16 @@
get_param('page', '-')
)));
exit;
case 'getAllProductsToOrder':
printXML(rs_XML_fields(get_all_products_to_order(
get_param_int('order_id')
)));
exit;
case 'getAllUfsToOrder':
printXML(rs_XML_fields(get_all_ufs_to_order(
get_param_int('order_id')
)));
exit;

//retrieves the order detail uf/quantities for given order. order_id OR provider_id / date are needed. Filters for uf and/or product_id if needed.
case 'getProductQuantiesForUfs':
Expand Down
55 changes: 52 additions & 3 deletions php/utilities/orders.php
Expand Up @@ -206,13 +206,13 @@ function reset_order_to_shop($order_id, $clear) {
function edit_order_quantity($order_id, $product_id, $uf_id, $quantity){
// Check parameters
if (!is_numeric($product_id)) {
throw new Exception("`product_id` must be integer!");
throw new Exception(i18n('product_name') . ': ' . i18n('msg_err_only_num'));
}
if (!is_numeric($uf_id)) {
throw new Exception("`uf_id` must be integer!");
throw new Exception(i18n('uf_long') . ': ' . i18n('msg_err_only_num'));
}
if (!is_numeric($quantity)) {
throw new Exception("`quantity` must be numeric!");
throw new Exception(i18n('quantity') . ': ' . i18n('msg_err_only_num'));
}
// Check if exist
prepare_order_to_shop($order_id); // and check $order_id parameter
Expand Down Expand Up @@ -893,4 +893,53 @@ function get_ordered_products_with_prices(
order by name;";
return $db->Execute($sql2);
}

function get_all_products_to_order($order_id)
{
$rowOrder = get_row_query(
"select provider_id
from aixada_order
where id = {$order_id};"
);
if (!$rowOrder) {
throw new Exception("Order not exists!");
}
$provider_id = $rowOrder['provider_id'];
$db = DBWrap::get_instance();
$sql = "
select p.id,
concat(p.name, if((
select count(*)
from aixada_order_item oi
where oi.order_id = {$order_id}
and p.id = oi.product_id
) > 0
, '', ' (+)'
)) product_name
from aixada_product p
where p.active = 1
and p.orderable_type_id <> 3
and p.provider_id = {$provider_id}
group by p.id, p.name
order by p.name;";
return $db->Execute($sql);
}

function get_all_ufs_to_order($order_id)
{
$db = DBWrap::get_instance();
$sql = "
select uf.id, concat(uf.name, ' #', uf.id, if((
select count(*)
from aixada_order_item oi
where oi.order_id = {$order_id}
and uf.id = oi.uf_id
) > 0
, '', ' (+)'
)) uf_name
from aixada_uf uf
where uf.active = 1
order by uf.name;";
return $db->Execute($sql);
}
?>

0 comments on commit 5e403e6

Please sign in to comment.