sell product list

This commit is contained in:
2015-10-05 17:24:26 +02:00
parent 203dfeac72
commit 2610749305
15 changed files with 373 additions and 40 deletions

View File

@@ -1,13 +1,21 @@
function ProductSell(o){
/**reference for the instance*/
var app = this;
/**currently loaded product*/
var product = null;
this.defaults = {
/**id of filter text*/
selector_filter_text: '#filter_text',
lookup_product_url: '' ,
/** ajax url for lookup service*/
lookup_product_url: '',
/**the id of form*/
selector_form: '#product_form',
form_invalid: 'Az ürlap hibákat tartalmaz'
/**form contains error text*/
form_invalid: 'Az ürlap hibákat tartalmaz',
/**list of sold items by current user*/
sold_items: [],
};
init();
@@ -25,13 +33,18 @@ function ProductSell(o){
addBehaviorAccountEnterPressedListener();
addBehaviorDiscountEnterPressedListener();
productChanged();
createUserSoldItemsTable();
}
/**
* set the focus for text input #filter_text
* */
function setFocus(){
$("#filter_text").focus();
}
/**listen for enter key pressed on #filter_text*/
function addBehaviorEnterPressedListener(){
$( app.defaults.selector_filter_text ).keypress(function( event ) {
if ( event.which == 13 ) {
@@ -41,6 +54,7 @@ function ProductSell(o){
});
}
/**listen for enter key pressed on #productsaleform-count*/
function addBehaviorCountEnterPressedListener(){
$( '#productsaleform-count' ).keypress(function( event ) {
if ( event.which == 13 ) {
@@ -50,7 +64,7 @@ function ProductSell(o){
}
});
}
/**listen for enter key pressed on #productsaleform-id_currency*/
function addBehaviorCurrencyEnterPressedListener(){
$( '#productsaleform-id_currency' ).keypress(function( event ) {
if ( event.which == 13 ) {
@@ -60,6 +74,7 @@ function ProductSell(o){
}
});
}
/**listen for enter key pressed on #productsaleform-id_account*/
function addBehaviorAccountEnterPressedListener(){
$( '#productsaleform-id_account' ).keypress(function( event ) {
if ( event.which == 13 ) {
@@ -69,7 +84,7 @@ function ProductSell(o){
}
});
}
/**listen for enter key pressed on #productsaleform-id_discount*/
function addBehaviorDiscountEnterPressedListener(){
$( '#productsaleform-id_discount' ).keypress(function( event ) {
if ( event.which == 13 ) {
@@ -79,7 +94,7 @@ function ProductSell(o){
}
});
}
/**listen for event "change" #productsaleform-count*/
function addBehaviorCountChangedListener(){
$( '#productsaleform-count' ).change(function( event ) {
refreshCalculatedValues();
@@ -87,6 +102,7 @@ function ProductSell(o){
});
}
/**load a product from server by exact barcode or product number*/
function lookupProduct(){
var data, url;
@@ -103,12 +119,13 @@ function ProductSell(o){
});
}
/**succes event handler after lookup product event*/
function onLookupProductReady( data ){
app.product = data.product;
productChanged();
}
/**handles product change.*/
function productChanged( ){
clearForm();
if ( app.product != null){
@@ -119,26 +136,30 @@ function ProductSell(o){
}
function clearForm(){
$('.product-name').html('-');
$('.product-price').html('-');
$('.product-number').html('-');
$('.product-barcode').html('-');
$('.product-stock').html('-');
$('.product-price').html('-');
$('.product-sale-price').html('-');
$("#productsaleform-count").val(1);
$('#productsaleform-id_product').val('');
$('#productsaleform-id_account').val('');
var table;
table = $('.table-product');
table.find('.product-name').html('-');
table.find('.product-price').html('-');
table.find('.product-number').html('-');
table.find('.product-barcode').html('-');
table.find('.product-stock').html('-');
table.find('.product-price').html('-');
table.find('.product-sale-price').html('-');
table.find("#productsaleform-count").val(1);
table.find('#productsaleform-id_product').val('');
table.find('#productsaleform-id_account').val('');
}
function applyProduct(product){
$('#productsaleform-id_product').val(product.id_product);
$('.product-name').html(product.name);
$('.product-sale-price').html(product.sale_price);
$('.product-number').html(product.product_number);
$('.product-barcode').html(product.barcode);
$('.product-stock').html(product.stock);
$('#productsaleform-id_account').val(product.id_account);
var table;
table = $('.table-product');
table.find('#productsaleform-id_product').val(product.id_product);
table.find('.product-name').html(product.name);
table.find('.product-sale-price').html(product.sale_price);
table.find('.product-number').html(product.product_number);
table.find('.product-barcode').html(product.barcode);
table.find('.product-stock').html(product.stock);
table.find('#productsaleform-id_account').val(product.id_account);
}
@@ -159,12 +180,22 @@ function ProductSell(o){
}
function addBehaviourBtnSellAndAppendToBill(){
$('#btn_sell_append').on('click',submitSell);
$('#btn_sell_append').on('click',submitSellAndAppend);
}
function submitSell(){
$('#productsaleform-append_to_sold_list').val('');
$('#product_form').submit();
}
function submitSellAndAppend(){
$('#productsaleform-append_to_sold_list').val('append');
$('#product_form').submit();
}
function refreshSoldUseritems(){
$('.sold-items-container').transferList('option','transfers' , app.defaults.sold_items );
}
function addBehaviorAjaxSubmit(){
@@ -188,6 +219,9 @@ function ProductSell(o){
refreshCalculatedValues();
$("#filter_text").val('');
setFocus();
app.defaults.sold_items = response.transfers;
$('.sold-items-container').transferList( 'option', 'transfers' , app.defaults.sold_items );
}else if ( response.code == 'invalid'){
if ( response.errors ){
$.each(response.errors, function (key, value){
@@ -206,4 +240,13 @@ function ProductSell(o){
}
function createUserSoldItemsTable(){
console.info( app.defaults.sold_items );
$('.sold-items-container').transferList({
'transfers' : app.defaults.sold_items
});
}
}

View File

@@ -6,29 +6,56 @@ $.widget( "fitness.transferList", {
{ 'label' : 'Ár' },
{ 'label' : 'Db' },
{ 'label' : 'Összesen' },
],
footers: [
{
'label' : 'Összesen',
'total' : function(transfers){
var totals;
totals = 0;
for ( var i = 0; i < transfers.length ; i++ ){
totals += transfers[i].money;
}
return totals;
},
'count' : function(transfers){
var totals;
totals = 0;
for ( var i = 0; i < transfers.length ; i++ ){
totals += transfers[i].count;
}
return totals;
},
}
]
},
_create: function() {
var o;
o = this.options;
this._refresh();
},
_refresh: function(){
var s;
s = this._render('table',{ 'columns' : this.options.columns });
s = this._render('table',{ 'columns' : this.options.columns, 'transfers' : this.options.transfers,'footer': this.options.footers });
this.element.html(s);
},
_render: function(template,params){
var s;
var columsn;
var transfer;
var footer;
s = "";
switch(template){
case 'table':
s += this._render('openTable', {});
s += this._render('header', { 'columns' : params.columns });
s += this._render('closeTable', {});
s += this._render('header', { 'columns' : params.columns });
s += this._render('body' , { 'transfers' : params.transfers });
s += this._render('footer' , { 'transfers' : params.transfers ,'footers': this.options.footers});
s += this._render('closeTable', { });
break;
case 'openTable':
s += '<table class="table table-bordered table-striped">';
s += '<table class="table table-bordered table-striped table-transfers">';
break;
case 'closeTable':
s += '</table>';
@@ -48,17 +75,70 @@ $.widget( "fitness.transferList", {
break;
case 'body':
s += '<tbody>';
for( var i = 0; i < transfers.length; i++){
for( var i = 0; i < params.transfers.length; i++){
s += this._render('row', { 'transfer' : params.transfers[i] })
}
s += '</tbody>';
break;
case 'row':
transfer = params.transfer;
s += '<tr>';
s += '<td class="product-name">';
s += transfer.product_name;
s += '</td>';
s += '<td class="sale-price">';
s += transfer.item_price;
s += '</td>';
s += '<td class=\'product-count\' >';
s += transfer.count;
s += '</td>';
s += '<td class=\'product-money\' >';
s += transfer.money;
s += '</td>';
s += '</tr>';
break;
case 'footer':
s += "<tfoot>";
for ( var i = 0; i < params.footers.length; i++ ){
footer = params.footers[i];
s += "<tr class='warning' >";
s += "<th class='product-name'>";
s += footer.label;
s += "</th>";
s += "<td class=\"sale-price\">";
s += "</td>";
s += "<td class=\'product-count\' >";
s += footer.count( params.transfers );
s += "</td>";
s += "<td class=\'product-money\' >";
s += footer.total( params.transfers );
s += "</td>";
s += "</tr>";
}
s += "</tfoot>";
break;
}
return s;
},
_setOption: function (key, value) {
var self = this,
prev = this.options[key],
fnMap = {
'transfers': function () {
self._refresh();
},
};
// base
this._super(key, value);
if (key in fnMap) {
fnMap[key]();
// Fire event
// this._triggerOptionChanged(key, prev, value);
}
}