add payment method

This commit is contained in:
2016-01-17 16:21:37 +01:00
parent abb69ce92d
commit d043759b1d
20 changed files with 751 additions and 168 deletions

View File

@@ -78,14 +78,16 @@ class ProductSaleForm extends Model
public $products;
public $payment_method;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_product','count','id_account'], 'required'],
[['id_product','id_currency','id_account', 'id_discount','count'], 'integer'],
[['id_product','count','id_account','payment_method'], 'required'],
[['id_product','id_currency','id_account', 'id_discount','count','payment_method'], 'integer'],
[['comment'], 'string' ,'max' => 255],
[['cart'], 'string' ,'max' => 20],
[['id_product' ], 'validateProduct'],
@@ -108,6 +110,7 @@ class ProductSaleForm extends Model
'id_account' => Yii::t("frontend/product", "Account"),
'id_discount' => Yii::t("frontend/product", "Discount"),
'comment' => Yii::t("frontend/product", "Comment"),
'payment_method' => Yii::t('common/transfer', 'Fizetési mód'),
];
}
@@ -199,6 +202,7 @@ class ProductSaleForm extends Model
}
$this->transfer = Transfer::createProductTransfer($this->sale,$this->account, $this->discount, $this->currency, $this->count, $this->product,$status,$customer);
$this->transfer->payment_method = $this->payment_method;
if ( isset($this->comment)){
$this->transfer->comment = $this->comment;
}

View File

@@ -32,6 +32,8 @@ class TicketCreate extends Ticket{
public $cart;
public $payment_method;
public function rules()
{
return [
@@ -48,6 +50,11 @@ class TicketCreate extends Ticket{
[[ 'id_account'], 'integer'],
[[ 'id_account'], 'validateAccount'],
/////////////////////
//payment_method
/////////////////////
[[ 'payment_method'], 'required'],
[[ 'payment_method'], 'integer'],
/////////////////////
//id_discount
/////////////////////
[[ 'id_discount'], 'integer'],
@@ -123,7 +130,7 @@ class TicketCreate extends Ticket{
$transfer->paid_by = \Yii::$app->user->id;
}
$transfer->status = $status;
$transfer->payment_method = $this->payment_method;
if ( isset($this->comment)){
$transfer->comment = $this->comment;

View File

@@ -2,6 +2,7 @@
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
use common\models\Transfer;
/* @var $this yii\web\View */
/* @var $model frontend\models\ProductSaleForm */
@@ -94,6 +95,11 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
<?php echo $form->field($model,'id_discount')->dropDownList($discountOptions) ?>
</div>
</div>
<div class="row">
<div class='col-md-12'>
<?php echo $form->field($model,'payment_method')->dropDownList(Transfer::paymentMethods()) ?>
</div>
</div>
<div class="row">
<div class='col-md-12'>
<?php echo $form->field( $model,'comment' )->textarea() ?>

View File

@@ -5,6 +5,7 @@ use yii\widgets\ActiveForm;
use frontend\components\HtmlHelper;
use kartik\widgets\DatePicker;
use common\models\Account;
use common\models\Transfer;
/* @var $this yii\web\View */
/* @var $model common\models\Ticket */
@@ -43,7 +44,9 @@ use common\models\Account;
<?= $form->field($model, 'id_account')->dropDownList($accountOptions) ?>
<?php //echo $form->field($model, 'id_discount')->dropDownList($discountOptions) ?>
<?php echo $form->field($model,'payment_method')->dropDownList(Transfer::paymentMethods()) ?>
<?php echo $form->field($model, 'id_discount')->dropDownList($discountOptions) ?>
<?= $form->field($model, 'start')->widget(DatePicker::classname(), [
'pluginOptions' => [

View File

@@ -40,6 +40,15 @@ if ( isset($receptionForm->card) ){
$options['customer_cart'] = $model->customerCart;
}
$discountItems = [];
foreach ($discounts as $d){
$item = [];
$item['id_discount'] = $d->id_discount;
$item['value'] = $d->value;
$discountItems[] = $item;
}
$options['discounts'] = $discountItems;
$this->registerJs ( 'new TicketSell( '. json_encode($options).');' );
?>
<div class="ticket-create">

View File

@@ -31,6 +31,9 @@ $formatter = Yii::$app->formatter;
<dt><?php echo $model->getAttributeLabel( 'status') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'statusName') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'payment_method') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'paymentMethodName') ?></dd>
</dl>
</div>
<div class='col-md-4'>

View File

@@ -541,7 +541,7 @@ function ProductSell(o){
function normalizePrice( price ){
var result;
// result = hufRound(price);
return result;
return price;
}
function hufRound(x)

View File

@@ -21,6 +21,7 @@ function TicketSell(o){
},
],
selector_type: '#ticketcreate-id_ticket_type',
selector_discount: '#ticketcreate-id_discount',
selector_start: '#ticketcreate-start',
selector_end: '#ticketcreate-end',
selector_account: '#ticketcreate-id_account',
@@ -47,6 +48,8 @@ function TicketSell(o){
url_pay_user_cart: '',
url_delete_transaction: '',
url_pay_transaction: '',
discounts : [],
discount: null,
};
@@ -55,6 +58,7 @@ function TicketSell(o){
function init(){
$.extend(app.defaults, o );
addBehaviourTypeChangedListener();
addBehaviourDiscountChangedListener();
useDefaults();
createCarts();
addPayoutButtons();
@@ -187,6 +191,9 @@ function TicketSell(o){
function addBehaviourTypeChangedListener(){
$(app.defaults.selector_type).change(change);
}
function addBehaviourDiscountChangedListener(){
$(app.defaults.selector_discount).change(typeChanged);
}
function change(event){
if ( '#'+event.target.id == app.defaults.selector_type ){
@@ -204,6 +211,7 @@ function TicketSell(o){
validateStartDate();
validateEndDate();
validateMaxUsageCount();
validateDiscount();
validatePriceBrutto();
validateAccount();
}
@@ -221,6 +229,22 @@ function TicketSell(o){
}
}
function validateDiscount(){
var discount;
discount = +$(app.defaults.selector_discount).val();
app.defaults.discount = null;
console.info( app.defaults.discounts );
for ( var i = 0; i < app.defaults.discounts.length; i++ ){
if ( app.defaults.discounts[i].id_discount == discount){
app.defaults.discount = app.defaults.discounts[i];
break;
}
}
console.info( 'discount found:');
console.info( app.defaults.discount );
}
function validateStartDate(){
app.defaults.start_date = moment( $( app.defaults.selector_start ).val(), app.defaults.date_format_moment) ;
@@ -258,6 +282,11 @@ function TicketSell(o){
function validatePriceBrutto(){
app.defaults.price = app.defaults.ticket_type.price_brutto;
if ( app.defaults.discount != null ){
var d = app.defaults.price * app.defaults.discount['value'] /100;
d = Math.floor( d );
app.defaults.price = app.defaults.price - d;
}
}
function validateAccount(){
app.defaults.id_account = $('#ticketcreate-id_account').val();