Sfoglia il codice sorgente

Merge branch 'declenchement_credit_pain' into dev

dev
keun 6 anni fa
parent
commit
263df2583e
9 ha cambiato i file con 92 aggiunte e 47 eliminazioni
  1. +5
    -5
      backend/controllers/CommandeController.php
  2. +33
    -1
      backend/controllers/CronController.php
  3. +20
    -3
      backend/views/commande/report.php
  4. +1
    -1
      backend/views/user/credit.php
  5. +4
    -2
      common/models/Commande.php
  6. +3
    -35
      common/models/CommandeAuto.php
  7. +9
    -0
      common/models/CreditHistorique.php
  8. +2
    -0
      common/models/User.php
  9. +15
    -0
      console/migrations/m180315_090156_add_champs_commande_paiement_auto.php

+ 5
- 5
backend/controllers/CommandeController.php Vedi File

@@ -40,10 +40,10 @@ class CommandeController extends BackendController {
$id_etablissement = Yii::$app->user->identity->id_etablissement;

$commandes = Commande::findBy([
'date' => $date,
'id_etablissement' => $id_etablissement,
'orderby' => 'commentaire_point_vente ASC, user.nom ASC'
]);
'date' => $date,
'id_etablissement' => $id_etablissement,
'orderby' => 'commentaire_point_vente ASC, user.nom ASC'
]);

foreach ($commandes as $c)
$c->init();
@@ -1191,7 +1191,7 @@ class CommandeController extends BackendController {
foreach ($historique as $h) {
$html .= '<tr>'
. '<td>' . date('d/m/Y H:i:s', strtotime($h->date)) . '</td>'
. '<td>' . Html::encode($h->userAction->nom . ' ' . $h->userAction->prenom) . '</td>'
. '<td>' . Html::encode($h->strUserAction()) . '</td>'
. '<td>' . $h->getStrLibelle() . '</td>'
. '<td>' . ($h->isTypeDebit() ? '- '.$h->getMontant(true) : '') . '</td>'
. '<td>' . ($h->isTypeCredit() ? '+ '.$h->getMontant(true) : '') . '</td>'

+ 33
- 1
backend/controllers/CronController.php Vedi File

@@ -158,7 +158,7 @@ class CronController extends BackendController {
}
}

public function actionSendCommandes($key = '') {
public function actionProcessCommandes($key = '') {
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') {
$heure = date('H');

@@ -178,6 +178,38 @@ class CronController extends BackendController {
]);

if ($production && $heure == $e['heure_limite_commande']) {
/*
* Paiement des commandes (paiement automatique)
*/
$commandes = Commande::find()
->with('commandeProduits', 'user')
->joinWith('production')
->where(['production.date' => $date])
->orderBy('date ASC')
->all();

foreach($commandes as $c) {
if($c->paiement_automatique && Etablissement::getConfig('credit_pain', $c->production->id_etablissement)) {
$c->init() ;

if ($c->getMontantRestant() > 0) {
$c->creditHistorique(
CreditHistorique::TYPE_PAIEMENT,
$c->getMontantRestant(),
$c->production->id_etablissement,
$c->id_user,
User::ID_USER_SYSTEM
);
}
}
}
/*
* Envoi des commandes par email au producteur
*/
$commandes = Commande::find()
->with('commandeProduits', 'user')
->joinWith('production')

+ 20
- 3
backend/views/commande/report.php Vedi File

@@ -15,12 +15,18 @@ foreach ($points_vente as $pv) {
$html .= '<h3>'.$pv->nom.'</h3>' ;

$col_credit_pain = '' ;
if($pv->credit_pain) {
$col_credit_pain = '<th>Rappel crédit</th>' ;
}
$html .= '<table class="table table-bordered">'
. '<thead>'
. '<tr>'
. '<th>Client</th>'
. '<th>Produits</th>'
. '<th>Commentaire</th>'
. $col_credit_pain
. '<th>Montant</th>'
. '</tr>'
. '<tbody>';
@@ -64,7 +70,16 @@ foreach ($points_vente as $pv) {
$html .= '<td>'.substr($str_produits, 0, strlen($str_produits) - 2).'</td>';
$html .= '<td>'.$c->commentaire.'</td>';
$html .= '<td>'.number_format($c->montant, 2) . ' € ';
if($pv->credit_pain) {
$credit = '' ;
if(isset($c->user) && isset($c->user->userEtablissement)) {
$credit = number_format($c->user->userEtablissement[0]->credit,2).' €' ;
}
$html .= '<td>'.$credit.'</td>' ;
}
$html .= '<td><strong>'.number_format($c->montant, 2) . ' € ';

if($c->getStatutPaiement() == Commande::STATUT_PAYEE)
{
@@ -79,8 +94,7 @@ foreach ($points_vente as $pv) {
$html .= '(surplus : '.$c->getMontantSurplus(true).' à rembourser)' ;
}
$html .= '</td>' ;
$html .= '</strong></td>' ;
$html .= '</tr>' ;
@@ -103,6 +117,9 @@ foreach ($points_vente as $pv) {
$str_produits = substr($str_produits, 0, strlen($str_produits) - 2) ;
$html .= '<td>'.$str_produits.'</td><td></td>' ;
if($pv->credit_pain) {
$html .= '<td></td>' ;
}
$html .= '<td><strong>'.number_format($pv->recettes_pain, 2) . ' €</strong></td>';
$html .= '</tbody></table><pagebreak>' ;

+ 1
- 1
backend/views/user/credit.php Vedi File

@@ -67,7 +67,7 @@ $this->params['breadcrumbs'][] = 'Créditer';
<?php foreach($historique as $ch): ?>
<tr>
<td><?= $ch->getDate(true) ; ?></td>
<td><?php if(isset($ch->userAction)): echo Html::encode($ch->userAction->nom. ' '.$ch->userAction->prenom) ; else: echo 'Administrateur' ;endif; ?></td>
<td><?= Html::encode($ch->strUserAction()); ?></td>
<td><?= $ch->getStrLibelle(); ?></td>
<td>
<?php if($ch->isTypeDebit()): ?>

+ 4
- 2
common/models/Commande.php Vedi File

@@ -15,6 +15,7 @@ use common\models\Etablissement;
* @property string $date_update
* @property integer $id_point_vente
* @property integer $id_production
* @property boolean $paiement_automatique
*/
class Commande extends \yii\db\ActiveRecord {

@@ -111,6 +112,7 @@ class Commande extends \yii\db\ActiveRecord {
return [
[['id_user', 'date', 'id_point_vente', 'id_production'], 'required', 'message' => ''],
[['id_user', 'id_point_vente', 'id_production'], 'integer'],
[['paiement_automatique'], 'boolean'],
[['date', 'date_update', 'commentaire', 'commentaire_point_vente'], 'safe']
];
}
@@ -311,7 +313,7 @@ class Commande extends \yii\db\ActiveRecord {

$commandes = Commande::find()
->with('commandeProduits', 'creditHistorique', 'pointVente')
->joinWith(['production', 'user'])
->joinWith(['production', 'user','user.userEtablissement'])
->where(['production.id_etablissement' => $params['id_etablissement']]);

if (isset($params['condition']))
@@ -333,7 +335,7 @@ class Commande extends \yii\db\ActiveRecord {
$commandes = $commandes->limit($params['limit']);

$commandes = $commandes->all();
return $commandes;
}


+ 3
- 35
common/models/CommandeAuto.php Vedi File

@@ -180,7 +180,8 @@ class CommandeAuto extends \yii\db\ActiveRecord {
$commande->type = Commande::TYPE_AUTO;
$commande->id_point_vente = $this->id_point_vente;
$commande->id_production = $production->id;

$commande->paiement_automatique = $this->paiement_automatique ;
$point_vente_user = PointVenteUser::find()
->where(['id_point_vente' => $this->id_point_vente, 'id_user' => $this->id_user])
->one();
@@ -208,40 +209,7 @@ class CommandeAuto extends \yii\db\ActiveRecord {

if (!$produits_add) {
$commande->delete();
} else {
// on débite automatiquement le crédit pain du client
if ($commande->id_user &&
$this->paiement_automatique &&
Etablissement::getConfig('credit_pain')) {
$commande = Commande::find()
->with('commandeProduits')
->where(['id' => $commande->id])
->one();

$commande->init();

$user_action = User::find()->where([
'id_etablissement' => $production->id_etablissement,
'status' => 11
])->one();

if ($user_action)
$id_user_action = $user_action->id;
else
$id_user_action = NULL;

if ($commande->getMontant() > 0) {
$commande->creditHistorique(
CreditHistorique::TYPE_PAIEMENT,
$commande->getMontant(),
$production->id_etablissement,
$commande->id_user,
$id_user_action
);
}
}
}
}
}
}

}

+ 9
- 0
common/models/CreditHistorique.php Vedi File

@@ -207,5 +207,14 @@ class CreditHistorique extends ActiveRecord {
default: return 'Crédit pain' ;
}
}
public function strUserAction() {
if($this->userAction) {
return $this->userAction->nom . ' ' . $this->userAction->prenom ;
}
else {
return 'Système' ;
}
}

}

+ 2
- 0
common/models/User.php Vedi File

@@ -26,6 +26,8 @@ class User extends ActiveRecord implements IdentityInterface {
const STATUS_BOULANGER = 11;
const STATUS_ADMIN = 13;

const ID_USER_SYSTEM = 0 ;
var $password_old;
var $password_new;
var $password_new_confirm;

+ 15
- 0
console/migrations/m180315_090156_add_champs_commande_paiement_auto.php Vedi File

@@ -0,0 +1,15 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

class m180315_090156_add_champs_commande_paiement_auto extends Migration {

public function up() {
$this->addColumn('commande', 'paiement_automatique', Schema::TYPE_BOOLEAN.' DEFAULT 0') ;
}

public function down() {
$this->dropColumn('commande', 'paiement_automatique') ;
}
}

Loading…
Annulla
Salva