sell product changes
This commit is contained in:
parent
e9f9567618
commit
36c8d37914
@ -56,7 +56,7 @@ $items = $adminMenu->run();
|
|||||||
|
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p class="pull-left">© My Company <?= date('Y') ?></p>
|
<p class="pull-left">© Botond <?= date('Y') ?></p>
|
||||||
|
|
||||||
<p class="pull-right"><?= Yii::powered() ?></p>
|
<p class="pull-right"><?= Yii::powered() ?></p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -51,4 +51,15 @@ class Currency extends \common\models\BaseFitnessActiveRecord
|
|||||||
'updated_at' => Yii::t('common/currency', 'Updated At'),
|
'updated_at' => Yii::t('common/currency', 'Updated At'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param integer $money
|
||||||
|
* @param common\models\Currency $currency
|
||||||
|
* */
|
||||||
|
public static function applyCurrency( $money,$currency ) {
|
||||||
|
$result = $money / $currency;
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,4 +103,19 @@ class Discount extends \yii\db\ActiveRecord
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function read(){
|
||||||
|
return Discount::find()->andWhere([ 'status' => self::STATUS_ACTIVE ])->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param integer $money
|
||||||
|
* @param common\models\Discount $discount
|
||||||
|
* */
|
||||||
|
public static function applyDiscount($money,$discount){
|
||||||
|
$result = $money;
|
||||||
|
$valueOfDiscount = $money * $discount->value * 100;
|
||||||
|
$result = $money - $valueOfDiscount;
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -154,11 +154,13 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
|||||||
|
|
||||||
return ArrayHelper::toArray($product, [
|
return ArrayHelper::toArray($product, [
|
||||||
'common\models\Product' => [
|
'common\models\Product' => [
|
||||||
|
'id_product',
|
||||||
'name',
|
'name',
|
||||||
'product_number',
|
'product_number',
|
||||||
'barcode',
|
'barcode',
|
||||||
'sale_price',
|
'sale_price',
|
||||||
'stock',
|
'stock',
|
||||||
|
'id_account',
|
||||||
'category' => function ($product) {
|
'category' => function ($product) {
|
||||||
return $product->productCategoryName;
|
return $product->productCategoryName;
|
||||||
},
|
},
|
||||||
@ -166,4 +168,8 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function sellProduct($product,$count){
|
||||||
|
$product->stock = $product->stock - $count;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace common\models;
|
namespace common\models;
|
||||||
|
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\base\Object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the model class for table "transfer".
|
* This is the model class for table "transfer".
|
||||||
@ -10,6 +11,7 @@ use Yii;
|
|||||||
* @property integer $id_transfer
|
* @property integer $id_transfer
|
||||||
* @property integer $id_discount
|
* @property integer $id_discount
|
||||||
* @property integer $id_currency
|
* @property integer $id_currency
|
||||||
|
* @property integer $id_account
|
||||||
* @property integer $id_object
|
* @property integer $id_object
|
||||||
* @property integer $status
|
* @property integer $status
|
||||||
* @property integer $type
|
* @property integer $type
|
||||||
@ -29,6 +31,9 @@ class Transfer extends \yii\db\ActiveRecord
|
|||||||
const TYPE_PRODUCT = 10;
|
const TYPE_PRODUCT = 10;
|
||||||
const TYPE_TICKET = 20;
|
const TYPE_TICKET = 20;
|
||||||
|
|
||||||
|
const STATUS_NOT_PAID = 10;
|
||||||
|
const STATUS_PAID = 20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
@ -72,4 +77,70 @@ class Transfer extends \yii\db\ActiveRecord
|
|||||||
'updated_at' => Yii::t('common/transfer', 'Updated At'),
|
'updated_at' => Yii::t('common/transfer', 'Updated At'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getProduct(){
|
||||||
|
return $this->hasOne( Product::className(), ["id_product" =>"id_object" ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAccount(){
|
||||||
|
return $this->hasOne( Account::className(), ["id_account" =>"id_account" ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrency(){
|
||||||
|
return $this->hasOne( Currency::className(), ["id_currency" =>"id_currency" ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDiscount(){
|
||||||
|
return $this->hasOne( Discount::className(), ["id_discount" =>"id_discount" ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function toProductSoldString(){
|
||||||
|
$s = "";
|
||||||
|
|
||||||
|
$s .= $this->count;
|
||||||
|
$s .= " " . Yii::t('frontend/transfer', 'pieces') . " ";
|
||||||
|
$s .= $this->product->name;
|
||||||
|
$s .= " - ";
|
||||||
|
$s .= $this->account->name;
|
||||||
|
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $account common\models\Account
|
||||||
|
* @param $discount common\models\Discount
|
||||||
|
* @param $currency common\models\Currency
|
||||||
|
* @param $product common\models\Product
|
||||||
|
* */
|
||||||
|
public static function createProductTransfer($account, $discount, $currency, $count,$product ){
|
||||||
|
$transfer = new Transfer();
|
||||||
|
|
||||||
|
$transfer->type = Transfer::TYPE_PRODUCT;
|
||||||
|
|
||||||
|
$transfer->id_object = $product->id_product;
|
||||||
|
|
||||||
|
$transfer->item_price = $product->sale_price;
|
||||||
|
$totalPrice = $transfer->item_price;
|
||||||
|
|
||||||
|
$transfer->count = $count;
|
||||||
|
$totalPrice = $totalPrice * $count;
|
||||||
|
|
||||||
|
if ( isset( $discount ) ){
|
||||||
|
$transfer->id_discount = $discount->id_discount;
|
||||||
|
$totalPrice = Discount::applyDiscount( $totalPrice, $discount);
|
||||||
|
}
|
||||||
|
|
||||||
|
$transfer->money = $totalPrice;
|
||||||
|
|
||||||
|
if ( isset( $currency ) ){
|
||||||
|
$transfer->rate = $currency->rate;
|
||||||
|
$transfer->money_currency = Currency::applyCurrency($totalPrice, $currency);
|
||||||
|
}
|
||||||
|
|
||||||
|
$transfer->id_account = $account->id_account;
|
||||||
|
|
||||||
|
return $transfer;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,8 @@
|
|||||||
"yiisoft/yii2-bootstrap": "*",
|
"yiisoft/yii2-bootstrap": "*",
|
||||||
"yiisoft/yii2-swiftmailer": "*",
|
"yiisoft/yii2-swiftmailer": "*",
|
||||||
"kartik-v/yii2-widgets": "^3.4",
|
"kartik-v/yii2-widgets": "^3.4",
|
||||||
"kartik-v/yii2-widget-typeahead": "*"
|
"kartik-v/yii2-widget-typeahead": "*",
|
||||||
|
"bower-asset/remarkable-bootstrap-notify": "^3.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"yiisoft/yii2-codeception": "*",
|
"yiisoft/yii2-codeception": "*",
|
||||||
|
|||||||
41
composer.lock
generated
41
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "f2a471b84002daca5d3a31691f578c78",
|
"hash": "a1314409d3150e430e6ff7e350de0e3b",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "bower-asset/bootstrap",
|
"name": "bower-asset/bootstrap",
|
||||||
@ -179,6 +179,45 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "bower-asset/remarkable-bootstrap-notify",
|
||||||
|
"version": "3.1.3",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/mouse0270/bootstrap-notify.git",
|
||||||
|
"reference": "c6a3e3acafda0815cce3703103499b6262500cd7"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/mouse0270/bootstrap-notify/zipball/c6a3e3acafda0815cce3703103499b6262500cd7",
|
||||||
|
"reference": "c6a3e3acafda0815cce3703103499b6262500cd7",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"bower-asset/bootstrap": ">=2.0.0",
|
||||||
|
"bower-asset/jquery": ">=1.10.2"
|
||||||
|
},
|
||||||
|
"type": "bower-asset-library",
|
||||||
|
"extra": {
|
||||||
|
"bower-asset-main": "bootstrap-notify.js",
|
||||||
|
"bower-asset-ignore": []
|
||||||
|
},
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "This is a simple plugin that turns standard Bootstrap alerts into \"Growl-like\" notifications.",
|
||||||
|
"keywords": [
|
||||||
|
"bootstrap",
|
||||||
|
"growl",
|
||||||
|
"jquery",
|
||||||
|
"message",
|
||||||
|
"notice",
|
||||||
|
"notification",
|
||||||
|
"notifications",
|
||||||
|
"notify",
|
||||||
|
"remarkable"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "bower-asset/yii2-pjax",
|
"name": "bower-asset/yii2-pjax",
|
||||||
"version": "v2.0.4",
|
"version": "v2.0.4",
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Schema;
|
||||||
|
use yii\db\Migration;
|
||||||
|
use common\models\Transfer;
|
||||||
|
|
||||||
|
class m151002_163816_add__id_account__to__table__transfer extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$this->addColumn("transfer", "id_account", "integer(11)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
echo "m151002_163816_add__id_account__to__table__transfer cannot be reverted.\n";
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Use safeUp/safeDown to run migration code within a transaction
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function safeDown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
@ -21,9 +21,11 @@ class AppAsset extends AssetBundle
|
|||||||
'css/site.css',
|
'css/site.css',
|
||||||
];
|
];
|
||||||
public $js = [
|
public $js = [
|
||||||
|
|
||||||
];
|
];
|
||||||
public $depends = [
|
public $depends = [
|
||||||
'yii\web\YiiAsset',
|
'yii\web\YiiAsset',
|
||||||
'yii\bootstrap\BootstrapAsset',
|
'yii\bootstrap\BootstrapAsset',
|
||||||
|
'frontend\assets\GrowlAsset'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
16
frontend/assets/GrowlAsset.php
Normal file
16
frontend/assets/GrowlAsset.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
namespace frontend\assets;
|
||||||
|
|
||||||
|
use yii\web\AssetBundle;
|
||||||
|
|
||||||
|
class GrowlAsset extends AssetBundle
|
||||||
|
{
|
||||||
|
public $sourcePath = '@bower';
|
||||||
|
|
||||||
|
public $js = [
|
||||||
|
'remarkable-bootstrap-notify/bootstrap-notify.min.js'
|
||||||
|
];
|
||||||
|
|
||||||
|
public $depends = [
|
||||||
|
];
|
||||||
|
}
|
||||||
@ -9,8 +9,14 @@ use yii\web\Controller;
|
|||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
use frontend\models\ProductSaleForm;
|
use frontend\models\ProductSaleForm;
|
||||||
|
use frontend\models\ProductLookupForm;
|
||||||
use common\models\Card;
|
use common\models\Card;
|
||||||
use common\models\Customer;
|
use common\models\Customer;
|
||||||
|
use yii\base\DynamicModel;
|
||||||
|
use yii\base\Object;
|
||||||
|
use common\models\Currency;
|
||||||
|
use common\models\Account;
|
||||||
|
use common\models\Discount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProductController implements the CRUD actions for Product model.
|
* ProductController implements the CRUD actions for Product model.
|
||||||
@ -40,11 +46,50 @@ class ProductController extends Controller
|
|||||||
|
|
||||||
$model = new ProductSaleForm();
|
$model = new ProductSaleForm();
|
||||||
|
|
||||||
return $this->render("sale",[
|
$lookupModel = new ProductLookupForm();
|
||||||
'customer' => $this->customer,
|
|
||||||
'card' => $this->card
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
$currencies = Currency::find()->all();
|
||||||
|
|
||||||
|
$accounts = Account::readAccounts();
|
||||||
|
|
||||||
|
$discounts = Discount::read();
|
||||||
|
|
||||||
|
|
||||||
|
if (Yii::$app->request->isAjax) {
|
||||||
|
|
||||||
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
|
||||||
|
|
||||||
|
$model->currencies = $currencies;
|
||||||
|
$model->accounts = $accounts;
|
||||||
|
$model->discounts = $discounts;
|
||||||
|
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
$result['code'] = 'unknown';
|
||||||
|
if ($model->load(Yii::$app->request->post()) ) {
|
||||||
|
if ( $model->save()){
|
||||||
|
|
||||||
|
|
||||||
|
$result['code'] = 'success';
|
||||||
|
$result['message'] = Yii::t('common/product',"Sold: {product}" ,[ 'product' => $model->transfer->toProductSoldString() ]);
|
||||||
|
}else{
|
||||||
|
$result['code'] = 'invalid';
|
||||||
|
$result['errors'] = $model->getErrors();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
}else{
|
||||||
|
return $this->render("sale",[
|
||||||
|
'customer' => $this->customer,
|
||||||
|
'card' => $this->card,
|
||||||
|
'model' => $model,
|
||||||
|
'lookupModel' =>$lookupModel,
|
||||||
|
'currencies' => $currencies,
|
||||||
|
'accounts' => $accounts,
|
||||||
|
'discounts' => $discounts,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
40
frontend/models/ProductLookupForm.php
Normal file
40
frontend/models/ProductLookupForm.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace frontend\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Model;
|
||||||
|
use common\models\Card;
|
||||||
|
use common\models\Customer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ContactForm is the model behind the contact form.
|
||||||
|
*/
|
||||||
|
class ProductLookupForm extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
public $filter_text;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function attributeLabels()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'verifyCode' => 'Verification Code',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -6,6 +6,12 @@ use Yii;
|
|||||||
use yii\base\Model;
|
use yii\base\Model;
|
||||||
use common\models\Card;
|
use common\models\Card;
|
||||||
use common\models\Customer;
|
use common\models\Customer;
|
||||||
|
use common\models\Product;
|
||||||
|
use common\models\Transfer;
|
||||||
|
use yii\base\Object;
|
||||||
|
use common\models\Account;
|
||||||
|
use common\models\Discount;
|
||||||
|
use common\models\Currency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ContactForm is the model behind the contact form.
|
* ContactForm is the model behind the contact form.
|
||||||
@ -13,25 +19,86 @@ use common\models\Customer;
|
|||||||
class ProductSaleForm extends Model
|
class ProductSaleForm extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
public $productNumber;
|
public $id_product;
|
||||||
public $productBarcode;
|
|
||||||
public $count;
|
public $count;
|
||||||
public $currency;
|
public $id_currency;
|
||||||
public $account;
|
public $id_account;
|
||||||
|
public $id_discount;
|
||||||
public $comment;
|
public $comment;
|
||||||
|
public $barcode;
|
||||||
|
public $product_number;
|
||||||
|
public $sale_price;
|
||||||
|
public $product_name;
|
||||||
|
|
||||||
|
|
||||||
|
public $accounts;
|
||||||
|
public $currencies;
|
||||||
|
public $discounts;
|
||||||
|
|
||||||
|
public $product;
|
||||||
|
public $account;
|
||||||
|
public $currency;
|
||||||
|
public $discount;
|
||||||
|
|
||||||
|
public $transfer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['number'], 'required'],
|
[['id_product','count','id_account'], 'required'],
|
||||||
|
[['id_product','id_currency','id_account', 'id_discount','count'], 'integer'],
|
||||||
|
[['comment'], 'string' ,'max' => 255],
|
||||||
|
[['id_product' ], 'validateProduct'],
|
||||||
|
[['count' ], 'validateCount'],
|
||||||
|
[['id_currency' ], 'validateCurrency'],
|
||||||
|
[['id_account' ], 'validateAccount'],
|
||||||
|
[['id_discount' ], 'validateDiscount'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function validateProduct($attribute,$params){
|
||||||
|
$this->product = Product::findOne($this->id_product);
|
||||||
|
|
||||||
|
if ( !isset( $this->product ) ){
|
||||||
|
$this->addError($attribute, Yii::t('frontend/product', 'Product not found!'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateCount($attribute,$params){
|
||||||
|
if ( $this->product != null ){
|
||||||
|
if ( $this->product->stock < $this->count ){
|
||||||
|
$this->addError($attribute, Yii::t('frontend/product', 'Stock {stock} lower then {count}!', [ 'count' => $this->count, 'stock' => $this->product->stock ] ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function validateCurrency($attribute,$params){
|
||||||
|
if ( isset($this->id_currency ) ){
|
||||||
|
$this->currency = Currency::findOne($this->id_currency);
|
||||||
|
if ( !isset( $this->currency ) ){
|
||||||
|
$this->addError($attribute,Yii::t('frontend/product', 'Currency not found') );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateAccount($attribute,$params){
|
||||||
|
$this->account = Account::findOne($this->id_account);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateDiscount($attribute,$params){
|
||||||
|
if ( isset( $this->id_discount ) ){
|
||||||
|
$this->discount = Discount::findOne($this->id_discount);
|
||||||
|
if ( !isset( $this->discount ) ){
|
||||||
|
$this->addError($attribute,Yii::t('frontend/product', 'Discount not found') );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
@ -43,4 +110,31 @@ class ProductSaleForm extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function save(){
|
||||||
|
if ( $this->validate() ){
|
||||||
|
$this->saveTransfer();
|
||||||
|
$this->saveProduct();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function saveTransfer(){
|
||||||
|
|
||||||
|
$this->transfer = Transfer::createProductTransfer($this->account, $this->discount, $this->currency, $this->count, $this->product);
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
$this->transfer->status = Transfer::STATUS_PAID;
|
||||||
|
if ( isset($this->comment)){
|
||||||
|
$this->transfer->comment = $this->comment;
|
||||||
|
}
|
||||||
|
$this->transfer->id_user = Yii::$app->user->id;
|
||||||
|
$this->transfer->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function saveProduct(){
|
||||||
|
Product::sellProduct($this->product, $this->count);
|
||||||
|
$this->product->save();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,85 +1,106 @@
|
|||||||
<?php
|
<?php
|
||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
|
use yii\bootstrap\ActiveForm;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model frontend\models\ProductSaleForm */
|
||||||
|
/* @var $form yii\bootstrap\ActiveForm */
|
||||||
|
/* @var $currencies common\models\Currency[] */
|
||||||
|
|
||||||
|
|
||||||
|
function mkOptions($options){
|
||||||
|
// $o = $options;
|
||||||
|
|
||||||
|
$all = ['' => '-' ];
|
||||||
|
|
||||||
|
$o = $all + $options;
|
||||||
|
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currencyOptions = mkOptions( ArrayHelper::map($currencies, 'id_currency', 'name') );
|
||||||
|
$accountOptions = mkOptions( ArrayHelper::map($accounts, 'id_account', 'name') );
|
||||||
|
$discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name') );
|
||||||
?>
|
?>
|
||||||
|
<?php ?>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class='col-md-4'>
|
<div class="col-md-12">
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Product name'))?>
|
<?php echo $this->render('_view')?>
|
||||||
</div>
|
|
||||||
<div class='col-md-6'>
|
|
||||||
<?php echo Html::tag('span','',[ 'class' => 'product product-name']); ?>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class='col-md-4'>
|
<?php $form = ActiveForm::begin([
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Product price'))?>
|
'id' => 'filter_text_form',
|
||||||
</div>
|
'class' =>'form-inline',
|
||||||
<div class='col-md-6'>
|
'layout' => 'horizontal',
|
||||||
<?php echo Html::tag('span','',[ 'class' => 'product product-price']); ?>
|
'fieldConfig' => [
|
||||||
|
'horizontalCssClasses' => [
|
||||||
|
'label' => 'col-sm-5',
|
||||||
|
'offset' => 'col-sm-offset-6',
|
||||||
|
'wrapper' => 'col-sm-7',
|
||||||
|
'error' => '',
|
||||||
|
'hint' => '',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
] )?>
|
||||||
|
<div class='col-md-12'>
|
||||||
|
<?php echo $form->field($lookupModel,'filter_text')->textInput(['id'=>'filter_text']); ?>
|
||||||
</div>
|
</div>
|
||||||
|
<?php ActiveForm::end()?>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
|
||||||
<div class='col-md-4'>
|
<?php $form = ActiveForm::begin(
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Product number'))?>
|
[
|
||||||
|
'id' => 'product_form',
|
||||||
|
'class' =>'form-inline',
|
||||||
|
'layout' => 'horizontal',
|
||||||
|
'fieldConfig' => [
|
||||||
|
'horizontalCssClasses' => [
|
||||||
|
'label' => 'col-sm-5',
|
||||||
|
'offset' => 'col-sm-offset-6',
|
||||||
|
'wrapper' => 'col-sm-7',
|
||||||
|
'error' => '',
|
||||||
|
'hint' => '',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
); ?>
|
||||||
|
<?php echo Html::activeHiddenInput($model, 'id_product') ?>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class='col-md-12'>
|
||||||
|
<?php echo $form->field($model, 'count')->input("number") ?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='col-md-6'>
|
<div class="row">
|
||||||
<?php echo Html::tag('span','',[ 'class' => 'product product-number']); ?>
|
<div class='col-md-12'>
|
||||||
|
<?php echo $form->field($model,'id_currency')->dropDownList($currencyOptions) ?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class='col-md-12'>
|
||||||
<div class='col-md-4'>
|
<?php echo $form->field($model,'id_account')->dropDownList($accountOptions) ?>
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Barcode'))?>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='col-md-6'>
|
<div class="row">
|
||||||
<?php echo Html::tag('span','',[ 'class' => 'product barcode']); ?>
|
<div class='col-md-12'>
|
||||||
|
<?php echo $form->field($model,'id_discount')->dropDownList($discountOptions) ?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class='col-md-12'>
|
||||||
<div class='col-md-4'>
|
<?php echo $form->field( $model,'comment' )->textarea() ?>
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Count'))?>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='col-md-6'>
|
<div class="row">
|
||||||
<?php echo Html::textInput('count') ?>
|
<div class='col-md-5'>
|
||||||
|
<?php echo Html::a(Yii::t("frontend/product","Sell product"),null,['class' => 'btn btn-success', 'id' => 'btn_sell'] );?>
|
||||||
|
</div>
|
||||||
|
<div class='col-md-7'>
|
||||||
|
<?php echo Html::a(Yii::t("frontend/product","Sell product and add to total"),null,['class' => 'btn btn-success', 'id' => 'btn_sell_append'] );?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<?php ActiveForm::end(); ?>
|
||||||
<div class="row">
|
|
||||||
<div class='col-md-4'>
|
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Currency'))?>
|
|
||||||
</div>
|
|
||||||
<div class='col-md-6'>
|
|
||||||
<?php echo Html::dropDownList('currency',null,[],[]); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class='col-md-4'>
|
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Account'))?>
|
|
||||||
</div>
|
|
||||||
<div class='col-md-6'>
|
|
||||||
<?php echo Html::dropDownList('account',null,[],[]); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class='col-md-4'>
|
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Discount'))?>
|
|
||||||
</div>
|
|
||||||
<div class='col-md-6'>
|
|
||||||
<?php echo Html::dropDownList('discount',null,[],[]); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class='col-md-4'>
|
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Comment'))?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class='col-md-10'>
|
|
||||||
<?php echo Html::textarea('comment', ''); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class='col-md-3'>
|
|
||||||
<?php echo Html::a(Yii::t("frontend/product","Sell product"),null,['class' => 'btn btn-success'] );?>
|
|
||||||
</div>
|
|
||||||
<div class='col-md-7'>
|
|
||||||
<?php echo Html::a(Yii::t("frontend/product","Sell product and add to total"),null,['class' => 'btn btn-success'] );?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@ -1,19 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
use yii\bootstrap\Html;
|
use yii\bootstrap\Html;
|
||||||
?>
|
?>
|
||||||
<div class="row">
|
|
||||||
<div class='col-md-10'>
|
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Bill'))?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class='col-md-4'>
|
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Debit'))?>
|
|
||||||
</div>
|
|
||||||
<div class='col-md-6'>
|
|
||||||
<?php echo Html::tag("span",'0,00',['sale', 'sale-debit'])?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class='col-md-12'>
|
<div class='col-md-12'>
|
||||||
<table class="table table-bordered table-striped">
|
<table class="table table-bordered table-striped">
|
||||||
@ -37,27 +27,6 @@ use yii\bootstrap\Html;
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
56
frontend/views/product/_view.php
Normal file
56
frontend/views/product/_view.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
?>
|
||||||
|
<table class="table table-bordered table-striped">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<?php echo Yii::t('frontend/product','Name')?>
|
||||||
|
</th>
|
||||||
|
<td colspan="3">
|
||||||
|
<span class="product-name"></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<?php echo Yii::t('frontend/product','Barcode')?>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<span class="product-barcode">123456789</span>
|
||||||
|
</td>
|
||||||
|
<th>
|
||||||
|
<?php echo Yii::t('frontend/product','Product number')?>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<span class="product-number">123456789</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<?php echo Yii::t('frontend/product','Stock'). ' (Db)'?>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<span class="product-stock"></span>
|
||||||
|
</td>
|
||||||
|
<th>
|
||||||
|
<?php echo Yii::t('frontend/product','Count'). ' (Db)'?>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<span class="product-count">1</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<?php echo Yii::t('frontend/product','Sale Price')?>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<span class="product-sale-price"></span>
|
||||||
|
</td>
|
||||||
|
<th>
|
||||||
|
<?php echo Yii::t('frontend/product','Price')?>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<span class="product-price">100 000</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
@ -6,6 +6,12 @@ use yii\helpers\Html;
|
|||||||
use common\models\Product;
|
use common\models\Product;
|
||||||
use frontend\assets\ProductSellAsset;
|
use frontend\assets\ProductSellAsset;
|
||||||
use yii\helpers\Url;
|
use yii\helpers\Url;
|
||||||
|
use yii\bootstrap\ActiveForm;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $form yii\bootstrap\ActiveForm */
|
||||||
|
/* @var $currencies common\models\Currency[] */
|
||||||
|
|
||||||
ProductSellAsset::register($this);
|
ProductSellAsset::register($this);
|
||||||
|
|
||||||
@ -20,9 +26,19 @@ $this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
/*
|
||||||
.product-form input, .product-form select, .product-form textarea{
|
.product-form input, .product-form select, .product-form textarea{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
.product-count{
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group{
|
||||||
|
margin-bottom: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class='row'>
|
<div class='row'>
|
||||||
@ -32,23 +48,11 @@ $this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
|
|||||||
<div class='col-md-4'>
|
<div class='col-md-4'>
|
||||||
<?php echo ReceptionCardNumberWidget::widget( [ 'customer' => $customer, 'card' =>$card, 'route' => ['product/sale'] ] )?>
|
<?php echo ReceptionCardNumberWidget::widget( [ 'customer' => $customer, 'card' =>$card, 'route' => ['product/sale'] ] )?>
|
||||||
</div>
|
</div>
|
||||||
<div class='col-md-4'>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<h1><?php echo Yii::t('frontend/product','Sell product')?></h1>
|
<h1><?php echo Yii::t('frontend/product','Sell product')?></h1>
|
||||||
<div class='row'>
|
|
||||||
<div class='col-md-4'>
|
|
||||||
<?php echo Html::label(Yii::t('frontend/product', 'Product'))?>
|
|
||||||
<?php echo Html::textInput('filter_text','', ['id'=>'filter_text'])?>
|
|
||||||
</div>
|
|
||||||
<div class='col-md-4'>
|
|
||||||
</div>
|
|
||||||
<div class='col-md-4'>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class='row '>
|
<div class='row '>
|
||||||
<div class='col-md-6 product-form'>
|
<div class='col-md-6 product-form'>
|
||||||
<?php echo $this->render('_sale_form' ) ?>
|
<?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'>
|
||||||
<?php echo $this->render('_sold_items' ) ?>
|
<?php echo $this->render('_sold_items' ) ?>
|
||||||
|
|||||||
@ -1,25 +1,88 @@
|
|||||||
function ProductSell(o){
|
function ProductSell(o){
|
||||||
|
|
||||||
|
var app = this;
|
||||||
|
var product = null;
|
||||||
|
|
||||||
this.defaults = {
|
this.defaults = {
|
||||||
selector_filter_text: '#filter_text',
|
selector_filter_text: '#filter_text',
|
||||||
lookup_product_url: ''
|
lookup_product_url: '' ,
|
||||||
|
selector_form: '#product_form',
|
||||||
|
form_invalid: 'Az ürlap hibákat tartalmaz'
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
function init(){
|
function init(){
|
||||||
this.defaults = $.extend(this.defaults, o );
|
$.extend(app.defaults, o );
|
||||||
addBehaviorEnterPressedListener();
|
addBehaviorEnterPressedListener();
|
||||||
|
addBehaviourBtnSell();
|
||||||
|
addBehaviourBtnSellAndAppendToBill();
|
||||||
|
addBehaviorAjaxSubmit();
|
||||||
|
setFocus();
|
||||||
|
addBehaviorCountEnterPressedListener();
|
||||||
|
addBehaviorCountChangedListener();
|
||||||
|
addBehaviorCurrencyEnterPressedListener();
|
||||||
|
addBehaviorAccountEnterPressedListener();
|
||||||
|
addBehaviorDiscountEnterPressedListener();
|
||||||
|
productChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setFocus(){
|
||||||
|
$("#filter_text").focus();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function addBehaviorEnterPressedListener(){
|
function addBehaviorEnterPressedListener(){
|
||||||
alert($( this.defaults.selector_filter_text ).length);
|
$( app.defaults.selector_filter_text ).keypress(function( event ) {
|
||||||
$( this.defaults.selector_filter_text ).keypress(function( event ) {
|
|
||||||
if ( event.which == 13 ) {
|
if ( event.which == 13 ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
lookupProduct();
|
lookupProduct();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBehaviorCountEnterPressedListener(){
|
||||||
|
$( '#productsaleform-count' ).keypress(function( event ) {
|
||||||
|
if ( event.which == 13 ) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
$('#productsaleform-id_currency').focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBehaviorCurrencyEnterPressedListener(){
|
||||||
|
$( '#productsaleform-id_currency' ).keypress(function( event ) {
|
||||||
|
if ( event.which == 13 ) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
$('#productsaleform-id_account').focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function addBehaviorAccountEnterPressedListener(){
|
||||||
|
$( '#productsaleform-id_account' ).keypress(function( event ) {
|
||||||
|
if ( event.which == 13 ) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
$('#productsaleform-id_discount').focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBehaviorDiscountEnterPressedListener(){
|
||||||
|
$( '#productsaleform-id_discount' ).keypress(function( event ) {
|
||||||
|
if ( event.which == 13 ) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
$('#productsaleform-comment').focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBehaviorCountChangedListener(){
|
||||||
|
$( '#productsaleform-count' ).change(function( event ) {
|
||||||
|
refreshCalculatedValues();
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -27,9 +90,9 @@ function ProductSell(o){
|
|||||||
function lookupProduct(){
|
function lookupProduct(){
|
||||||
var data, url;
|
var data, url;
|
||||||
|
|
||||||
url = this.defaults.lookup_product_url;
|
url = app.defaults.lookup_product_url;
|
||||||
data = {
|
data = {
|
||||||
'query' : $( this.defaults.selector_filter_text ).val()
|
'query' : $( app.defaults.selector_filter_text ).val()
|
||||||
};
|
};
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@ -41,27 +104,106 @@ function ProductSell(o){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onLookupProductReady( data ){
|
function onLookupProductReady( data ){
|
||||||
alert('ok');
|
app.product = data.product;
|
||||||
productChanged(data.product);
|
productChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function productChanged(product){
|
function productChanged( ){
|
||||||
clearForm();
|
clearForm();
|
||||||
if ( product == null){
|
if ( app.product != null){
|
||||||
applyProduct();
|
applyProduct( app.product);
|
||||||
|
refreshCalculatedValues();
|
||||||
|
$("#productsaleform-count").focus().select();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearForm(){
|
function clearForm(){
|
||||||
$('.product-name').html('-');
|
$('.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('');
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyProduct(product){
|
function applyProduct(product){
|
||||||
|
$('#productsaleform-id_product').val(product.id_product);
|
||||||
$('.product-name').html(product.name);
|
$('.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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshCalculatedValues(){
|
||||||
|
var count,price;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBehaviourBtnSell(){
|
||||||
|
$('#btn_sell').on('click',submitSell);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBehaviourBtnSellAndAppendToBill(){
|
||||||
|
$('#btn_sell_append').on('click',submitSell);
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitSell(){
|
||||||
|
$('#product_form').submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBehaviorAjaxSubmit(){
|
||||||
|
|
||||||
|
$('body').on('beforeSubmit', '#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' : '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();
|
||||||
|
refreshCalculatedValues();
|
||||||
|
$("#filter_text").val('');
|
||||||
|
setFocus();
|
||||||
|
}else if ( response.code == 'invalid'){
|
||||||
|
if ( response.errors ){
|
||||||
|
$.each(response.errors, function (key, value){
|
||||||
|
var message;
|
||||||
|
message = $.map(value, function(obj){ return obj }).join(' ');
|
||||||
|
$.notify(message, { 'type' : 'danger' });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user