add daily listing by paid_by, add customer cart details

This commit is contained in:
2016-01-27 09:01:02 +01:00
parent 9fb349ee64
commit 2291ca5ff4
28 changed files with 577 additions and 81 deletions

View File

@@ -0,0 +1,28 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class TransferCustomerCartAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'js/transfer.customercart.js',
];
public $depends = [
'frontend\assets\AppAsset',
];
}

View File

@@ -155,15 +155,15 @@ class ProductController extends Controller {
}
public function actionPayoutUserCart() {
if (Yii::$app->request->isAjax) {
$result = [ ];
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
// $result = [ ];
// \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$user = User::findOne ( Yii::$app->user->id );
UserSoldItem::payout ( $user );
// $user = User::findOne ( Yii::$app->user->id );
// UserSoldItem::payout ( $user );
$userTransfers = Transfer::modelsToArray ( Transfer::readUserSoldTransfers ( $user ) );
$result ['transfers'] = $userTransfers;
$result ['code'] = 'success';
// $userTransfers = Transfer::modelsToArray ( Transfer::readUserSoldTransfers ( $user ) );
// $result ['transfers'] = $userTransfers;
// $result ['code'] = 'success';
return $result;
} else {
@@ -175,7 +175,7 @@ class ProductController extends Controller {
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction ();
try {
UserSoldItem::payout ( $user, $model->transfers );
UserSoldItem::payout ( $user, $model->transfers , Account::readDefault() );
$transaction->commit ();
\Yii::$app->session->setFlash ( 'success', 'Recepicó kosár fizetve' );
} catch ( Exception $e ) {
@@ -231,7 +231,7 @@ class ProductController extends Controller {
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction ();
try {
ShoppingCart::payout ( $this->customer, $model->transfers );
ShoppingCart::payout ( $this->customer, $model->transfers , Account::readDefault());
$transaction->commit ();
\Yii::$app->session->setFlash ( 'success', 'Vendég kosár kifizetve' );
} catch ( Exception $e ) {

View File

@@ -20,6 +20,9 @@ use common\models\Product;
use common\models\TransferTicketSearch;
use common\models\TicketType;
use frontend\models\UserCartForm;
use common\models\Customer;
use frontend\models\CustomerCartForm;
use common\models\Card;
/**
* TransferController implements the CRUD actions for Transfer model.
@@ -191,10 +194,11 @@ class TransferController extends Controller
$transfer->status = Transfer::STATUS_PAID;
$transfer->paid_at = date('Y-m-d H:i:s' ) ;
$transfer->paid_by = \Yii::$app->user->id;
$transfer->id_account = Account::readDefault();
ShoppingCart::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
UserSoldItem::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
if ( $transfer->save() ){
\Yii::$app->session->setFlash( 'success','Tranzakció kifizetve' );
\Yii::$app->session->setFlash( 'success','Tranzakció kifizetve!' );
$transaction->commit();
}else{
throw new \Exception("Failed to save");
@@ -342,6 +346,12 @@ class TransferController extends Controller
public function actionUserCart(){
$defaultAccount = Account::readDefault();
if ( !isset($defaultAccount)){
return $this->redirect(['account/select']);
}
$model = new UserCartForm();
if ($model->load(Yii::$app->request->post()) && $model->payout()) {
return $this->redirect(['user-cart']);
@@ -349,4 +359,30 @@ class TransferController extends Controller
$model->run();
return $this->render("usercart",[ 'model' => $model]);
}
public function actionCustomerCart($id_card){
$defaultAccount = Account::readDefault();
if ( !isset($defaultAccount)){
return $this->redirect(['account/select']);
}
$customer = null;
$card = Card::findOne($id_card);
if ($card != null )
$customer = $card->customer;
if ( !isset($customer) ){
throw new NotFoundHttpException ( 'Az oldal nem található' );
}
$model = new CustomerCartForm();
$model->customer = $customer;
if ($model->load(Yii::$app->request->post()) && $model->payout()) {
return $this->redirect(['customer-cart','id_card' => $model->customer->card->id_card]);
}
$model->run();
return $this->render("customercart",[ 'model' => $model]);
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\Transfer;
use common\models\Account;
/**
* ContactForm is the model behind the contact form.
*/
class CustomerCartForm extends Model
{
public $items = [];
public $transfers;
public $payment_method;
public $money = 0;
public $selected = [];
public $customer;
/**
* @inheritdoc
*/
public function rules()
{
return [
['selected', 'each', 'rule' => ['integer']],
[['money' ,'payment_method'],'integer'],
[['payment_method'],'validatePaymentMethod'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
];
}
public function validatePaymentMethod( $attribute, $params ){
if ( !empty($this->payment_method)){
// echo $this->payment_method;
$arr = Transfer::paymentMethods();
if ( !array_key_exists($this->payment_method, $arr) ){
$this->addError($attribute, "Érvénytelen fizetési mód");
}
}
}
public function payout(){
$valid = $this->validate();
if ( !$valid ){
return false;
}
if ( isset($this->selected) && count($this->selected) > 0 ){
$items = $this->loadTransfers($this->selected);
if ( count($items) == count($this->selected) ){
foreach ($items as $item){
$this->changePaymentMethod($item);
$item->id_account = Account::readDefault();
$item->payout();
}
\Yii::$app->session->setFlash('success', 'Kifizetve');
return true;
}else{
\Yii::$app->session->setFlash('danger', 'Időközben változtak a kosrában található tételek');
return false;
}
}else{
\Yii::$app->session->setFlash('danger', 'Nem választott ki terméket');
return false;
}
}
public function changePaymentMethod($item){
if ( !empty($this->payment_method)){
$item->payment_method = $this->payment_method;
}
}
public function run(){
$this->readTransfers();
}
public function readTransfers( ) {
$this->transfers = $this->loadTransfers();
}
public function loadTransfers($id_tranfer_array = null){
$query = Transfer::find();
$query->innerJoin("shopping_cart", "shopping_cart.id_transfer = transfer.id_transfer");
// $query->andWhere(["transfer.id_user" => \Yii::$app->user->id]);
$query->andWhere(["shopping_cart.id_customer" => $this->customer->id_customer]);
if (isset($id_tranfer_array)){
$query->andWhere(["in", "transfer.id_transfer" , $id_tranfer_array ]);
}
return $query->all();
}
}

View File

@@ -77,7 +77,7 @@ class TransferSearch extends Transfer
// uncomment the following line if you do not want to return any records when validation fails
$query->where('0=1');
}
$query->andWhere(['id_user' => Yii::$app->user->id ] );
$query->andWhere( ['or',['id_user' => Yii::$app->user->id ] , ['paid_by' => Yii::$app->user->id],] );
$query->andFilterWhere([
'id_account' => $this->id_account,

View File

@@ -5,6 +5,8 @@ namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\Transfer;
use common\components\Helper;
use common\models\Account;
/**
* ContactForm is the model behind the contact form.
@@ -62,6 +64,7 @@ class UserCartForm extends Model
if ( count($items) == count($this->selected) ){
foreach ($items as $item){
$this->changePaymentMethod($item);
$item->id_account = Account::readDefault();
$item->payout();
}
\Yii::$app->session->setFlash('success', 'Kifizetve');
@@ -93,7 +96,9 @@ class UserCartForm extends Model
public function loadTransfers($id_tranfer_array = null){
$query = Transfer::find();
$query->innerJoin("user_sold_item", "user_sold_item.id_transfer = transfer.id_transfer");
$query->andWhere(["user_sold_item.id_user" => \Yii::$app->user->id]);
if ( Helper::isUserCartVisibilityUser()){
$query->andWhere(["user_sold_item.id_user" => \Yii::$app->user->id]);
}
if (isset($id_tranfer_array)){
$query->andWhere(["in", "transfer.id_transfer" , $id_tranfer_array ]);
}

View File

@@ -20,6 +20,7 @@ $items = [
[ 'Befizetések', ['ticket/index', 'number' => $card->number] ],
[ 'Kulcsok', ['key/index', 'id_card' => $card->id_card] ],
[ 'Szerződések', ['contract/index', 'id_card' => $card->id_card ]],
[ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]],
];

View File

@@ -41,4 +41,7 @@ use yii\widgets\ActiveForm;
<div class='col-md-3 '>
<?php echo Html::a(Yii::t('frontend/product', "Frissít"),null,[ 'class' => 'btn btn-primary btn-block' , 'onclick' => 'location.reload();']) ?>
</div>
<div class='col-md-3 '>
<?php echo Html::a("Kosár részletei",['transfer/customer-cart' ,'id_card' => $model->customer->card->id_card],[ 'class' => 'btn btn-primary btn-block' , 'onclick' => 'location.reload();']) ?>
</div>
</div>

View File

@@ -39,4 +39,7 @@ use kartik\widgets\ActiveForm;
<div class='col-md-3 '>
<?php echo Html::a(Yii::t('frontend/product', "Frissít"),null,[ 'class' => 'btn btn-primary btn-block' , 'onclick' => 'location.reload();']) ?>
</div>
<div class='col-md-3 '>
<?php echo Html::a("Kosár részletei",['transfer/customer-cart' ,'id_card' => $model->customer->card->id_card],[ 'class' => 'btn btn-primary btn-block' , 'onclick' => 'location.reload();']) ?>
</div>
</div>

View File

@@ -41,4 +41,7 @@ use kartik\widgets\ActiveForm;
<div class='col-md-3 '>
<?php echo Html::a(Yii::t('frontend/product', "Frissít"),null,[ 'class' => 'btn btn-primary btn-block' , 'onclick' => 'location.reload();']) ?>
</div>
<div class='col-md-3 '>
<?php echo Html::a(Yii::t('transfer/user-cart', "Kosár részletei"),['transfer/user-cart'],[ 'class' => 'btn btn-primary btn-block' ]) ?>
</div>
</div>

View File

@@ -66,7 +66,7 @@ $this->registerJs ( 'new TicketSell( '. json_encode($options).');' );
</div>
<div class='col-md-6'>
<?php if ( $receptionForm->isCardWithCustomer() ){ ?>
<?php echo $this->render('_customer_cart' ) ?>
<?php echo $this->render('_customer_cart' ,['model' => $receptionForm]) ?>
<?php }?>
<?php echo $this->render('_user_cart' ) ?>
</div>

View File

@@ -20,10 +20,13 @@ $formatter = Yii::$app->formatter;
<dt><?php echo $model->getAttributeLabel( 'id_transfer') ?></dt>
<dt><?php echo "Tranz. azonosító" ?></dt>
<dd><?php echo ( Html::getAttributeValue($model, 'id_transfer') ) ?></dd>
<dt><?php echo $model->getAttributeLabel( 'created_at') ?></dt>
<dt><?php echo $model->getAttributeLabel( 'payment_method') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'paymentMethodName') ?></dd>
<dt><?php echo "Kiadás ideje" ?></dt>
<dd><?php echo $formatter->asDatetime( Html::getAttributeValue($model, 'created_at') ) ?></dd>
<dt><?php echo $model->getAttributeLabel( 'paid_at') ?></dt>
@@ -31,9 +34,9 @@ $formatter = Yii::$app->formatter;
<dt><?php echo $model->getAttributeLabel( 'status') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'statusName') ?></dd>
<dt><?php echo "Kassza" ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'accountName') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'payment_method') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'paymentMethodName') ?></dd>
</dl>
</div>
<div class='col-md-4'>
@@ -44,8 +47,10 @@ $formatter = Yii::$app->formatter;
<dt>Megnevezés</dt>
<dd><?php echo Html::getAttributeValue($model, 'objectName') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'id_user') ?></dt>
<dt><?php echo "Kiadta" ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'userName') ?></dd>
<dt><?php echo "Fizette" ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'paidByName') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'id_customer') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'customerName') ?></dd>

View File

@@ -0,0 +1,114 @@
<?php
use yii\data\ArrayDataProvider;
use yii\widgets\ListView;
use yii\base\Widget;
use yii\grid\GridView;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\models\Transfer;
use yii\grid\CheckboxColumn;
use frontend\assets\TransferUserCartAsset;
use frontend\assets\TransferCustomerCartAsset;
use frontend\components\CustomerTabWidget;
?>
<?php
TransferCustomerCartAsset::register($this);
$options = [];
$this->registerJs ( 'new TransferCustomerCart( '. json_encode($options).');' );
$dp = new ArrayDataProvider(
[
'allModels' => $model->transfers,
'pagination' => false
]
);
$this->params['breadcrumbs'][] = "Vendég Kosár";
?>
<?php echo CustomerTabWidget::widget(['card' => $model->customer->card])?>
<div class="transfer-form">
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->field($model, 'payment_method')->dropDownList( ['' => 'Aktuális'] + Transfer::paymentMethods())->label("Fizetése mód") ?>
<div class="row">
<div class="col-md-4">
<span style="font-weight: bold;">Összesen:</span>
<span class="selected-money"><?php echo $model->money ?></span>
<span> Ft</span>
<?php echo $form->field($model, "money" , [ ])->hiddenInput()->label(false); ?>
</div>
</div>
<div style="margin-bottom: 6px;">
<?php
echo Html::a("Összes kiválasztása",null, ['class' => 'btn btn-primary select-all' ,'style' => 'margin-right: 6px;']);
echo Html::a("Egyiket sem",null, ['class' => 'btn btn-primary deselect-all']);
?>
</div>
<?php
$formModel = $model;
echo GridView::widget([
"dataProvider" => $dp,
'columns' =>[
[
'label' => '',
'value' => function ($model, $key, $index, $column) use (&$form, &$formModel){
return Html::checkbox(Html::getInputName($formModel, 'selected[]') , in_array($model->id_transfer, $formModel->selected) , [ 'data-money' => $model->money, 'class' => 'cart-item', 'value' => $model->id_transfer] );
},
'format' => 'raw'
],
[
'value' => 'created_at',
'label' => 'Kiadva',
'format' => 'datetime'
],
[
'value' => 'user.username',
'label' => 'Kiadta',
],
[
'value' => 'transferTypeName',
'label' => 'Típus'
],
[
'value' => 'objectName',
'label' => 'Megnevezés'
],
[
'value' => 'item_price',
'label' => 'Egység ár'
],
[
'value' => 'count',
'label' => 'Mennyiség'
],
[
'value' => 'money',
'label' => 'Összesen'
],
[
'value' => 'paymentMethodName',
'label' => 'Fizetési mód'
],
]
]);
?>
<div class="form-group">
<?= Html::submitButton( "Kiválasztott elemek fizetve", ['class' => 'btn btn-primary']) ?>
</div>
<p>
A kifizetés az alapértelmezett kasszához lesz elszámolva
</p>
<?php ActiveForm::end(); ?>
</div>

View File

@@ -72,7 +72,8 @@ td.name {
<th>F. mód</th>
<th>Fizetve</th>
<th>Kassza</th>
<th>Felhasználó</th>
<th>Kiadta</th>
<th>Fizette</th>
<th>Vásárló</th>
<th>Kategória</th>
<th>Termék</th>
@@ -90,6 +91,7 @@ td.name {
<td><?php echo $p['product_paid_at']?> </td>
<td><?php echo $p['account_name']?> </td>
<td><?php echo $p['user_name']?> </td>
<td><?php echo $p['paid_by_name']?> </td>
<td><?php echo $p['customer_name']?> </td>
<td><?php echo $p['product_category_name'] ?></td>
<td><?php echo $p['product_name'] ?></td>

View File

@@ -71,7 +71,8 @@ td.name {
<th>Kiadva</th>
<th>Fizetve</th>
<th>Kassza</th>
<th>Felhasználó</th>
<th>Kiadta</th>
<th>Fizette</th>
<th>Vendég</th>
<th>Bérlet típus</th>
<th>Státusz</th>
@@ -85,15 +86,16 @@ td.name {
<tr>
<td><?php echo $t['ticket_id_ticket']?> </td>
<td><?php echo $t['ticket_created_at']?> </td>
<td><?php echo $t['ticket_paid_at']?> </td>
<td><?php echo $t['account_name']?> </td>
<td><?php echo $t['user_name']?> </td>
<td><?php echo $t['customer_name']?> </td>
<td><?php echo $t['ticket_type_name'] ?></td>
<td><?php echo Ticket::toStatusName( $t['ticket_status'] ) ?></td>
<td class='money'><?php echo $t['ticket_item_price']?> Ft</td>
<td class='count'><?php echo $t['ticket_count']?> Db</td>
<td class='money'><?php echo $t['ticket_money']?> FT</td>
<td><?php echo $t['ticket_paid_at']?> </td>
<td><?php echo $t['account_name']?> </td>
<td><?php echo $t['user_name']?> </td>
<td><?php echo $t['paid_by_name']?> </td>
<td><?php echo $t['customer_name']?> </td>
<td><?php echo $t['ticket_type_name'] ?></td>
<td><?php echo Ticket::toStatusName( $t['ticket_status'] ) ?></td>
<td class='money'><?php echo $t['ticket_item_price']?> Ft</td>
<td class='count'><?php echo $t['ticket_count']?> Db</td>
<td class='money'><?php echo $t['ticket_money']?> FT</td>
</tr>
<?php } ?>

View File

@@ -24,7 +24,7 @@ $this->registerJs ( 'new TransferUserCart( '. json_encode($options).');' );
);
?>
<h1>Kosár</h1>
<h1>Recepció kosár</h1>
<div class="transfer-form">
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->field($model, 'payment_method')->dropDownList( ['' => 'Aktuális'] + Transfer::paymentMethods())->label("Fizetése mód") ?>
@@ -33,13 +33,18 @@ $this->registerJs ( 'new TransferUserCart( '. json_encode($options).');' );
<span>Összesen:</span>
<span class="selected-money"><?php echo $model->money ?></span>
<span> Ft</span>
<?php echo $form->field($model, "money" , [ ])->hiddenInput(); ?>
<?php echo $form->field($model, "money" , [ ])->hiddenInput()->label(false); ?>
</div>
</div>
<div style="margin-bottom: 6px;">
<?php
echo Html::a("Összes kiválasztása",null, ['class' => 'btn btn-primary select-all' ,'style' => 'margin-right: 6px;']);
echo Html::a("Egyiket sem",null, ['class' => 'btn btn-primary deselect-all']);
?>
</div>
<?php
$formModel = $model;
echo GridView::widget([
@@ -53,6 +58,19 @@ echo GridView::widget([
},
'format' => 'raw'
],
[
'value' => 'created_at',
'label' => 'Kiadva',
'format' => 'datetime'
],
[
'value' => 'user.username',
'label' => 'Kiadta',
],
[
'value' => 'accountName',
'label' => 'Kassza'
],
[
'value' => 'transferTypeName',
'label' => 'Típus'
@@ -85,6 +103,8 @@ echo GridView::widget([
<div class="form-group">
<?= Html::submitButton( "Kiválasztott elemek fizetve", ['class' => 'btn btn-primary']) ?>
</div>
<p>
A kifizetés az alapértelmezett kasszához lesz elszámolva
</p>
<?php ActiveForm::end(); ?>
</div>

View File

@@ -0,0 +1,63 @@
function TransferCustomerCart(o){
var defaults = {};
init();
function init(){
defaults = $.extend(defaults,o);
$('.select-on-check-all').click(recalculate);
$('.cart-item').click(recalculate);
$('.select-all').click(selectAll);
$('.deselect-all').click(deselectAll);
}
function selectAll(){
var table;
table = $('.grid-view').find('table');
table.find('input').prop('checked',true);
recalculate();
}
function deselectAll(){
var table;
table = $('.grid-view').find('table');
table.find('input').prop('checked',false);
recalculate();
}
function recalculate(){
var items = $('.cart-item');
var money = 0;
items.each(function(i,e){
if ( $(e).is(':checked')){
money += $(e).data('money');
}
});
$('#customercartform-money').val(money);
$('.selected-money').html(money);
selectRows();
}
function selectRows(){
var table;
var rows;
table = $('.grid-view').find('table');
rows = table.find('tbody').find('tr');
rows.removeClass('info');
rows.each(function(i,e){
var cb;
var selected;
var row;
row = $(e);
cb = row.find('td').eq(0).find('input');
selected = cb.is(':checked');
if ( selected){
row.addClass('info');
}
});
}
}

View File

@@ -8,6 +8,23 @@ function TransferUserCart(o){
defaults = $.extend(defaults,o);
$('.select-on-check-all').click(recalculate);
$('.cart-item').click(recalculate);
$('.select-all').click(selectAll);
$('.deselect-all').click(deselectAll);
}
function selectAll(){
var table;
table = $('.grid-view').find('table');
table.find('input').prop('checked',true);
recalculate();
}
function deselectAll(){
var table;
table = $('.grid-view').find('table');
table.find('input').prop('checked',false);
recalculate();
}
function recalculate(){
@@ -20,6 +37,28 @@ function TransferUserCart(o){
});
$('#usercartform-money').val(money);
$('.selected-money').html(money);
selectRows();
}
function selectRows(){
var table;
var rows;
table = $('.grid-view').find('table');
rows = table.find('tbody').find('tr');
rows.removeClass('info');
rows.each(function(i,e){
var cb;
var selected;
var row;
row = $(e);
cb = row.find('td').eq(0).find('input');
selected = cb.is(':checked');
if ( selected){
row.addClass('info');
}
});
}