diff --git a/backend/models/ContractSearch.php b/backend/models/ContractSearch.php index 6fe2c03..43408c4 100644 --- a/backend/models/ContractSearch.php +++ b/backend/models/ContractSearch.php @@ -59,6 +59,7 @@ class ContractSearch extends Contract 'contract.part_count as contract_part_count', 'contract.created_at as contract_created_at', 'contract.expired_at as contract_expired_at', + 'contract.started_at as contract_started_at', ]); $query->from('contract'); @@ -117,6 +118,10 @@ class ContractSearch extends Contract 'asc' => ['contract.expired_at' => SORT_ASC ], 'desc' => ['contract.expired_at' => SORT_DESC], ], + 'contract_started_at' => [ + 'asc' => ['contract.started_at' => SORT_ASC ], + 'desc' => ['contract.started_at' => SORT_DESC], + ], ] ], ]); diff --git a/backend/views/contract/index.php b/backend/views/contract/index.php index 94aa537..b6f8037 100644 --- a/backend/views/contract/index.php +++ b/backend/views/contract/index.php @@ -75,6 +75,11 @@ $this->params['breadcrumbs'][] = $this->title; 'label' =>'Létrehozva', 'format' => 'date' ], + [ + 'attribute' => 'contract_started_at' , + 'label' =>'Érvényes tól', + 'format' => 'date' + ], [ 'attribute' => 'contract_expired_at' , 'label' =>'Lejárat', diff --git a/common/models/Contract.php b/common/models/Contract.php index 728bd11..2dfd0d0 100644 --- a/common/models/Contract.php +++ b/common/models/Contract.php @@ -22,6 +22,7 @@ use common\components\Helper; * @property string $expired_at * @property string $created_at * @property string $updated_at + * @property string $started_at */ class Contract extends \yii\db\ActiveRecord { @@ -82,6 +83,7 @@ class Contract extends \yii\db\ActiveRecord 'expired_at' => Yii::t('common/contract', 'Lejárati dátum'), 'created_at' => Yii::t('common/contract', 'Létrehozva'), 'updated_at' => Yii::t('common/contract', 'Módosítva'), + 'started_at' => Yii::t('common/contract', 'Érvényesség kezdete'), ]; } diff --git a/common/models/TicketInstallmentRequest.php b/common/models/TicketInstallmentRequest.php index 3fb6a00..5791dfe 100644 --- a/common/models/TicketInstallmentRequest.php +++ b/common/models/TicketInstallmentRequest.php @@ -123,7 +123,12 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord } public function getTicketExpirationDate(){ - return strtotime( $this->request_target_time_at . " +1 month -1 day") ; + $date = \DateTime::createFromFormat("Y-m-d H:i:s", $this->request_target_time_at, new \DateTimeZone( 'UTC')); + $date->modify("+1 month"); + $date->modify("-1 day"); + $date->setTime(0, 0, 0); + + return $date->getTimestamp(); } @@ -244,11 +249,13 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord $discount = $ticket->discount; $money = $type->installment_money; if ( isset( $discount ) ){ - $money = Discount::applyDiscount($money, $discount); + $money = Discount::applyDiscount( $money, $discount ); } - $ticketCreatedAt = time(); + + + for ( $i = 1; $i <= $count; $i++){ - $request = TicketInstallmentRequest::createInstallment($ticket, $type, $customer, $contract, $money, $ticketCreatedAt, $i); + $request = TicketInstallmentRequest::createInstallment($ticket, $type, $customer, $contract, $money, null, $i); $result[] = $request; } @@ -262,7 +269,11 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord $request->id_customer = $customer->id_customer; $request->status = TicketInstallmentRequest::$STATUS_PENDING; $request->priority = $index; - $request->request_target_time_at = date('Y-m-d H:i:s', strtotime("+".$index." month" )); + $date = \DateTime::createFromFormat("Y.m.d", $contract->started_at, new \DateTimeZone( 'UTC')); + $date->modify("+$index month"); +// $date->modify("-1 day"); + $date->setTime(0, 0, 0); + $request->request_target_time_at = $date->format ( 'Y-m-d H:i:s' ); $request->request_processed_at = null; $request->request_sent_at = null; $request->money = $money; diff --git a/common/models/Transfer.php b/common/models/Transfer.php index b4666cf..a842ab1 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -672,8 +672,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { self::notInInterval ( $query, 'transfer.created_at', $start, $end ); } - echo "start date is: ". $start; - echo "start date is: " . gettype( $start ); +// echo "start date is: ". $start; +// echo "start date is: " . gettype( $start ); if ( !RoleDefinition::isAdmin() ){ Helper::restrictIfNotAdminTheStartDate($query, $start); diff --git a/console/migrations/m160302_171507_alter__table__contract__add__column__started_at.php b/console/migrations/m160302_171507_alter__table__contract__add__column__started_at.php new file mode 100644 index 0000000..83a8339 --- /dev/null +++ b/console/migrations/m160302_171507_alter__table__contract__add__column__started_at.php @@ -0,0 +1,31 @@ +addColumn("contract", "started_at", "datetime"); + $this->execute("update contract set started_at = created_at"); + } + + public function down() + { + echo "m160302_171507_alter__table__contract__add__column__started_at 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/assets/ContractMakeAsset.php b/frontend/assets/ContractMakeAsset.php new file mode 100644 index 0000000..e8b10eb --- /dev/null +++ b/frontend/assets/ContractMakeAsset.php @@ -0,0 +1,29 @@ + + * @since 2.0 + */ +class ContractMakeAsset extends AssetBundle +{ + public $basePath = '@webroot'; + public $baseUrl = '@web'; + public $css = [ + ]; + public $js = [ + 'js/contract.make.js', + ]; + public $depends = [ + 'frontend\assets\AppAsset', + 'yii\jui\JuiAsset', + ]; +} diff --git a/frontend/controllers/ContractController.php b/frontend/controllers/ContractController.php index a3644a2..e6ca023 100644 --- a/frontend/controllers/ContractController.php +++ b/frontend/controllers/ContractController.php @@ -284,9 +284,14 @@ class ContractController extends Controller { throw new Exception ( "Az oldal nem található" ); } + $model = new ContractForm ( [ 'customer' => $customer ] ); + + $model->started_at = date(date('Y.m.d')); + + $model->fillOut (); if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { diff --git a/frontend/models/ContractForm.php b/frontend/models/ContractForm.php index 63c8f72..156cf8c 100644 --- a/frontend/models/ContractForm.php +++ b/frontend/models/ContractForm.php @@ -39,6 +39,8 @@ class ContractForm extends Model { private $ticketType; private $money; private $discount; + public $started_at; + public $timestampStart; /** * @inheritdoc */ @@ -59,7 +61,9 @@ class ContractForm extends Model { "bank_name", 'phone', 'email', - 'payment_method' + 'payment_method' , + 'started_at', + 'started_at' ], 'required' ], @@ -124,7 +128,8 @@ class ContractForm extends Model { 'ticket_type' ], 'validateTicketType' - ] + ] , + [[ 'started_at', ], 'date', 'format' =>Yii::$app->formatter->dateFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ,'timeZone' => 'UTC' ], ]; } public function validateTicketType($attribute, $params) { @@ -162,6 +167,7 @@ class ContractForm extends Model { 'ticket_type' => 'Bérlet típus' , 'payment_method' => 'Fizetési mód (első bérlet)' , 'id_discount' => 'Kedvezmény' , + 'started_at' => 'Érvényesség kezdete' , ]; } public function fillOut() { @@ -223,8 +229,8 @@ class ContractForm extends Model { $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 (); + $ticket->start = $this->started_at; + $date = new \DateTime ( $this->timestampStart); $date->modify ( '+1 month' ); $date->modify ( '-1 day' ); $ticket->end = $date->format ( 'Y-m-d H:i:s' ); @@ -283,7 +289,12 @@ class ContractForm extends Model { $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->started_at = $this->started_at; + $date = new \DateTime( $this->timestampStart ); + $date->modify ( '+1 year' ); + $date->modify ( '-1 day' ); + $date->setTime(0, 0, 0); + $contract->expired_at = $date->format ( 'Y-m-d H:i:s' ); $contract->id_ticket_type = $this->ticketType->id_ticket_type; if (! $contract->save ( false )) { diff --git a/frontend/views/contract/_contract.php b/frontend/views/contract/_contract.php index 38c31f3..f0f08a7 100644 --- a/frontend/views/contract/_contract.php +++ b/frontend/views/contract/_contract.php @@ -14,6 +14,11 @@ use common\components\Azaz; $customerBankAccount = $customer->bank_account; $customerIdCustomer = $customer->id_customer; +// $dt = \DateTime::createFromFormat("Y-m-d H:i:s", $model->started_at); +// $contractStartAtDate = $dt->format("Y.m.d"); + $contractStartAtDate = \Yii::$app->formatter->asDate($model->started_at); + + $contractDate = date('Y.m.d'); $azaz = new Azaz(); @@ -241,7 +246,7 @@ másrészről: Teljesítés adatai:
+ Figyelem: A szerződés létrehozásakor a szerződés első bérlete bekerül a vásálró kosarába. +
+| Bérlet ára | ++ |
| Összesen | ++ |