add changes to sell product
This commit is contained in:
parent
2610749305
commit
8fbe963379
@ -148,7 +148,7 @@ class Transfer extends \yii\db\ActiveRecord
|
|||||||
return $transfer;
|
return $transfer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function modelsToArray($transfers,$default = null){
|
public static function modelsToArray($transfers,$default = []){
|
||||||
|
|
||||||
if ( $transfers == null ){
|
if ( $transfers == null ){
|
||||||
return $default;
|
return $default;
|
||||||
@ -161,6 +161,9 @@ class Transfer extends \yii\db\ActiveRecord
|
|||||||
'count',
|
'count',
|
||||||
'money',
|
'money',
|
||||||
'money_currency',
|
'money_currency',
|
||||||
|
'time' => function ($transfer){
|
||||||
|
return Yii::$app->formatter->asTime($transfer->created_at);
|
||||||
|
},
|
||||||
'account_name' => function ($transfer) {
|
'account_name' => function ($transfer) {
|
||||||
return $transfer->account->name;
|
return $transfer->account->name;
|
||||||
},
|
},
|
||||||
|
|||||||
@ -19,6 +19,7 @@ use common\models\Account;
|
|||||||
use common\models\Discount;
|
use common\models\Discount;
|
||||||
use common\models\Transfer;
|
use common\models\Transfer;
|
||||||
use common\models\User;
|
use common\models\User;
|
||||||
|
use common\models\UserSoldItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProductController implements the CRUD actions for Product model.
|
* ProductController implements the CRUD actions for Product model.
|
||||||
@ -105,6 +106,26 @@ class ProductController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionClearList(){
|
||||||
|
|
||||||
|
if (Yii::$app->request->isAjax) {
|
||||||
|
$result = [];
|
||||||
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
|
||||||
|
|
||||||
|
$user = User::findOne(Yii::$app->user->id );
|
||||||
|
|
||||||
|
UserSoldItem::deleteAll(['id_user' => Yii::$app->user->id]);
|
||||||
|
|
||||||
|
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
|
||||||
|
$result['transfers'] = $userTransfers;
|
||||||
|
$result['code'] = 'success';
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists all Product models.
|
* Lists all Product models.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|||||||
@ -18,6 +18,7 @@ ProductSellAsset::register($this);
|
|||||||
$options = [];
|
$options = [];
|
||||||
|
|
||||||
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
|
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
|
||||||
|
$options['clear_list_url'] = Url::toRoute(['product/clear-list']);
|
||||||
$options['sold_items'] = $userTransfers;
|
$options['sold_items'] = $userTransfers;
|
||||||
|
|
||||||
|
|
||||||
@ -39,6 +40,24 @@ $this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
|
|||||||
margin-bottom: 3px;
|
margin-bottom: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.table-transfers thead th{
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-transfers tfoot .product-money,
|
||||||
|
.table-transfers tfoot .product-count,
|
||||||
|
.table-transfers tbody .product-money,
|
||||||
|
.table-transfers tbody .product-count,
|
||||||
|
.table-transfers tbody .sale-price
|
||||||
|
{
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
.table-transfers tbody .product-name,
|
||||||
|
.table-transfers tbody .product-time
|
||||||
|
{
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class='row'>
|
<div class='row'>
|
||||||
@ -55,8 +74,8 @@ $this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
|
|||||||
<?php echo $this->render('_sale_form' ,['model' =>$model , 'lookupModel' =>$lookupModel, 'currencies' => $currencies, 'accounts' => $accounts,'discounts' => $discounts,]) ?>
|
<?php echo $this->render('_sale_form' ,['model' =>$model , 'lookupModel' =>$lookupModel, 'currencies' => $currencies, 'accounts' => $accounts,'discounts' => $discounts,]) ?>
|
||||||
</div>
|
</div>
|
||||||
<div class='col-md-6'>
|
<div class='col-md-6'>
|
||||||
<h1><?php echo Yii::t('frontend/product','Sold')?></h1>
|
<h1><?php echo Yii::t('frontend/product','Cart')?></h1>
|
||||||
<?php echo $this->render('_sold_items' ) ?>
|
<?php echo $this->render('_sold_items' ) ?>
|
||||||
<?php echo Html::a(Yii::t('frontend/product', "Paid"),null,[ 'class' => 'btn btn-primary' ]) ?>
|
<?php echo Html::a(Yii::t('frontend/product', "Paid"),null,[ 'id' => 'btn_paid', 'class' => 'btn btn-primary' ]) ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
6
frontend/web/coffee/keypresslistener.coffee
Normal file
6
frontend/web/coffee/keypresslistener.coffee
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class KeypressListener
|
||||||
|
|
||||||
|
constructor: (@name) ->
|
||||||
|
|
||||||
|
listen: ()->
|
||||||
|
|
||||||
@ -10,10 +10,13 @@ function ProductSell(o){
|
|||||||
selector_filter_text: '#filter_text',
|
selector_filter_text: '#filter_text',
|
||||||
/** ajax url for lookup service*/
|
/** ajax url for lookup service*/
|
||||||
lookup_product_url: '',
|
lookup_product_url: '',
|
||||||
|
/**mark list paid url*/
|
||||||
|
clear_list_url: '',
|
||||||
/**the id of form*/
|
/**the id of form*/
|
||||||
selector_form: '#product_form',
|
selector_form: '#product_form',
|
||||||
/**form contains error text*/
|
/**form contains error text*/
|
||||||
form_invalid: 'Az ürlap hibákat tartalmaz',
|
form_invalid: 'Az ürlap hibákat tartalmaz',
|
||||||
|
message_paid: 'Tételek fizetve',
|
||||||
/**list of sold items by current user*/
|
/**list of sold items by current user*/
|
||||||
sold_items: [],
|
sold_items: [],
|
||||||
};
|
};
|
||||||
@ -22,18 +25,82 @@ function ProductSell(o){
|
|||||||
|
|
||||||
function init(){
|
function init(){
|
||||||
$.extend(app.defaults, o );
|
$.extend(app.defaults, o );
|
||||||
addBehaviorEnterPressedListener();
|
app.keyDate = null;
|
||||||
|
app.keySeq = '';
|
||||||
|
app.enterPressed = 0;
|
||||||
addBehaviourBtnSell();
|
addBehaviourBtnSell();
|
||||||
addBehaviourBtnSellAndAppendToBill();
|
addBehaviourBtnSellAndAppendToBill();
|
||||||
addBehaviorAjaxSubmit();
|
addBehaviorAjaxSubmit();
|
||||||
setFocus();
|
setFocus();
|
||||||
addBehaviorCountEnterPressedListener();
|
addEnterPressedBehaviours();
|
||||||
addBehaviorCountChangedListener();
|
addBehaviorCountChangedListener();
|
||||||
|
createUserSoldItemsTable();
|
||||||
|
addBehaviourBtnPaid();
|
||||||
|
productChanged();
|
||||||
|
addDocumentKeypressedListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
function addDocumentKeypressedListener(){
|
||||||
|
$( document ).keypress(function( event ) {
|
||||||
|
|
||||||
|
var tag = event.target.tagName.toLowerCase();
|
||||||
|
if ( tag != 'input' && tag != 'textarea') {
|
||||||
|
|
||||||
|
resetSequenceIfToMuchTimePassedOrEnterWasPressed(event);
|
||||||
|
|
||||||
|
if ( event.which == 13 ) {
|
||||||
|
app.enterPressed = 1;
|
||||||
|
$( document ).trigger( "wordtyped", [ { originalEvent: event, 'word': app.seq } ] );
|
||||||
|
}else {
|
||||||
|
appendCharToSeq(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$( document ).on( "wordtyped", function( event, data ) {
|
||||||
|
var word;
|
||||||
|
word = data.word;
|
||||||
|
if ( word.length > 0){
|
||||||
|
if ( word.length >= 6 && word.length <= 8 ){
|
||||||
|
//lookupuser
|
||||||
|
}else{
|
||||||
|
$("#filter_text").val(data.word);
|
||||||
|
_lookupProduct(data.word);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function resetSequenceIfToMuchTimePassedOrEnterWasPressed(){
|
||||||
|
var prevDate, timePassed;
|
||||||
|
prevDate= app.keyDate;
|
||||||
|
app.keyDate = new Date().getTime();
|
||||||
|
timePassed = app.keyDate - prevDate;
|
||||||
|
if ( app.enterPressed > 0 || timePassed > 2000 ){
|
||||||
|
app.seq = '';
|
||||||
|
app.enterPressed = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendCharToSeq(event){
|
||||||
|
var code,s;
|
||||||
|
code = event.which;
|
||||||
|
if ( code ){
|
||||||
|
s = String.fromCharCode(code);
|
||||||
|
app.seq += s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addEnterPressedBehaviours(){
|
||||||
|
addBehaviorEnterPressedListener();
|
||||||
|
addBehaviorCountEnterPressedListener();
|
||||||
addBehaviorCurrencyEnterPressedListener();
|
addBehaviorCurrencyEnterPressedListener();
|
||||||
addBehaviorAccountEnterPressedListener();
|
addBehaviorAccountEnterPressedListener();
|
||||||
addBehaviorDiscountEnterPressedListener();
|
addBehaviorDiscountEnterPressedListener();
|
||||||
productChanged();
|
|
||||||
createUserSoldItemsTable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,19 +171,23 @@ function ProductSell(o){
|
|||||||
|
|
||||||
/**load a product from server by exact barcode or product number*/
|
/**load a product from server by exact barcode or product number*/
|
||||||
function lookupProduct(){
|
function lookupProduct(){
|
||||||
|
_lookupProduct($( app.defaults.selector_filter_text ).val());
|
||||||
|
}
|
||||||
|
|
||||||
|
function _lookupProduct(s){
|
||||||
var data, url;
|
var data, url;
|
||||||
|
|
||||||
url = app.defaults.lookup_product_url;
|
url = app.defaults.lookup_product_url;
|
||||||
data = {
|
data = {
|
||||||
'query' : $( app.defaults.selector_filter_text ).val()
|
'query' : s,
|
||||||
};
|
};
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
url: url,
|
url: url,
|
||||||
data: data,
|
data: data,
|
||||||
success: onLookupProductReady
|
success: onLookupProductReady
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**succes event handler after lookup product event*/
|
/**succes event handler after lookup product event*/
|
||||||
@ -145,34 +216,36 @@ function ProductSell(o){
|
|||||||
table.find('.product-stock').html('-');
|
table.find('.product-stock').html('-');
|
||||||
table.find('.product-price').html('-');
|
table.find('.product-price').html('-');
|
||||||
table.find('.product-sale-price').html('-');
|
table.find('.product-sale-price').html('-');
|
||||||
table.find("#productsaleform-count").val(1);
|
$('#productsaleform-id_product').val('');
|
||||||
table.find('#productsaleform-id_product').val('');
|
$('#productsaleform-id_account').val('');
|
||||||
table.find('#productsaleform-id_account').val('');
|
$("#productsaleform-count").val(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyProduct(product){
|
function applyProduct(product){
|
||||||
var table;
|
var table;
|
||||||
table = $('.table-product');
|
table = $('.table-product');
|
||||||
table.find('#productsaleform-id_product').val(product.id_product);
|
|
||||||
table.find('.product-name').html(product.name);
|
table.find('.product-name').html(product.name);
|
||||||
table.find('.product-sale-price').html(product.sale_price);
|
table.find('.product-sale-price').html(product.sale_price);
|
||||||
table.find('.product-number').html(product.product_number);
|
table.find('.product-number').html(product.product_number);
|
||||||
table.find('.product-barcode').html(product.barcode);
|
table.find('.product-barcode').html(product.barcode);
|
||||||
table.find('.product-stock').html(product.stock);
|
table.find('.product-stock').html(product.stock);
|
||||||
table.find('#productsaleform-id_account').val(product.id_account);
|
$('#productsaleform-id_product').val(product.id_product);
|
||||||
|
$('#productsaleform-id_account').val(product.id_account);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshCalculatedValues(){
|
function refreshCalculatedValues(){
|
||||||
var count,price;
|
var count,price;
|
||||||
|
var table;
|
||||||
|
table = $('.table-product');
|
||||||
count = $("#productsaleform-count").val();
|
count = $("#productsaleform-count").val();
|
||||||
count = +count;
|
count = +count;
|
||||||
if ( isNaN(count)){
|
if ( isNaN(count)){
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
price = count * app.product.sale_price;
|
price = count * app.product.sale_price;
|
||||||
$('.product-count').html(count);
|
table.find('.product-count').html(count);
|
||||||
$('.product-price').html(price);
|
table.find('.product-price').html(price);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addBehaviourBtnSell(){
|
function addBehaviourBtnSell(){
|
||||||
@ -199,6 +272,16 @@ function ProductSell(o){
|
|||||||
|
|
||||||
function addBehaviorAjaxSubmit(){
|
function addBehaviorAjaxSubmit(){
|
||||||
|
|
||||||
|
$('body').on('afterValidate', '#product_form', function () {
|
||||||
|
var form = $(this);
|
||||||
|
// return false if form still have some validation errors
|
||||||
|
if ( form.find('.has-error').length ) {
|
||||||
|
$.notify(app.defaults.form_invalid, { 'type' : 'warning' });
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$('body').on('beforeSubmit', '#product_form', function () {
|
$('body').on('beforeSubmit', '#product_form', function () {
|
||||||
var form = $(this);
|
var form = $(this);
|
||||||
// return false if form still have some validation errors
|
// return false if form still have some validation errors
|
||||||
@ -206,13 +289,13 @@ function ProductSell(o){
|
|||||||
$.notify(app.defaults.form_invalid, { 'type' : 'success' });
|
$.notify(app.defaults.form_invalid, { 'type' : 'success' });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// submit form
|
// submit form
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: form.attr('action'),
|
url: form.attr('action'),
|
||||||
type: 'post',
|
type: 'post',
|
||||||
data: form.serialize(),
|
data: form.serialize(),
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
// do something with response
|
|
||||||
if ( response.code == 'success'){
|
if ( response.code == 'success'){
|
||||||
$.notify(response.message, { 'type' : 'success' });
|
$.notify(response.message, { 'type' : 'success' });
|
||||||
clearForm();
|
clearForm();
|
||||||
@ -220,8 +303,7 @@ function ProductSell(o){
|
|||||||
$("#filter_text").val('');
|
$("#filter_text").val('');
|
||||||
setFocus();
|
setFocus();
|
||||||
app.defaults.sold_items = response.transfers;
|
app.defaults.sold_items = response.transfers;
|
||||||
$('.sold-items-container').transferList( 'option', 'transfers' , app.defaults.sold_items );
|
refreshSoldItemsList();
|
||||||
|
|
||||||
}else if ( response.code == 'invalid'){
|
}else if ( response.code == 'invalid'){
|
||||||
if ( response.errors ){
|
if ( response.errors ){
|
||||||
$.each(response.errors, function (key, value){
|
$.each(response.errors, function (key, value){
|
||||||
@ -240,8 +322,31 @@ function ProductSell(o){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function refreshSoldItemsList(){
|
||||||
|
$('.sold-items-container').transferList( 'option', 'transfers' , app.defaults.sold_items );
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBehaviourBtnPaid( ){
|
||||||
|
$('#btn_paid').on('click',function(){
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: app.defaults.clear_list_url,
|
||||||
|
type: 'post',
|
||||||
|
data: {},
|
||||||
|
success: function (response) {
|
||||||
|
if ( response.code == 'success'){
|
||||||
|
app.defaults.sold_items= response.transfers;
|
||||||
|
refreshSoldItemsList();
|
||||||
|
$.notify(app.defaults.message_paid, { 'type' : 'success' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function createUserSoldItemsTable(){
|
function createUserSoldItemsTable(){
|
||||||
console.info( app.defaults.sold_items );
|
|
||||||
$('.sold-items-container').transferList({
|
$('.sold-items-container').transferList({
|
||||||
'transfers' : app.defaults.sold_items
|
'transfers' : app.defaults.sold_items
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,6 +2,8 @@ $.widget( "fitness.transferList", {
|
|||||||
options: {
|
options: {
|
||||||
transfers: [],
|
transfers: [],
|
||||||
columns: [
|
columns: [
|
||||||
|
|
||||||
|
{ 'label' : 'Idő' },
|
||||||
{ 'label' : 'Termék' },
|
{ 'label' : 'Termék' },
|
||||||
{ 'label' : 'Ár' },
|
{ 'label' : 'Ár' },
|
||||||
{ 'label' : 'Db' },
|
{ 'label' : 'Db' },
|
||||||
@ -83,6 +85,9 @@ $.widget( "fitness.transferList", {
|
|||||||
case 'row':
|
case 'row':
|
||||||
transfer = params.transfer;
|
transfer = params.transfer;
|
||||||
s += '<tr>';
|
s += '<tr>';
|
||||||
|
s += '<td class="product-time">';
|
||||||
|
s += transfer.time;
|
||||||
|
s += '</td>';
|
||||||
s += '<td class="product-name">';
|
s += '<td class="product-name">';
|
||||||
s += transfer.product_name;
|
s += transfer.product_name;
|
||||||
s += '</td>';
|
s += '</td>';
|
||||||
@ -102,9 +107,11 @@ $.widget( "fitness.transferList", {
|
|||||||
for ( var i = 0; i < params.footers.length; i++ ){
|
for ( var i = 0; i < params.footers.length; i++ ){
|
||||||
footer = params.footers[i];
|
footer = params.footers[i];
|
||||||
s += "<tr class='warning' >";
|
s += "<tr class='warning' >";
|
||||||
s += "<th class='product-name'>";
|
s += "<th class='product-time'>";
|
||||||
s += footer.label;
|
s += footer.label;
|
||||||
s += "</th>";
|
s += "</th>";
|
||||||
|
s += "<th class='product-name'>";
|
||||||
|
s += "</th>";
|
||||||
s += "<td class=\"sale-price\">";
|
s += "<td class=\"sale-price\">";
|
||||||
s += "</td>";
|
s += "</td>";
|
||||||
s += "<td class=\'product-count\' >";
|
s += "<td class=\'product-count\' >";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user