From 29a8b440b2c0d09b2c901c4c318fdfa4b4b2d7a4 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Sun, 21 Feb 2016 21:41:25 +0100 Subject: [PATCH 1/3] Add ContractForm, Add contract pdf, Add Display all Transfer option --- backend/views/transfer/index.php | 8 +- changelog.txt | 4 + common/components/Azaz.php | 63 ++++ common/components/Helper.php | 3 + common/components/TransferPayout.php | 118 +++++++ common/config/params.php | 18 +- common/models/Contract.php | 19 ++ common/models/Customer.php | 12 + common/models/ShoppingCart.php | 3 + common/models/TicketType.php | 6 +- common/models/Transfer.php | 59 ++-- common/models/UserSoldItem.php | 4 + ...__add__column_mother_name__birth_place.php | 31 ++ frontend/controllers/ContractController.php | 93 ++++-- frontend/controllers/CustomerController.php | 19 +- frontend/controllers/KeyController.php | 3 + frontend/controllers/ProductController.php | 290 ++++++++--------- frontend/controllers/TransferController.php | 40 ++- frontend/models/ContactForm.php | 3 + frontend/models/ContractForm.php | 307 ++++++++++++++++++ frontend/models/CustomerCartForm.php | 42 ++- frontend/models/CustomerCreate.php | 4 +- frontend/models/CustomerUpdate.php | 4 +- frontend/models/KeyToggleForm.php | 3 +- frontend/models/UserCartForm.php | 56 +++- frontend/views/contract/_contract.php | 294 +++++++++++++++++ frontend/views/contract/_make_contract.php | 119 +++++++ frontend/views/contract/index.php | 4 + frontend/views/contract/view.php | 12 +- frontend/views/customer/_contract.php | 24 -- frontend/views/customer/_form_create.php | 16 + frontend/views/customer/_form_update.php | 20 +- frontend/views/layouts/main.php | 20 +- 33 files changed, 1417 insertions(+), 304 deletions(-) create mode 100644 common/components/Azaz.php create mode 100644 common/components/TransferPayout.php create mode 100644 console/migrations/m160221_132448_alter__table__customer__add__column_mother_name__birth_place.php create mode 100644 frontend/models/ContractForm.php create mode 100644 frontend/views/contract/_contract.php create mode 100644 frontend/views/contract/_make_contract.php delete mode 100644 frontend/views/customer/_contract.php diff --git a/backend/views/transfer/index.php b/backend/views/transfer/index.php index 946593c..b554728 100644 --- a/backend/views/transfer/index.php +++ b/backend/views/transfer/index.php @@ -56,7 +56,13 @@ $this->params['breadcrumbs'][] = $this->title; ], [ 'attribute' => 'id_user', - 'value' => 'userName' + 'value' => 'userName' , + 'label' => 'Kiadta' , + ], + [ + 'attribute' => 'paid_by', + 'value' => 'paidByName' , + 'label' => 'Fizette' ], [ 'attribute' => 'id_account', diff --git a/changelog.txt b/changelog.txt index 6a41bb9..e3ab6d8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +-0.0.39 + - add TransferPayout + - add ContractForm + -0.0.38 - add backend skin - add import add/edit to key diff --git a/common/components/Azaz.php b/common/components/Azaz.php new file mode 100644 index 0000000..f495138 --- /dev/null +++ b/common/components/Azaz.php @@ -0,0 +1,63 @@ +EgyesStr = array('', 'egy', 'kettő', 'három', 'négy', 'öt', 'hat', 'hét', 'nyolc', 'kilenc'); + $this->TizesStr = array('', 'tíz', 'húsz', 'harminc', 'negyven', 'ötven', 'hatvan', 'hetven', 'nyolcvan', 'kilencven'); + $this->TizenStr = array('', 'tizen', 'huszon', 'harminc', 'negyven', 'ötven', 'hatvan', 'hetven', 'nyolcvan', 'kilencven'); + } + + public function toString($Mit) + { + $this->Mit = $Mit; + $this->Result = ''; + if ($Mit == 0) + { + $this->Result = 'Nulla'; + } + else + { + $this->Maradek = abs($this->Mit); + if ($this->Maradek > 999999999999) + { + throw new Exception('Túl nagy szám: '.$this->Maradek); + } + $this->Alakit($this->Maradek, 1000000000, 'milliárd'); + $this->Alakit($this->Maradek, 1000000, 'millió'); + $this->Alakit($this->Maradek, 1000, 'ezer'); + $this->Alakit($this->Maradek, 1, ''); + $this->Result = ucfirst($this->Result); + if ( $Mit < 0 ) + $this->Result = 'Mínusz ' . $this->Result; + } + + return $this->Result; + } + + + protected function Alakit($Maradek, $Oszto, $Osztonev) + { + if ( $Maradek >= $Oszto) + { + if ( mb_strlen($this->Result) > 0 ) + $this->Result = $this->Result . '-'; + + $this->Mit = $Maradek / $Oszto; + if ( $this->Mit >= 100) + $this->Result = $this->Result . $this->EgyesStr[$this->Mit / 100] . 'száz'; + + $this->Mit = $this->Mit % 100; + if ($this->Mit % 10 !== 0) + $this->Result = $this->Result . $this->TizenStr[$this->Mit / 10] . $this->EgyesStr[$this->Mit % 10] . $Osztonev; + else + $this->Result = $this->Result . $this->TizesStr[$this->Mit / 10] . $Osztonev; + } + + $this->Maradek = $this->Maradek % $Oszto; + } + +} \ No newline at end of file diff --git a/common/components/Helper.php b/common/components/Helper.php index 2fd8139..d25b481 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -255,6 +255,9 @@ class Helper { public static function isUserCartVisibilityUser() { return \Yii::$app->params ['user_cart_item_visibility'] == 'user'; } + public static function isUserCartVisibilityAll() { + return \Yii::$app->params ['user_cart_item_visibility'] == 'all'; + } public static function getBackendSkin() { return \Yii::$app->params ['backend_skin'] ; diff --git a/common/components/TransferPayout.php b/common/components/TransferPayout.php new file mode 100644 index 0000000..75dcfcc --- /dev/null +++ b/common/components/TransferPayout.php @@ -0,0 +1,118 @@ +readTransfers(); + + + if ( count($this->transfers ) ==0 ){ + \Yii::error("TransferPayout - üres lista kifizetés"); + throw new Exception("Nem található kifizethető tranzakció a listában. "); + } + + + if ( !$this->isTransferCountMatchWithRequestesTransferCount() ){ + \Yii::error("TransferPayout - input tranzakció azonosítók száma nem egyezik a betöltött tranzakciók számával"); + throw new Exception("A kifizetni kívánt tranzakciók száma nem egyezik a kifizehtető tranzakciók számával. "); + } + + foreach ($this->transfers as $transfer){ + $this->payoutTransfer($transfer); + } + } + + public function readTransfers(){ + $query = Transfer::find(); + $query->andWhere([ 'in' , 'transfer.id_transfer' , $this->idTransfers ]); + $query->andWhere( ['transfer.status' => Transfer::STATUS_NOT_PAID]) ; + + if ( Helper::isUserCartVisibilityUser()){ + $query->innerJoin("user" ,"user.id = transfer.id_user"); + } + + $this->transfers = $query->all(); + \Yii::info("TransferPayout - betöltött tranzakciók száma:" . count($this->transfers) ); + } + + /** + * Ellenőrizzük, hogy annyi tranzakciót töltöttünk e be, mint amennyit parameterként kaptunkk + * */ + public function isTransferCountMatchWithRequestesTransferCount(){ + return count($this->transfers) == count($this->idTransfers); + } + + /** + * @param common\models\Transfer $transfer the transfer to payout + * */ + protected function payoutTransfer($transfer){ + + $transfer->paid_by = $this->idUser; + $transfer->status = Transfer::STATUS_PAID; + $transfer->paid_at = date('Y-m-d H:i:s' ); + + $account = $transfer->account; + + if ( isset($account )){ + /**Ha a tranzakció eredet kasszája látható típusu, akkor változtathatjuk az atuális kasszára. Különben nem*/ + if ($account->type == Account::TYPE_ALL){ + $transfer->id_account = Account::readDefault(); + } + } + + \Yii::info("fizetési mód: " . $this->overridePaymentMethod); + if ( isset($this->overridePaymentMethod ) && array_search($this->overridePaymentMethod, array_keys( Transfer::paymentMethods()) ) ){ + \Yii::info("fizetési mód beállítva: " .$this->overridePaymentMethod ); + $transfer->payment_method = $this->overridePaymentMethod; + } + + if ( $transfer->save(false) == false ){ + \Yii::error("Tranzakció kifizetése sikertelen volt: " . $transfer->id_transfer); + throw new Exception("Tranzakció fizetése sikertelen volt!"); + } + + try{ + ShoppingCart::deleteAll( ['id_transfer' => $transfer->id_transfer] ); + UserSoldItem::deleteAll( ['id_transfer' => $transfer->id_transfer] ); + }catch (\Exception $e){ + \Yii::error("TransferPayout - tranzakció törlése a kosarakból sikertelen volt. Tranzakció: " . $transfer->id_transfer); + throw new Exception("Tranzakció fizetése sikertelen volt!"); + } + + } + + +} \ No newline at end of file diff --git a/common/config/params.php b/common/config/params.php index 4127063..8aa8a67 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -4,7 +4,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.38', + 'version' => 'v0.0.39', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global @@ -12,9 +12,9 @@ return [ /**Kassza nyitáskor küldjünk email-t?*/ 'mail_account_state_open' => true, /**Kassza záráskor küldjünk email-t?*/ - 'mail_account_state_close' => true, - 'login_reception_email' => true, //if reception login should send email - 'login_admin_email' => true, //if admin login should send email + 'mail_account_state_close' => false, + 'login_reception_email' => false, //if reception login should send email + 'login_admin_email' => false, //if admin login should send email 'account_state_close_preload_money' => 'true',//preload money wnen show account state close page 'ugiro_duplom_kod' => 1, 'ugiro_kezdemenyezo_szamlaszam' => '000000000000000',//5860025215371128 @@ -22,10 +22,20 @@ return [ //a recepicó kosár csak az aktuális user által kiadott termékeket tartalmazza //vagy mindent //értékek user|all + // * - user: a felhasználó csak azokat a termékeket látja a kosrába, amiket ő rakott bele + // - all: a felhasználó minden kosrában lévő terméket lát, még azokat is , amiket nem ő rakott bele 'user_cart_item_visibility' => 'user', /** * Hány napig láthatják visszamenőleg a recepciósok az adatokat * */ 'reception_visibility_days' => 3, 'backend_skin' => 'skin-red', //skin-green + /** + * if products in carts are visible for everyone or only for the user + * possible values : + * - user: a felhasználó csak azokat a termékeket látja a kosrába, amiket ő rakott bele + * - global: a felhasználó minden kosrában lévő terméket lát, még azokat is , amiket nem ő rakott bele + * + **/ + ]; diff --git a/common/models/Contract.php b/common/models/Contract.php index 16aedad..722ed80 100644 --- a/common/models/Contract.php +++ b/common/models/Contract.php @@ -88,6 +88,9 @@ class Contract extends \yii\db\ActiveRecord public function getTicketType(){ return $this->hasOne(TicketType::className(), ['id_ticket_type' => 'id_ticket_type']); } + public function getTicket(){ + return $this->hasOne(Ticket::className(), ['id_contract' => 'id_contract']); + } public function getCustomer(){ return $this->hasOne(Customer::className(), ['id_customer' => 'id_customer']); @@ -179,4 +182,20 @@ class Contract extends \yii\db\ActiveRecord public function isFlagActive() { return $this->flag == static::$FLAG_ACTIVE; } + + public function getPriceMonthly(){ + return $this->ticket->price_brutto; + } + + public function getPartsTotal(){ + $money = $this->getPriceMonthly(); + $money = $money * $this->part_count; + return $money; + } + + public function getPriceTotal(){ + $money = $this->getPartsTotal(); + $money = $money + $this->getPriceMonthly(); + return $money; + } } diff --git a/common/models/Customer.php b/common/models/Customer.php index 6f90a73..ba2d763 100644 --- a/common/models/Customer.php +++ b/common/models/Customer.php @@ -96,6 +96,8 @@ class Customer extends \yii\db\ActiveRecord 'updated_at' => Yii::t('common/customer', 'Updated At'), 'customerCardNumber' => Yii::t('common/customer', 'Card number'), 'cardNumber' => Yii::t('common/customer', 'Card number'), + 'mother_name' => Yii::t('common/customer', 'Anyja neve'), + 'birth_place' => Yii::t('common/customer', 'Születési hely'), ]; } @@ -172,6 +174,16 @@ class Customer extends \yii\db\ActiveRecord return $result; } + public function getFullAddress(){ + $zip = $this->zip; + $city = $this->city; + $address = $this->address; + + $result = $zip . " " .$city . ", ". $address; + return $result; + + } + } diff --git a/common/models/ShoppingCart.php b/common/models/ShoppingCart.php index f57aaca..40fc652 100644 --- a/common/models/ShoppingCart.php +++ b/common/models/ShoppingCart.php @@ -3,6 +3,7 @@ namespace common\models; use Yii; +use common\components\Helper; /** * This is the model class for table "shopping_cart". @@ -72,6 +73,8 @@ class ShoppingCart extends \yii\db\ActiveRecord if ( isset($account)){ $sql .= " , id_account = " . $account; + } else if ( Helper::isUserCartVisibilityAll()){ + $sql .= " , id_account = " . Account::readDefault(); } $sql .= " WHERE t.status = " . Transfer::STATUS_NOT_PAID diff --git a/common/models/TicketType.php b/common/models/TicketType.php index 9cbaf09..2a03a4c 100644 --- a/common/models/TicketType.php +++ b/common/models/TicketType.php @@ -223,9 +223,11 @@ class TicketType extends \common\models\BaseFitnessActiveRecord { $ticketTypes = null; if ( $forceIncludeObjectWithId == null){ - $ticketTypes = TicketType::find()->andWhere(['status' => self::STATUS_ACTIVE])->andFilterWhere(['ticket_type.id_account' => $account])->all(); + $ticketTypes = TicketType::find()->andWhere(['status' => self::STATUS_ACTIVE ]) + ->andWhere([ '<>', 'installment_enabled' , '1']) ->andFilterWhere(['ticket_type.id_account' => $account])->all(); }else{ - $ticketTypes = TicketType::find()->andWhere( ['or', ['status' => self::STATUS_ACTIVE], ['id_ticket_type' => $forceIncludeObjectWithId ] ])->andFilterWhere(['ticket_type.id_account' => $account])->all(); + $ticketTypes = TicketType::find()->andWhere( ['or', ['status' => self::STATUS_ACTIVE], ['id_ticket_type' => $forceIncludeObjectWithId ] ]) + ->andWhere([ '<>', 'installment_enabled' , '1'])->andFilterWhere(['ticket_type.id_account' => $account])->all(); } return $ticketTypes; diff --git a/common/models/Transfer.php b/common/models/Transfer.php index fb30ce2..b4666cf 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -488,8 +488,9 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { $transfers = [ ]; $query = Transfer::find (); + $query->innerJoin("user_sold_item","user_sold_item.id_transfer = transfer.id_transfer"); - $query->innerJoinWith ( 'userSoldItem' ); +// $query->innerJoinWith ( 'userSoldItem' ); if ( Helper::isUserCartVisibilityUser()){ $query->andWhere ( [ 'user_sold_item.id_user' => $user->id @@ -942,6 +943,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { } } public function payout() { + if ($this->status != Transfer::STATUS_NOT_PAID) { return false; } @@ -949,14 +951,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { $this->status = Transfer::STATUS_PAID; $this->paid_at = Helper::getDateTimeString (); $this->paid_by = \Yii::$app->user->id; - ShoppingCart::deleteAll ( [ - 'id_transfer' => $this->id_transfer - ] ); - UserSoldItem::deleteAll ( [ - 'id_transfer' => $this->id_transfer + + if( Helper::isUserCartVisibilityAll() ){ + $this->id_account = Account::readDefault(); + } + + ShoppingCart::deleteAll ( [ 'id_transfer' => $this->id_transfer ] ); + UserSoldItem::deleteAll ( [ 'id_transfer' => $this->id_transfer ] ); return $this->save (); } + + public static function payoutAll($id_user, $id_array) { ShoppingCart::deleteAll ( [ 'in', @@ -968,24 +974,29 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { 'id_transfer', $id_array ] ); - Transfer::updateAll ( [ - 'status' => Transfer::STATUS_PAID, - 'paid_at' => Helper::getDateTimeString (), - 'paid_by' => $id_user - ], [ - [ - 'in', - 'id_transfer', - $id_array - ], - [ - 'in', - 'status', - [ - Transfer::STATUS_NOT_PAID - ] - ] - ] ); + + $updateConfig = null; + if ( Helper::isUserCartVisibilityUser() ){ + $updateConfig = [ + 'status' => Transfer::STATUS_PAID, + 'paid_at' => Helper::getDateTimeString (), + 'paid_by' => $id_user + ]; + }else{ + $updateConfig = [ + 'status' => Transfer::STATUS_PAID, + 'paid_at' => Helper::getDateTimeString (), + 'paid_by' => $id_user, + 'id_account' => Account::readDefault(), + ]; + } + + $updateConditions = [ + [ 'in','id_transfer', $id_array ], + [ 'in', 'status', [ Transfer::STATUS_NOT_PAID ] ] + ]; + + Transfer::updateAll ( $updateConfig , $updateConditions ); } /** diff --git a/common/models/UserSoldItem.php b/common/models/UserSoldItem.php index 7b7ad3c..45b0915 100644 --- a/common/models/UserSoldItem.php +++ b/common/models/UserSoldItem.php @@ -99,8 +99,12 @@ class UserSoldItem extends \yii\db\ActiveRecord if ( isset($account)){ $sql .= " , id_account = " . $account; + }else if ( Helper::isUserCartVisibilityAll() ){ + $sql .= " , id_account = " . Account::readDefault(); } + + $sql .= " WHERE t.status = " . Transfer::STATUS_NOT_PAID; //we can see all transfer in cart, or just our diff --git a/console/migrations/m160221_132448_alter__table__customer__add__column_mother_name__birth_place.php b/console/migrations/m160221_132448_alter__table__customer__add__column_mother_name__birth_place.php new file mode 100644 index 0000000..6befa23 --- /dev/null +++ b/console/migrations/m160221_132448_alter__table__customer__add__column_mother_name__birth_place.php @@ -0,0 +1,31 @@ +addColumn("customer", "mother_name", "string"); + $this->addColumn("customer", "birth_place", "string"); + } + + public function down() + { + echo "m160221_132448_alter__table__customer__add__column_mother_name__birth_place cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/controllers/ContractController.php b/frontend/controllers/ContractController.php index bd6a4ef..e3e6e1a 100644 --- a/frontend/controllers/ContractController.php +++ b/frontend/controllers/ContractController.php @@ -17,6 +17,8 @@ use common\components\Helper; use common\models\Sale; use common\models\Product; use common\models\ShoppingCart; +use common\models\Customer; +use frontend\models\ContractForm; /** * ContractController implements the CRUD actions for Contract model. @@ -32,10 +34,10 @@ class ContractController extends Controller { ], 'payout' => [ 'post' - ], + ], 'cancel' => [ 'post' - ], + ] ] ] ]; @@ -43,7 +45,7 @@ class ContractController extends Controller { /** * Lists all Contract models. - * + * * @return mixed */ public function actionIndex($id_card) { @@ -65,7 +67,7 @@ class ContractController extends Controller { /** * Displays a single Contract model. - * + * * @param integer $id * @return mixed */ @@ -90,7 +92,7 @@ class ContractController extends Controller { /** * Creates a new Contract model. * If creation is successful, the browser will be redirected to the 'view' page. - * + * * @return mixed */ public function actionCreate() { @@ -111,7 +113,7 @@ class ContractController extends Controller { /** * Updates an existing Contract model. * If update is successful, the browser will be redirected to the 'view' page. - * + * * @param integer $id * @return mixed */ @@ -133,7 +135,7 @@ class ContractController extends Controller { /** * Deletes an existing Contract model. * If deletion is successful, the browser will be redirected to the 'index' page. - * + * * @param integer $id * @return mixed */ @@ -160,21 +162,21 @@ class ContractController extends Controller { $result = Transfer::sellContractTicket ( $contract, $part, Account::readDefaultObject (), Transfer::STATUS_NOT_PAID, Transfer::PAYMENT_METHOD_CASH, true ); $transfer = $result [0]; - $ticket = $result[1]; - if ( $part->status != TicketInstallmentRequest::$STATUS_REJECTED ){ - $contract->part_required = $contract->part_required +1; + $ticket = $result [1]; + if ($part->status != TicketInstallmentRequest::$STATUS_REJECTED) { + $contract->part_required = $contract->part_required + 1; } - $contract->part_paid = $contract->part_paid +1; + $contract->part_paid = $contract->part_paid + 1; - if ( $contract->part_paid >= $contract->part_required){ + if ($contract->part_paid >= $contract->part_required) { $contract->status = Contract::$STATUS_PAID; - }else{ + } else { $contract->status = Contract::$STATUS_NOT_PAID; } - $contract->save(false); - + $contract->save ( false ); + $part->status = TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL; $part->id_transfer = $transfer->id_transfer; $part->request_processed_at = Helper::getDateTimeString (); @@ -258,16 +260,16 @@ class ContractController extends Controller { $transaction->commit (); \Yii::$app->session->setFlash ( 'success', "Szerződés felbontva!" ); - return $this->redirect ( [ + return $this->redirect ( [ 'product/sale', - 'number' => $card->number + 'number' => $card->number ] ); } catch ( Exception $e ) { $transaction->rollback (); Yii::error ( "Szerződés felbontása nem sikerült!" ); } - }else{ - \Yii::$app->session->setFlash ( 'danger', "Szerződést nem lehet felbontani!" ); + } else { + \Yii::$app->session->setFlash ( 'danger', "Szerződést nem lehet felbontani!" ); } return $this->redirect ( [ @@ -275,11 +277,62 @@ class ContractController extends Controller { 'id' => $contract->id_contract ] ); } + public function actionMake($id) { + $customer = Customer::findOne ( $id ); + + if (! isset ( $customer )) { + throw new Exception ( "Az oldal nem található" ); + } + + $model = new ContractForm ( [ + 'customer' => $customer + ] ); + $model->fillOut (); + + if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { + + $connection = \Yii::$app->db; + $transaction = $connection->beginTransaction (); + try { + + $model->make (); + $transaction->commit(); + return $this->redirect ( [ + 'contract/view', + 'id' => $model->contract->id_contract + ] ); + } catch ( \Exception $e ) { + $transaction->rollBack(); + \Yii::$app->session->setFlash('danger', $e->getMessage()); + } + } + + return $this->render ( '_make_contract', [ + 'model' => $model + ] ); + } + + public function actionContract($id){ + $model = $this->findModel($id); + + $mpdf=new \mPDF('utf-8', 'A4'); + $mpdf->WriteHTML($this->renderPartial('_contract', [ + 'model' => $model, + ])); + + $fileName = "szerzodes"; + $fileName .= "." . $model->customer->name; + $fileName .= "." .\Yii::$app->formatter->asDate( $model->created_at, "Y"); + $fileName .=".pdf"; + $mpdf->Output($fileName, 'D');//download file +// $mpdf->Output('szerzodes.pdf', 'I');//open in new tab + exit; + } /** * Finds the Contract model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. - * + * * @param integer $id * @return Contract the loaded model * @throws NotFoundHttpException if the model cannot be found diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index 6b61d50..0ac81bf 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -14,6 +14,8 @@ use common\models\Card; use frontend\models\CustomerUpdate; use frontend\models\CustomerCreate; use common\models\Image; +use frontend\models\ContractForm; +use yii\base\Exception; /** * CustomerController implements the CRUD actions for Customer model. @@ -205,16 +207,13 @@ class CustomerController extends Controller } - public function actionContract($id){ - $model = $this->findModel($id); - - $mpdf=new \mPDF('utf-8', 'A4-L'); - $mpdf->WriteHTML($this->renderPartial('_contract', [ - 'model' => $model, - ])); - $mpdf->Output('szerzodes.pdf', 'D'); - exit; - } + + + + + + +// s /** * Deletes an existing Customer model. diff --git a/frontend/controllers/KeyController.php b/frontend/controllers/KeyController.php index c6ada24..a4948aa 100644 --- a/frontend/controllers/KeyController.php +++ b/frontend/controllers/KeyController.php @@ -100,6 +100,9 @@ class KeyController extends Controller $model->toggleKey(); } + if ( isset($model->action ) && $model->action == 'unassign' ){ + return $this->redirect(['product/sale', 'number' => $number ]); + } return $this->redirect(['customer/reception', 'number' => $number ]); diff --git a/frontend/controllers/ProductController.php b/frontend/controllers/ProductController.php index 81991c2..0033c22 100644 --- a/frontend/controllers/ProductController.php +++ b/frontend/controllers/ProductController.php @@ -28,6 +28,8 @@ use frontend\components\DefaultAccountBehavior; use frontend\components\CassaOpenBehavior; use common\components\ProductInventory; use frontend\models\ProductInventorySearch; +use common\components\Helper; +use common\components\TransferPayout; /** * ProductController implements the CRUD actions for Product model. @@ -62,17 +64,17 @@ class ProductController extends Controller { '@' ] ] - ] - // everything else is denied - - ] , + ] + ], + // everything else is denied + // named behavior, configuration array - 'defaultAccount' => [ - 'class' => DefaultAccountBehavior::className(), - ], - 'cassaIsOpen' => [ - 'class' => CassaOpenBehavior::className(), + 'defaultAccount' => [ + 'class' => DefaultAccountBehavior::className () ], + 'cassaIsOpen' => [ + 'class' => CassaOpenBehavior::className () + ] ]; } public function actionSale($number = null) { @@ -156,100 +158,86 @@ class ProductController extends Controller { } } public function actionPayoutUserCart() { - if (Yii::$app->request->isAjax) { -// $result = [ ]; -// \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + $model = new UserCartPayoutForm (); + $user = User::findOne ( Yii::$app->user->id ); + + if ($model->load ( Yii::$app->request->post () ) && $model->validate () && isset ( $user ) && count ( $model->transfers ) > 0) { -// $user = User::findOne ( Yii::$app->user->id ); -// UserSoldItem::payout ( $user ); - -// $userTransfers = Transfer::modelsToArray ( Transfer::readUserSoldTransfers ( $user ) ); -// $result ['transfers'] = $userTransfers; -// $result ['code'] = 'success'; - - return $result; - } else { - $model = new UserCartPayoutForm (); - $user = User::findOne ( Yii::$app->user->id ); - - if ( $model->load ( Yii::$app->request->post () ) && $model->validate () &&isset ( $user ) && count ( $model->transfers ) > 0) { + $connection = \Yii::$app->db; + $transaction = $connection->beginTransaction (); + try { + $tp = new TransferPayout ( [ + 'idUser' => \Yii::$app->user->id, + 'idTransfers' => $model->transfers, + 'cartType' => 'user', + 'idAccount' => Account::readDefault () + ] ); - $connection = \Yii::$app->db; - $transaction = $connection->beginTransaction (); - try { - UserSoldItem::payout ( $user, $model->transfers ); - $transaction->commit (); - \Yii::$app->session->setFlash ( 'success', 'Recepicó kosár fizetve' ); - } catch ( Exception $e ) { - $transaction->rollback (); - Yii::error ( "faled to save :" . $e->getMessage () ); - } - } else { - Yii::error ( "faled to save : transfer" ); - \Yii::$app->session->setFlash ( 'warning', 'Nem történt változás' ); + $tp->payout (); + + // UserSoldItem::payout ( $user, $model->transfers ); + $transaction->commit (); + \Yii::$app->session->setFlash ( 'success', 'Recepicó kosár fizetve' ); + } catch ( Exception $e ) { + $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); + } catch ( \Exception $e ) { + $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); } + } else { + Yii::error ( "faled to save : transfer" ); + \Yii::$app->session->setFlash ( 'warning', 'Nem történt változás' ); } return $this->redirect ( Yii::$app->request->referrer ); } + + public function actionPayoutCustomerCart($number) { $cart = [ ]; $code = 'error'; $message = 'Hiba történt'; - if (Yii::$app->request->isAjax) { - $result = [ ]; - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + // post + $model = new CustomerCartPayoutForm (); + + if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { $this->findByNumber ( $number ); - if (isset ( $this->customer )) { + if (isset ( $this->customer ) && count ( $model->transfers ) > 0) { $connection = \Yii::$app->db; $transaction = $connection->beginTransaction (); try { - ShoppingCart::payout ( $this->customer ); + $tp = new TransferPayout ( [ + 'idUser' => \Yii::$app->user->id, + 'idTransfers' => $model->transfers, + 'cartType' => 'customer', + 'idAccount' => Account::readDefault (), + 'idCustomer' => $this->customer->id_customer + ] ); + + $tp->payout (); + + // UserSoldItem::payout ( $user, $model->transfers ); $transaction->commit (); - $cart = Transfer::modelsToArray ( Transfer::readCustomerCart ( $this->customer ) ); - $code = 'success'; - $message = 'Bevásárlókosár fizetve: ' . $this->card->number; + \Yii::$app->session->setFlash ( 'success', 'Vendég kosár fizetve : ' . $this->customer->name ); } catch ( Exception $e ) { $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); + } catch ( \Exception $e ) { + $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); } + } else { + Yii::error ( "faled to save : no customer or transfer" ); + \Yii::$app->session->setFlash ( 'warning', 'Nem történt kifizetés' ); } - $result ['customer_cart'] = $cart; - $result ['code'] = $code; - $result ['message'] = $message; - - return $result; } else { - // post - $model = new CustomerCartPayoutForm (); - - if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { - - $this->findByNumber ( $number ); - - if (isset ( $this->customer ) && count ( $model->transfers ) > 0) { - $connection = \Yii::$app->db; - $transaction = $connection->beginTransaction (); - try { - ShoppingCart::payout ( $this->customer, $model->transfers , Account::readDefault()); - $transaction->commit (); - \Yii::$app->session->setFlash ( 'success', 'Vendég kosár kifizetve' ); - } catch ( Exception $e ) { - $transaction->rollback (); - Yii::error ( "faled to save :" . $e->getMessage () ); - \Yii::$app->session->setFlash ( 'danger', 'Hiba történt a mentés során' ); - } - } else { - Yii::error ( "faled to save : no customer or transfer" ); - \Yii::$app->session->setFlash ( 'warning', 'Nem történt változás' ); - } - }else{ - \Yii::$app->session->setFlash ( 'warning', 'Nem történt változás' ); - } - return $this->redirect ( Yii::$app->request->referrer ); + \Yii::$app->session->setFlash ( 'warning', 'Nem történt változás' ); } + return $this->redirect ( Yii::$app->request->referrer ); } /** @@ -279,102 +267,84 @@ class ProductController extends Controller { return $result; } - - - - - - public function actionInventory( ) { + public function actionInventory() { + $searchModel = new ProductInventorySearch ( [ + 'account' => Account::readDefaultObject () + ] ); - $searchModel = new ProductInventorySearch( - ['account' => Account::readDefaultObject()] - ); + // $searchModel->search(\Yii::$app->request->params); + $dataProvider = $searchModel->search ( Yii::$app->request->queryParams ); -// $searchModel->search(\Yii::$app->request->params); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + // $inventory = new ProductInventory([ + // ]); + // if ( $output == 'xls'){ + // $inventory->pagination = false; + // } + // $inventory->createDataProvider(); + // $dp = $inventory->dataProvider; -// $inventory = new ProductInventory([ -// ]); -// if ( $output == 'xls'){ -// $inventory->pagination = false; -// } - -// $inventory->createDataProvider(); -// $dp = $inventory->dataProvider; - - if ( $searchModel->output == 'xls' ){ - - $models = $dataProvider->getModels(); - $objPHPExcel = new \PHPExcel(); - - $sheet = $objPHPExcel->setActiveSheetIndex(0); - /** - * -Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva - * */ + if ($searchModel->output == 'xls') { + + $models = $dataProvider->getModels (); + $objPHPExcel = new \PHPExcel (); + + $sheet = $objPHPExcel->setActiveSheetIndex ( 0 ); + /** + * Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva + */ $row = 1; - $sheet - ->setCellValue('A'.$row, "Termék azonosító") - ->setCellValue('B'.$row, "Termék név") - ->setCellValue('C'.$row, "Termék szám") - ->setCellValue('D'.$row, "Termék vonalkód") - ->setCellValue('E'.$row, "Termék raktáron"); -// ->setCellValue('F'.$row, "Eladott mennyiség"); - - foreach ($models as $model ){ - $row++; - $sheet->setCellValue('A'.$row, $model['product_id']) - ->setCellValue('B'.$row, $model['product_name']) - ->setCellValue('C'.$row, $model['product_number']) - ->setCellValue('D'.$row, $model['product_barcode']) - ->setCellValue('E'.$row, $model['product_stock']); -// ->setCellValue('F'.$row, $model['product_sold']); + $sheet->setCellValue ( 'A' . $row, "Termék azonosító" )->setCellValue ( 'B' . $row, "Termék név" )->setCellValue ( 'C' . $row, "Termék szám" )->setCellValue ( 'D' . $row, "Termék vonalkód" )->setCellValue ( 'E' . $row, "Termék raktáron" ); + // ->setCellValue('F'.$row, "Eladott mennyiség"); + + foreach ( $models as $model ) { + $row ++; + $sheet->setCellValue ( 'A' . $row, $model ['product_id'] )->setCellValue ( 'B' . $row, $model ['product_name'] )->setCellValue ( 'C' . $row, $model ['product_number'] )->setCellValue ( 'D' . $row, $model ['product_barcode'] )->setCellValue ( 'E' . $row, $model ['product_stock'] ); + // ->setCellValue('F'.$row, $model['product_sold']); } - $styleArray = array( - 'font' => array( - 'bold' => true, -// 'color' => array('rgb' => 'FF0000'), -// 'size' => 15, -// 'name' => 'Verdana' - )); + $styleArray = array ( + 'font' => array ( + 'bold' => true + ) + ); + // 'color' => array('rgb' => 'FF0000'), + // 'size' => 15, + // 'name' => 'Verdana' - foreach(range('A','E') as $columnID) - { - $sheet->getColumnDimension($columnID)->setAutoSize(true); - $sheet->getStyle($columnID.'1')->applyFromArray($styleArray); + + + foreach ( range ( 'A', 'E' ) as $columnID ) { + $sheet->getColumnDimension ( $columnID )->setAutoSize ( true ); + $sheet->getStyle ( $columnID . '1' )->applyFromArray ( $styleArray ); } - // Redirect output to a client’s web browser (Excel5) - header('Content-Type: application/vnd.ms-excel'); - header('Content-Disposition: attachment;filename="leltar.xls"'); - header('Cache-Control: max-age=0'); + header ( 'Content-Type: application/vnd.ms-excel' ); + header ( 'Content-Disposition: attachment;filename="leltar.xls"' ); + header ( 'Cache-Control: max-age=0' ); // If you're serving to IE 9, then the following may be needed - header('Cache-Control: max-age=1'); + header ( 'Cache-Control: max-age=1' ); // If you're serving to IE over SSL, then the following may be needed - header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past - header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified - header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 - header ('Pragma: public'); // HTTP/1.0 - $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); - $objWriter->save('php://output'); - exit; - + header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); // Date in the past + header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); // always modified + header ( 'Cache-Control: cache, must-revalidate' ); // HTTP/1.1 + header ( 'Pragma: public' ); // HTTP/1.0 + $objWriter = \PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' ); + $objWriter->save ( 'php://output' ); + exit (); } - - - return $this->render('inventory',[ 'searchModel' =>$searchModel, 'dataProvider' => $dataProvider]); + return $this->render ( 'inventory', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider + ] ); } - - /** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. - * + * * @param integer $id * @return Product the loaded model * @throws NotFoundHttpException if the model cannot be found @@ -398,12 +368,10 @@ Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktár } } } - - /** * Lists all Product models. - * + * * @return mixed */ /* @@ -420,7 +388,7 @@ Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktár */ /** * Displays a single Product model. - * + * * @param integer $id * @return mixed */ @@ -435,7 +403,7 @@ Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktár /** * Updates an existing Product model. * If update is successful, the browser will be redirected to the 'view' page. - * + * * @param integer $id * @return mixed */ @@ -456,7 +424,7 @@ Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktár /** * Deletes an existing Product model. * If deletion is successful, the browser will be redirected to the 'index' page. - * + * * @param integer $id * @return mixed */ @@ -471,7 +439,7 @@ Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktár /** * Creates a new Product model. * If creation is successful, the browser will be redirected to the 'view' page. - * + * * @return mixed */ /* diff --git a/frontend/controllers/TransferController.php b/frontend/controllers/TransferController.php index 72ede21..ce8ebbd 100644 --- a/frontend/controllers/TransferController.php +++ b/frontend/controllers/TransferController.php @@ -23,6 +23,9 @@ use frontend\models\UserCartForm; use common\models\Customer; use frontend\models\CustomerCartForm; use common\models\Card; +use common\components\Helper; +use yii\base\Exception; +use common\components\TransferPayout; /** * TransferController implements the CRUD actions for Transfer model. @@ -190,26 +193,27 @@ class TransferController extends Controller $transfer = $this->findModel($id); $connection = \Yii::$app->db; $transaction = $connection->beginTransaction(); + try { - $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!' ); - $transaction->commit(); - }else{ - throw new \Exception("Failed to save"); - } - - } catch(Exception $e) { - $transaction->rollback(); - \Yii::$app->session->setFlash( 'danger','Tranzakció kifizetése nem sikerült' ); + $tp = new TransferPayout( [ + 'idUser' => \Yii::$app->user->id, + 'idTransfers' => [$transfer->id_transfer ], + 'idAccount' => Account::readDefault (), + ] ); + + $tp->payout (); + + // UserSoldItem::payout ( $user, $model->transfers ); + $transaction->commit (); + \Yii::$app->session->setFlash ( 'success', 'Tranzakció fizetve: ' . $transfer->count ." db " . $transfer->getObjectName() . " - " . $transfer->money); + } catch ( Exception $e ) { + $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); + } catch ( \Exception $e ) { + $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); } - return $this->redirect(Yii::$app->request->referrer); } @@ -359,6 +363,8 @@ class TransferController extends Controller $model->run(); return $this->render("usercart",[ 'model' => $model]); } + + public function actionCustomerCart($id_card){ $defaultAccount = Account::readDefault(); diff --git a/frontend/models/ContactForm.php b/frontend/models/ContactForm.php index 613abb5..3d04aff 100644 --- a/frontend/models/ContactForm.php +++ b/frontend/models/ContactForm.php @@ -56,4 +56,7 @@ class ContactForm extends Model ->setTextBody($this->body) ->send(); } + + + } diff --git a/frontend/models/ContractForm.php b/frontend/models/ContractForm.php new file mode 100644 index 0000000..63cce09 --- /dev/null +++ b/frontend/models/ContractForm.php @@ -0,0 +1,307 @@ + 20 + ], + [ + [ + 'bank_account' + ], + 'string', + 'max' => 24 + ], + [ + [ + 'bank_name' + ], + 'string', + 'max' => 100 + ], + [ + [ + 'mothername', + 'birthplace', + 'name', + 'zip', + 'city', + 'address' + ], + 'string', + 'max' => 100 + ], + [ + [ + 'birthdate' + ], + 'date' + ], + [ + [ + 'ticket_type', + 'id_discount', + 'payment_method' + ], + 'integer' + ], + [ + [ + 'ticket_type' + ], + 'validateTicketType' + ] + ]; + } + public function validateTicketType($attribute, $params) { + $this->ticketType = TicketType::findOne ( $this->ticket_type ); + if (! isset ( $this->ticketType )) { + $this->addError ( $attribute, "Bérlet típus nem található" ); + } + } + + /** + * @inheritdoc + */ + public function attributeLabels() { + return [ + 'name' => 'Név', + 'birthdate' => 'Születési dátum', + 'birthplace' => 'Születési hely', + 'mothername' => 'Anyja neve', + 'zip' => 'Irányítószám', + 'city' => 'Város', + 'address' => 'Cím', + 'bank_account' => 'Bankszámlaszám', + 'bank_name' => 'Bank neve', + 'phone' => 'Telefonszám', + 'email' => 'E-mail', + 'ticket_type' => 'Bérlet típus' , + 'payment_method' => 'Fizetési mód' , + 'id_discount' => 'Kedvezmény' , + ]; + } + public function fillOut() { + $this->name = $this->customer->name; + $this->birthdate = isset ( $this->customer->birthdate ) ? \Yii::$app->formatter->asDate ( $this->customer->birthdate ) : ''; + $this->birthplace = $this->customer->birth_place; + $this->mothername = $this->customer->mother_name; + $this->zip = $this->customer->zip; + $this->city = $this->customer->city; + $this->address = $this->customer->address; + $this->bank_account = $this->customer->bank_account; + $this->bank_name = $this->customer->bank_name; + $this->phone = $this->customer->phone; + $this->email = $this->customer->email; + } + public function make() { + $this->money = $this->ticketType->price_brutto; + $this->discount = Discount::findOne($this->id_discount); + if ( isset($this->discount)){ + $this->money = Discount::applyDiscount($this->ticketType->price_brutto, $this->discount); + } + $this->updateCustomer (); + + + $this->createTicket (); + $this->createTransfer (); + $this->appendToCustomerCart(); + $this->addContract(); + + $this->ticket->id_contract = $this->contract->id_contract; + + if ( !$this->ticket->update(false)){ + \Yii::error("Nem sikerült a bérlethez hozzárendelni a szerződést"); + throw new Exception("Hiba történt mentés közben!"); + } + + return true; + } + public function updateCustomer() { + $this->customer->name = $this->name; + $this->customer->birthdate = $this->birthdate; + $this->customer->birth_place = $this->birthplace; + $this->customer->mother_name = $this->mothername; + $this->customer->zip = $this->zip; + $this->customer->city = $this->city; + $this->customer->address = $this->address; + $this->customer->bank_account = $this->bank_account; + $this->customer->bank_name = $this->bank_name; + $this->customer->phone = $this->phone; + $this->customer->email = $this->email; + + if (! $this->customer->save ( false )) { + throw new Exception ( 'nem sikerült a szerződés létrehozása' ); + } + } + public function createTicket() { + + $ticket = new Ticket (); + $ticket->id_user = \Yii::$app->user->id; + $ticket->id_account = Account::readDefault (); + $ticket->id_discount = $this->id_discount; + $ticket->start = date ( 'Y-m-d' ); + $date = new \DateTime (); + $date->modify ( '+1 month' ); + $date->modify ( '-1 day' ); + $ticket->end = $date->format ( 'Y-m-d H:i:s' ); + $ticket->id_ticket_type = $this->ticketType->id_ticket_type; + $ticket->price_brutto = $this->money; + $ticket->max_usage_count = $this->ticketType->max_usage_count; + $ticket->usage_count = 0; + $ticket->status = Ticket::STATUS_ACTIVE; + $ticket->comment = "Szerződéses bérlet"; + $ticket->id_card = $this->customer->card->id_card; + $ticket->part = 0; + $ticket->part_paid = 0; + $ticket->part_count = $this->ticketType->installment_count; + + if (! $ticket->save ( false )) { + \Yii::error ( "A bérlet mentése sikertelen volt" ); + throw new Exception ( "Hiba történt mentés közben" ); + } + + $this->ticket = $ticket; + } + public function createTransfer() { + $transfer = new Transfer (); + $transfer->id_object = $this->ticket->id_ticket; + $transfer->status = Transfer::STATUS_NOT_PAID; + $transfer->type = Transfer::TYPE_TICKET; + $transfer->item_price = $this->money; + $transfer->count = 1; + $transfer->money = $this->money; + $transfer->id_user = \Yii::$app->user->id; + $transfer->comment = "Szerződéses bérlet"; + $transfer->id_account = Account::readDefault (); + $transfer->direction = Transfer::DIRECTION_IN; + $transfer->id_customer = $this->customer->id_customer; + $transfer->payment_method = $this->payment_method; + $transfer->id_discount = $this->id_discount; + + if (! $transfer->save ( false )) { + \Yii::error ( "A tranzakció mentése sikertelen volt" ); + throw new Exception ( "Hiba történt mentés közben" ); + } + $this->transfer = $transfer; + } + + public function addContract() { + if (! $this->ticketType->isInstallment ()) { + \Yii::error ( "A bérlet típus nem tágmogatja a szerződés kötést!" ); + throw new Exception ( "A bérlet típus nem tágmogatja a szerződés kötést!" ); + } + + $contract = new Contract (); + $contract->id_customer = $this->customer->id_customer; + $contract->id_user = \Yii::$app->user->id; + $contract->status = Contract::$STATUS_PAID; + $contract->flag = Contract::$FLAG_ACTIVE; + $contract->part_count = $this->ticketType->installment_count; + $contract->part_paid = 0; + $contract->part_required = 0; + $contract->expired_at = date ( 'Y-m-d', strtotime ( "today +12 month -1 day" ) ); + $contract->id_ticket_type = $this->ticketType->id_ticket_type; + + if (! $contract->save ( false )) { + \Yii::error ( "A szerződés mentése sikertelen volt" ); + throw new Exception ( "Hiba történt mentés közben" ); + } + + $this->contract = $contract; + + $requests = TicketInstallmentRequest::createInstallments ( $this->ticket, $this->ticketType, $this->customer, $contract ); + foreach ( $requests as $request ) { + $request->save ( false ); + if (! $request->save ( false )) { + \Yii::error ( "A szerződés részlet mentése sikertelen volt" ); + throw new Exception ( "Hiba történt mentés közben" ); + } + } + } + + public function appendToCustomerCart(){ + $item = new ShoppingCart(); + $item->id_customer = $this->customer->id_customer; + $item->id_transfer = $this->transfer->id_transfer; + if ( !$item->save(false) ){ + \Yii::error("Vendég kosár hozzárendelés sikertelen!"); + throw new Exception ( "Hiba történt mentés közben" ); + } + + } +} diff --git a/frontend/models/CustomerCartForm.php b/frontend/models/CustomerCartForm.php index 807e091..8fa730b 100644 --- a/frontend/models/CustomerCartForm.php +++ b/frontend/models/CustomerCartForm.php @@ -6,6 +6,7 @@ use Yii; use yii\base\Model; use common\models\Transfer; use common\models\Account; +use common\components\TransferPayout; /** * ContactForm is the model behind the contact form. @@ -60,19 +61,34 @@ class CustomerCartForm extends Model } 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; - } + + $connection = \Yii::$app->db; + $transaction = $connection->beginTransaction(); + try { + $tp = new TransferPayout( [ + 'idUser' => \Yii::$app->user->id, + 'idTransfers' => $this->selected, + 'idAccount' => Account::readDefault (), + 'cartType' => 'customer', + 'overridePaymentMethod' => $this->payment_method, + 'idCustomer' => $this->customer->id_customer + ] ); + + $tp->payout (); + + $transaction->commit (); + \Yii::$app->session->setFlash ( 'success', 'A vásárló kosár kiválasztott tranzakciói ki lettek kifizetve!'); + return true; + + } catch ( Exception $e ) { + $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); + } catch ( \Exception $e ) { + $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); + } + return false; + }else{ \Yii::$app->session->setFlash('danger', 'Nem választott ki terméket'); return false; diff --git a/frontend/models/CustomerCreate.php b/frontend/models/CustomerCreate.php index dbedb6c..958f714 100644 --- a/frontend/models/CustomerCreate.php +++ b/frontend/models/CustomerCreate.php @@ -105,7 +105,9 @@ class CustomerCreate extends \common\models\Customer [['zip'], 'string', 'max' => 8], [['city'], 'string', 'max' => 30], - [['photo_data'] ,'safe'] + [['photo_data'] ,'safe'], + [['birth_place'] ,'safe'], + [['mother_name'] ,'safe'], // [['email','phone'], 'validateEmailOrPhoneRequired' ], ]; diff --git a/frontend/models/CustomerUpdate.php b/frontend/models/CustomerUpdate.php index db4f31b..89214fa 100644 --- a/frontend/models/CustomerUpdate.php +++ b/frontend/models/CustomerUpdate.php @@ -115,7 +115,9 @@ class CustomerUpdate extends \common\models\Customer [['zip'], 'string', 'max' => 8], [['city'], 'string', 'max' => 30], - [['photo_data'] ,'safe'] + [['photo_data'] ,'safe'], + [['birth_place'] ,'safe'], + [['mother_name'] ,'safe'], ]; } diff --git a/frontend/models/KeyToggleForm.php b/frontend/models/KeyToggleForm.php index 43efd5f..d3af4a3 100644 --- a/frontend/models/KeyToggleForm.php +++ b/frontend/models/KeyToggleForm.php @@ -17,7 +17,7 @@ class KeyToggleForm extends Model public $card; public $customer; public $keyModel; - + public $action; @@ -55,6 +55,7 @@ class KeyToggleForm extends Model $assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all(); if ( count($assignments) > 0){ $this->unassign(); + $this->action = 'unassign'; }else{ $this->assign(); } diff --git a/frontend/models/UserCartForm.php b/frontend/models/UserCartForm.php index 92f031a..c49172e 100644 --- a/frontend/models/UserCartForm.php +++ b/frontend/models/UserCartForm.php @@ -7,6 +7,7 @@ use yii\base\Model; use common\models\Transfer; use common\components\Helper; use common\models\Account; +use common\components\TransferPayout; /** * ContactForm is the model behind the contact form. @@ -60,19 +61,48 @@ class UserCartForm extends Model } 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; - } + + $connection = \Yii::$app->db; + $transaction = $connection->beginTransaction(); + try { + $tp = new TransferPayout( [ + 'idUser' => \Yii::$app->user->id, + 'idTransfers' => $this->selected, + 'idAccount' => Account::readDefault (), + 'cartType' => 'user', + 'overridePaymentMethod' => $this->payment_method + ] ); + + $tp->payout (); + + $transaction->commit (); + \Yii::$app->session->setFlash ( 'success', 'A recepció kosár kiválasztott tranzakciói ki lettek kifizetve!'); + return true; + + } catch ( Exception $e ) { + $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); + } catch ( \Exception $e ) { + $transaction->rollback (); + Yii::error ( "faled to save :" . $e->getMessage () ); + } + return false; + +// $items = $this->loadTransfers($this->selected); +// if ( count($items) == count($this->selected) ){ +// foreach ($items as $item){ +// $this->changePaymentMethod($item); +// if ( Helper::isUserCartVisibilityAll() ){ +// $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; diff --git a/frontend/views/contract/_contract.php b/frontend/views/contract/_contract.php new file mode 100644 index 0000000..5a439a9 --- /dev/null +++ b/frontend/views/contract/_contract.php @@ -0,0 +1,294 @@ + + +customer; + + $customerName = $customer->name; + $customerAddress = $customer->getFullAddress(); + $customerBirthInfo = $customer->birth_place . ", " . ( isset( $customer->birthdate ) ? \Yii::$app->formatter->asDate($customer->birthdate) : ''); + $customerMotherName = $customer->mother_name; + $customerPhone = $customer->phone; + $customerEmail = $customer->email; + $customerBankAccount = $customer->bank_account; + $customerIdCustomer = $customer->id_customer; + + $contractDate = date('Y.m.d'); + + $azaz = new Azaz(); + $ticketMoneyYear = $model->getPriceTotal(); + $ticketMoneyYearText = $azaz->toString($ticketMoneyYear); + + $ticketMoneyMonth = $model->getPriceMonthly(); + $ticketMoneyMonthText = $azaz->toString($ticketMoneyMonth); + + $customerBankName = $customer->bank_name; + + +?> +

+ TAGSÁGI SZERZŐDÉS +

+ + +

+ Mely létrejött egyrészről: + + + + + + + + + + +
+ Cutler-Four Kereskedelmi és Szolgáltató Korlátolt Felelősségű Társaság +
+ székhely: 9222 Hegyeshalom, Pozsonyi u. 11. +
+ adószám: 25006285-2-08 +
+ cégjegyzékszám: 08-09-0260601 +
+ bankszámlaszám: 59500155-11109938 +
+ képviseli: Freimann Sándor ügyvezető +
+ (a továbbiakban, mint Szolgáltató), +
+

+ +

+másrészről: + + + + + + + + + + +
+ név: +
+ lakcím: +
+ születési hely, idő: +
+ anyja neve: +
+ telefonszám: +
+ e-mail cím: +
+ bankszámlaszám: +
+

+

+ (a továbbiakban, mint Tag) között alulírott helyen és időben az alábbi feltételekkel. +

+ + +
    +
  1. + A szerződő felek rögzítik, hogy a Tag igénybe kívánja venni a 9027 Győr, Nagysándor József utca 31. szám alatti CUTLER FITNESS Győr edzőterem szolgáltatásait az alábbiakban részletezett feltételek alapján. +
  2. +
  3. + A szerződő felek rögzítik, hogy jelen megállapodást 12 hónap határozott időtartamra kötik, melynek kezdő időpontja a jelen szerződés aláírásának a napja. +

    + Felek megállapodnak abban is, hogy a jelen szerződés automatikusan további újabb és újabb 12 hónappal ráutaló magatartással meghosszabbodik mindaddig, ameddig bármelyik fél a szerződés, illetve a meghosszabbodott szerződés lejártát megelőző 30 napon belül a másik fél részére írásban a szerződés megszűntetésére vonatkozó szándékát nem közli. +

    +

    + A Szerződő Felek kijelentik, hogy a Tag a határozott időtartamú szerződés hatálya alatt, a CUTLER FITNESS Győr szolgáltatásait kedvezményesen veheti igénybe. Ezen kedvezményes éves tagsági díj összege Ft, azaz forint, amely havi részletekben fizetendő meg. Így a havonta fizetendő tagsági díj összege havi Ft, azaz forint, melynek első részletét a Tag jelen szerződés aláírásakor köteles megfizetni. Az első részlet megfizetéséig a Tag nem jogosult a szolgáltatások igénybe vételére. +

    +

    + A további részletek előre, a jelen szerződésmegkötését követő 30 naponta esedékesek. Ezen összegeket a Szolgáltató a Tag bankszámlájáról történő leemeléssel, úgy nevezett csoportos beszedési megbízással szedi be a Tag jelen szerződéssel egyidejűleg adott, aláírt felhatalmazása alapján. +

    +

    + Tag tudomásul veszi, hogy a Szolgáltató a bankszámláról történő beszedést az esedékességet megelőző 15 napon belül jogosult elindítani. Tag köteles a bankszámláján legalább a levonandó összegnek megfelelő egyenleget tartani, hogy a beszedés megtörténhessen. +

    +
  4. +
  5. + Amennyiben a Szolgáltató részére az adott hónapban nem teljesül a bankszámláról történő beszedés, úgy azt Szolgáltató nem ismétli meg (aktuális időszakra). Amennyiben a Tag továbbra is igénybe kívánja venni a Szolgáltató szolgáltatását a díjfizetéssel nem rendezett időszakban, úgy köteles a hátralék egyéb úton történő megfizetésére. +
  6. +
  7. + Tag tudomásul veszi, hogy a Szolgáltató a szolgáltatási díjjal nem rendezett időszak alatt az elmaradás rendezéséig, az igénybe vehető szolgáltatások körét részben vagy egészben korlátozhatja, a Szolgáltató a belépést a területére megtilthatja. +
  8. +
  9. + Amennyiben Szolgáltató legalább 3 egymást követő hónapban sem tudja beszedni a bérlet összegét a bankszámlára indított csoportos beszedéssel, úgy Szolgáltató jogosult jelen Szerződés azonnali hatályú felmondására. +
  10. +
  11. + A Tag kijelenti, hogy a Szolgáltató recepciójánál kifüggesztett Házirendjét és jelen szerződést elolvasta, értelmezte és azt magára nézve kötelezőnek ismerte el. +
  12. +
  13. + 7. Felmondási lehetőségek +
      +
    1. + A Tag tudomásul veszi, hogy a határozott időtartam alatt nincs lehetőség a tagsági jogviszony felmondására. Indokolt esetben (pl. terhesség, sérülés, távoli helyre költözés, stb.) a Tag írásban kezdeményezheti a Szerződés közös megegyezéssel történő megszűntetését, amely kérelemről a Szolgáltató 15 napon belül saját belátása szerint dönt és döntéséről a kérelmezőt értesíti. +
    2. +
    3. + Jelen szerződés azonnali hatályú felmondására jogosult a Szolgáltató, amennyiben a Tag a bankszámlájára vonatkozó csoportos beszedési megbízásra vonatkozó felhatalmazást visszavonja a bankjánál, a bankszámláját megszünteti vagy a Házirendet súlyosan megszegi. +

      + Ha Szolgáltató bármelyik fenti ok kapcsán él az azonnali hatályú felmondásra vonatkozó jogával, akkor a Tag köteles a szerződéséből hátralévő határozott időtartam alapulvételével havi 3.000,- Ft, azaz Háromezer forint kötbér megfizetésére, továbbá a felmondást követő 1 éven belül nem lesz jogosult újabb éves szerződés megkötésére. +

      +
    4. +
    5. + Szolgáltató bármikor egyoldalúan jogosult arra, hogy a jelen Szerződést 30 napos felmondási idővel írásban felmondja, amennyiben a Tag a Házirendet bizonyíthatóan megsérti. +
    6. +
    +
  14. +
  15. + Jelen szerződésben nem szabályozott kérdésekben a Ptk. rendelkezései az irányadóak. +
  16. +
+ +

+ Kelt: Győr, +

+ + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Szolgáltató + + + Tag +
+ Cutler-FourKft. + + + +
+ Freimann Sándor ügyvezető + + +
+ + + + +

Felhatalmazás csoportos beszedési megbízás teljesítésére

+
    +
  1. +
    + Fizető fél adatai: +
    +
    + Fizető fél neve: +
    +
    + Fizető fél bankszámlaszáma: +
    +
  2. +
  3. +
    + Kedvezményezett adatai: +
    +
    + Kedvezményezett neve: CUTLER-FOUR Kereskedelmi és Szolgáltató Kft. +
    +
    + Kedvezményezett azonosítója: A25006285 +
    +
  4. +
  5. +
    + Kedvezményezettel szerződéses viszonyban lévő személy adatai: +
    +
    + Szerződő fél neve: +
    +
    + Szerződő fél címe: +
    +
    + Szerződő fél azonosítója a Kedvezményezettnél: +
    +
  6. +
  7. +
    + Teljesítés adatai: +
    +
    + Érvényesség kezdete: lejárata: +
    +
    + Teljesítés felső értékhatára: +
    +
  8. +
  9. +
    + Felhatalmazás jellege: eredeti felhatalmazás +
    +
  10. +
  11. + Nyilatkozat +

    + Jelen nyomtatvány kitöltésével és aláírásával felhatalmazom pénzforgalmi szolgáltatót arra, hogy a fentebb megjelölt Kedvezményezettet az általam benyújtott felhatalmazásról értesítse, és fizetési számlámat a Kedvezményezett által benyújtott beszedési megbízás alapján – megbízásom keretei között – megterhelje. Tudomásul veszem, hogy a beszedési megbízás teljesítésére szóló felhatalmazás elfogadásáról, a beszedés megkezdésének tényleges időpontjáról, illetve az elutasításáról és annak okáról a Kedvezményezettől a számlavezetőm és a szerződő fél értesítést kap. +

    +
  12. +
+ + + + + + + +
+ Kelt: Győr, + + + + Kelt: Győr, +
+ + + + + + + + + + + + + +
+ + + +
+ Fizető fél aláírása + + + Átvevő aláírása +
\ No newline at end of file diff --git a/frontend/views/contract/_make_contract.php b/frontend/views/contract/_make_contract.php new file mode 100644 index 0000000..87b1ff9 --- /dev/null +++ b/frontend/views/contract/_make_contract.php @@ -0,0 +1,119 @@ + + + TicketType::STATUS_ACTIVE ,'installment_enabled' => '1']); + $types = HtmlHelper::mkTicketTypeOptions($types); + + $discounts = Discount::read(); + $discounts = ['' => ''] + HtmlHelper::mkDiscountOptions($discounts); + +?> +

Szerződés létrehozása

+
+ + +
+
+ field($model, 'name')->textInput() ?> +
+
+ field($model, 'mothername')->textInput() ?> +
+
+
+
+ field($model, 'birthdate')->widget(DatePicker::classname(), [ + 'pluginOptions' => [ + 'autoclose'=>true, + 'format' => 'yyyy.mm.dd' + ] + ]) ?> +
+
+ field($model, 'birthplace')->textInput() ?> +
+
+
+
+ field($model, 'zip')->textInput() ?> + +
+
+ + field($model, 'city')->textInput() ?> + + +
+
+
+
+ + field($model, 'address')->textInput() ?> + +
+
+ +
+
+
+
+ field($model, 'bank_name')->textInput() ?> +
+
+ field($model, 'bank_account')->textInput() ?> +
+
+
+
+ field($model, 'phone')->textInput() ?> +
+
+ field($model, 'email')->textInput() ?> +
+
+
+
+ field($model, 'ticket_type')->dropDownList($types) ?> +
+
+ +
+
+
+
+ field($model, 'payment_method')->dropDownList(Transfer::paymentMethods()) ?> +
+
+ field($model, 'id_discount')->dropDownList( $discounts ) ?> +
+
+ + + + + + + +
+ 'btn btn-success' ]) ?> +
+ + + +
diff --git a/frontend/views/contract/index.php b/frontend/views/contract/index.php index 9062efc..991265f 100644 --- a/frontend/views/contract/index.php +++ b/frontend/views/contract/index.php @@ -19,6 +19,10 @@ $this->params['breadcrumbs'][] = $this->title; render('_search', ['model' => $searchModel]); ?> + $searchModel->customer->id_customer ], ['class' => 'btn btn-success']) +?> $dataProvider, diff --git a/frontend/views/contract/view.php b/frontend/views/contract/view.php index 142f759..98726c9 100644 --- a/frontend/views/contract/view.php +++ b/frontend/views/contract/view.php @@ -14,6 +14,8 @@ $this->params['breadcrumbs'][] = $this->title; ?> $model->customer->card,'title' => 'Szerződés részletek'])?> + +
params['breadcrumbs'][] = $this->title; ?> Szerződés felbontása esetén a már megkezdett hónapokra hónaponként 3000 Ft büntetést írunk fel a vásárló kosarába
+ +
+
+
+ $model->id_contract], [ 'class' => 'btn btn-success']); + ?> +

@@ -90,7 +100,7 @@ $this->params['breadcrumbs'][] = $this->title; isStatusPending() || $inst->isStatusRejected() ){ - echo Html::a("Fizetettnek jelölés és bérlet vásárló kásrba helyezése",['contract/payout' , 'id' => $inst->id_ticket_installment_request], [ 'data-method' => 'post', 'class' => 'btn btn-danger']); + echo Html::a("Fizetettnek jelölés és bérlet vásárló kosarába helyezése",['contract/payout' , 'id' => $inst->id_ticket_installment_request], [ 'data-method' => 'post', 'class' => 'btn btn-danger']); } ?> diff --git a/frontend/views/customer/_contract.php b/frontend/views/customer/_contract.php deleted file mode 100644 index 08b2be7..0000000 --- a/frontend/views/customer/_contract.php +++ /dev/null @@ -1,24 +0,0 @@ -

- Éves szerződés -

- - -

- Ez az éves szerződés szövege -

-

- Kövektező bekezdés -

-

- A szerződő fél neve: - -name -?> - -

- -

- A cég neve: - params['company_name']?> -

\ No newline at end of file diff --git a/frontend/views/customer/_form_create.php b/frontend/views/customer/_form_create.php index b0f27a0..c00a7e2 100644 --- a/frontend/views/customer/_form_create.php +++ b/frontend/views/customer/_form_create.php @@ -54,6 +54,20 @@ use kartik\widgets\DatePicker;
field($model, 'sex')->dropDownList(Customer::sexes()) ?>
+
+
+ + +
+
+ field($model, 'mother_name')->textInput(['maxlength' => true]) ?> +
+
+ +
+
+ field($model, 'birth_place')->textInput(['maxlength' => true]) ?> +
field($model, 'birthdate')->widget(DatePicker::classname(), [ 'pluginOptions' => [ @@ -78,6 +92,8 @@ use kartik\widgets\DatePicker;
+ +
field($model, 'description')->textarea(['maxlength' => true]) ?> diff --git a/frontend/views/customer/_form_update.php b/frontend/views/customer/_form_update.php index 063cab5..26612df 100644 --- a/frontend/views/customer/_form_update.php +++ b/frontend/views/customer/_form_update.php @@ -44,20 +44,34 @@ use yii\base\Widget; field($model, 'email')->textInput(['maxlength' => true]) ?>
- +
field($model, 'sex')->dropDownList(Customer::sexes()) ?>
+
+ +
+
+ field($model, 'mother_name')->textInput(['maxlength' => true]) ?> +
+
+ +
- field($model, 'birthdate',[ ] )->widget(DatePicker::classname(), [ + field($model, 'birth_place')->textInput(['maxlength' => true]) ?> +
+
+ field($model, 'birthdate')->widget(DatePicker::classname(), [ 'pluginOptions' => [ 'autoclose'=>true, 'format' => 'yyyy.mm.dd' ] ]) ?>
-
+ + +
diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 677f614..c2ae89f 100644 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -68,17 +68,21 @@ AppAsset::register($this);
-