Add ContractForm, Add contract pdf, Add Display all Transfer option

This commit is contained in:
2016-02-21 21:41:25 +01:00
parent 462e93c740
commit 29a8b440b2
33 changed files with 1417 additions and 304 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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 ]);

View File

@@ -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 clients 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
*/
/*

View File

@@ -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();