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;
|
||||
}
|
||||
|
||||
public static function modelsToArray($transfers,$default = null){
|
||||
public static function modelsToArray($transfers,$default = []){
|
||||
|
||||
if ( $transfers == null ){
|
||||
return $default;
|
||||
@ -161,6 +161,9 @@ class Transfer extends \yii\db\ActiveRecord
|
||||
'count',
|
||||
'money',
|
||||
'money_currency',
|
||||
'time' => function ($transfer){
|
||||
return Yii::$app->formatter->asTime($transfer->created_at);
|
||||
},
|
||||
'account_name' => function ($transfer) {
|
||||
return $transfer->account->name;
|
||||
},
|
||||
|
||||
@ -19,6 +19,7 @@ use common\models\Account;
|
||||
use common\models\Discount;
|
||||
use common\models\Transfer;
|
||||
use common\models\User;
|
||||
use common\models\UserSoldItem;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return mixed
|
||||
|
||||
@ -18,6 +18,7 @@ ProductSellAsset::register($this);
|
||||
$options = [];
|
||||
|
||||
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
|
||||
$options['clear_list_url'] = Url::toRoute(['product/clear-list']);
|
||||
$options['sold_items'] = $userTransfers;
|
||||
|
||||
|
||||
@ -39,6 +40,24 @@ $this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
|
||||
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>
|
||||
|
||||
<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,]) ?>
|
||||
</div>
|
||||
<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 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>
|
||||
|
||||
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',
|
||||
/** ajax url for lookup service*/
|
||||
lookup_product_url: '',
|
||||
/**mark list paid url*/
|
||||
clear_list_url: '',
|
||||
/**the id of form*/
|
||||
selector_form: '#product_form',
|
||||
/**form contains error text*/
|
||||
form_invalid: 'Az ürlap hibákat tartalmaz',
|
||||
message_paid: 'Tételek fizetve',
|
||||
/**list of sold items by current user*/
|
||||
sold_items: [],
|
||||
};
|
||||
@ -22,18 +25,82 @@ function ProductSell(o){
|
||||
|
||||
function init(){
|
||||
$.extend(app.defaults, o );
|
||||
addBehaviorEnterPressedListener();
|
||||
app.keyDate = null;
|
||||
app.keySeq = '';
|
||||
app.enterPressed = 0;
|
||||
addBehaviourBtnSell();
|
||||
addBehaviourBtnSellAndAppendToBill();
|
||||
addBehaviorAjaxSubmit();
|
||||
setFocus();
|
||||
addBehaviorCountEnterPressedListener();
|
||||
addEnterPressedBehaviours();
|
||||
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();
|
||||
addBehaviorAccountEnterPressedListener();
|
||||
addBehaviorDiscountEnterPressedListener();
|
||||
productChanged();
|
||||
createUserSoldItemsTable();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,19 +171,23 @@ function ProductSell(o){
|
||||
|
||||
/**load a product from server by exact barcode or product number*/
|
||||
function lookupProduct(){
|
||||
_lookupProduct($( app.defaults.selector_filter_text ).val());
|
||||
}
|
||||
|
||||
function _lookupProduct(s){
|
||||
var data, url;
|
||||
|
||||
url = app.defaults.lookup_product_url;
|
||||
data = {
|
||||
'query' : $( app.defaults.selector_filter_text ).val()
|
||||
'query' : s,
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: url,
|
||||
data: data,
|
||||
success: onLookupProductReady
|
||||
});
|
||||
dataType: "json",
|
||||
url: url,
|
||||
data: data,
|
||||
success: onLookupProductReady
|
||||
});
|
||||
}
|
||||
|
||||
/**succes event handler after lookup product event*/
|
||||
@ -145,34 +216,36 @@ function ProductSell(o){
|
||||
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('');
|
||||
$('#productsaleform-id_product').val('');
|
||||
$('#productsaleform-id_account').val('');
|
||||
$("#productsaleform-count").val(1);
|
||||
}
|
||||
|
||||
function applyProduct(product){
|
||||
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);
|
||||
$('#productsaleform-id_product').val(product.id_product);
|
||||
$('#productsaleform-id_account').val(product.id_account);
|
||||
|
||||
}
|
||||
|
||||
function refreshCalculatedValues(){
|
||||
var count,price;
|
||||
var table;
|
||||
table = $('.table-product');
|
||||
count = $("#productsaleform-count").val();
|
||||
count = +count;
|
||||
if ( isNaN(count)){
|
||||
count = 0;
|
||||
}
|
||||
price = count * app.product.sale_price;
|
||||
$('.product-count').html(count);
|
||||
$('.product-price').html(price);
|
||||
table.find('.product-count').html(count);
|
||||
table.find('.product-price').html(price);
|
||||
}
|
||||
|
||||
function addBehaviourBtnSell(){
|
||||
@ -199,6 +272,16 @@ function ProductSell(o){
|
||||
|
||||
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 () {
|
||||
var form = $(this);
|
||||
// return false if form still have some validation errors
|
||||
@ -206,13 +289,13 @@ function ProductSell(o){
|
||||
$.notify(app.defaults.form_invalid, { 'type' : 'success' });
|
||||
return false;
|
||||
}
|
||||
|
||||
// submit form
|
||||
$.ajax({
|
||||
url: form.attr('action'),
|
||||
type: 'post',
|
||||
data: form.serialize(),
|
||||
success: function (response) {
|
||||
// do something with response
|
||||
if ( response.code == 'success'){
|
||||
$.notify(response.message, { 'type' : 'success' });
|
||||
clearForm();
|
||||
@ -220,8 +303,7 @@ function ProductSell(o){
|
||||
$("#filter_text").val('');
|
||||
setFocus();
|
||||
app.defaults.sold_items = response.transfers;
|
||||
$('.sold-items-container').transferList( 'option', 'transfers' , app.defaults.sold_items );
|
||||
|
||||
refreshSoldItemsList();
|
||||
}else if ( response.code == 'invalid'){
|
||||
if ( response.errors ){
|
||||
$.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(){
|
||||
console.info( app.defaults.sold_items );
|
||||
$('.sold-items-container').transferList({
|
||||
'transfers' : app.defaults.sold_items
|
||||
});
|
||||
|
||||
@ -2,6 +2,8 @@ $.widget( "fitness.transferList", {
|
||||
options: {
|
||||
transfers: [],
|
||||
columns: [
|
||||
|
||||
{ 'label' : 'Idő' },
|
||||
{ 'label' : 'Termék' },
|
||||
{ 'label' : 'Ár' },
|
||||
{ 'label' : 'Db' },
|
||||
@ -83,6 +85,9 @@ $.widget( "fitness.transferList", {
|
||||
case 'row':
|
||||
transfer = params.transfer;
|
||||
s += '<tr>';
|
||||
s += '<td class="product-time">';
|
||||
s += transfer.time;
|
||||
s += '</td>';
|
||||
s += '<td class="product-name">';
|
||||
s += transfer.product_name;
|
||||
s += '</td>';
|
||||
@ -102,9 +107,11 @@ $.widget( "fitness.transferList", {
|
||||
for ( var i = 0; i < params.footers.length; i++ ){
|
||||
footer = params.footers[i];
|
||||
s += "<tr class='warning' >";
|
||||
s += "<th class='product-name'>";
|
||||
s += "<th class='product-time'>";
|
||||
s += footer.label;
|
||||
s += "</th>";
|
||||
s += "<th class='product-name'>";
|
||||
s += "</th>";
|
||||
s += "<td class=\"sale-price\">";
|
||||
s += "</td>";
|
||||
s += "<td class=\'product-count\' >";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user