Просмотр исходного кода

Refactoring services #885

refactoring
Guillaume Bourgeois 1 год назад
Родитель
Сommit
7fa81d5f13
49 измененных файлов: 529 добавлений и 679 удалений
  1. +1
    -1
      backend/controllers/AccessController.php
  2. +16
    -24
      backend/controllers/DocumentController.php
  3. +3
    -2
      backend/controllers/ProducerController.php
  4. +1
    -1
      backend/controllers/TaxRateAdminController.php
  5. +15
    -7
      backend/controllers/UserController.php
  6. +1
    -1
      backend/models/AccessUserProducerForm.php
  7. +13
    -5
      backend/models/CreditForm.php
  8. +1
    -1
      backend/models/MailForm.php
  9. +3
    -1
      backend/views/access/index.php
  10. +17
    -28
      backend/views/delivery-note/index.php
  11. +14
    -3
      backend/views/document/_download_product_line.php
  12. +11
    -7
      backend/views/document/_form.php
  13. +20
    -13
      backend/views/document/download.php
  14. +109
    -107
      backend/views/invoice/index.php
  15. +0
    -296
      backend/views/layouts/main-old.php
  16. +3
    -2
      backend/views/producer-admin/_form.php
  17. +16
    -12
      backend/views/producer-admin/index.php
  18. +8
    -5
      backend/views/producer/billing.php
  19. +12
    -7
      backend/views/producer/update.php
  20. +96
    -91
      backend/views/quotation/index.php
  21. +4
    -1
      backend/views/subscription/index.php
  22. +6
    -3
      backend/views/user/_form.php
  23. +6
    -4
      backend/views/user/credit.php
  24. +16
    -12
      backend/views/user/orders.php
  25. +1
    -1
      common/components/BusinessLogicTrait.php
  26. +1
    -3
      common/logic/Distribution/Distribution/Service/DistributionSolver.php
  27. +12
    -5
      common/logic/Document/DeliveryNote/Wrapper/DeliveryNoteContainer.php
  28. +44
    -0
      common/logic/Document/Document/Repository/DocumentRepository.php
  29. +5
    -1
      common/logic/Document/Document/Service/DocumentBuilder.php
  30. +16
    -4
      common/logic/Document/Document/Service/DocumentSolver.php
  31. +8
    -8
      common/logic/Document/Document/Service/DocumentUtils.php
  32. +7
    -0
      common/logic/Document/Document/Wrapper/DocumentContainer.php
  33. +1
    -0
      common/logic/Document/Invoice/Wrapper/InvoiceContainer.php
  34. +1
    -1
      common/logic/Document/Quotation/Model/QuotationSearch.php
  35. +7
    -2
      common/logic/Document/Quotation/Repository/QuotationRepository.php
  36. +3
    -1
      common/logic/Document/Quotation/Wrapper/QuotationContainer.php
  37. +2
    -2
      common/logic/Document/Quotation/Wrapper/QuotationManager.php
  38. +4
    -1
      common/logic/Order/Order/Repository/OrderRepository.php
  39. +3
    -3
      common/logic/Order/Order/Service/OrderBuilder.php
  40. +2
    -2
      common/logic/Order/Order/Service/OrderSolver.php
  41. +1
    -1
      common/logic/Producer/Producer/Service/ProducerBuilder.php
  42. +1
    -1
      common/logic/Producer/ProducerPriceRange/Repository/ProducerPriceRangeRepository.php
  43. +3
    -3
      common/logic/User/CreditHistory/Service/CreditHistorySolver.php
  44. +1
    -1
      common/mail/creditUser-html.php
  45. +1
    -1
      common/mail/creditUser-text.php
  46. +4
    -1
      common/mail/sendDocument-html.php
  47. +5
    -1
      common/mail/sendDocument-text.php
  48. +2
    -1
      console/migrations/m190206_135142_ajout_champs_gestion_credit_avancee.php
  49. +2
    -1
      console/migrations/m210326_104759_add_option_order_entry_point.php

+ 1
- 1
backend/controllers/AccessController.php Просмотреть файл

@@ -89,7 +89,7 @@ class AccessController extends BackendController
}

$producer = $this->getProducerCurrent();
$usersAccessArray = $this->getUserManager()->findUsersByProducer($producer->id);
$usersAccessArray = $this->getUserManager()->findUsersByProducer($producer);

return $this->render('index', [
'usersArray' => $usersArray,

+ 16
- 24
backend/controllers/DocumentController.php Просмотреть файл

@@ -332,14 +332,16 @@ class DocumentController extends BackendController

public function actionDownload($id)
{
$documentManager = $this->getDocumentManager();
$document = $this->findModel($id);
return $document->downloadPdf();
return $documentManager->downloadPdf($document);
}

public function actionRegenerate($id)
{
$documentManager = $this->getDocumentManager();
$document = $this->findModel($id);
$document->downloadPdf(true);
$documentManager->downloadPdf($document, true);
$this->setFlash('success', 'Le document PDF a bien été regénéré.');

return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]);
@@ -347,8 +349,9 @@ class DocumentController extends BackendController

public function actionSend(int $id, $backUpdateForm = false)
{
$documentManager = $this->getDocumentManager();
$document = $this->findModel($id);
if ($document->send()) {
if ($documentManager->send($document)) {
$document->is_sent = true;
$document->save();

@@ -377,10 +380,7 @@ class DocumentController extends BackendController
if ($user) {
$document = null;
if ($documentManager->isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $idDocument,
'id_user' => $idUser
]);
$document = $this->findModel($idDocument, $classDocument);
}

if ($document && $document->id_user == $user->id) {
@@ -464,9 +464,7 @@ class DocumentController extends BackendController
$classDocument = $this->getClass();

if ($id > 0 && $documentManager->isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $id
]);
$document = $this->findModel($id);

if ($document) {
$documentManager->changeStatus($document,Document::STATUS_VALID);
@@ -536,16 +534,15 @@ class DocumentController extends BackendController
$pointSaleManager = $this->getPointSaleManager();

if ($idDocument > 0 && $documentManager->isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $idDocument
]);

$document = $this->findModel($idDocument, $classDocument);

if ($document) {
$ordersArray = [];
$productsArray = $productManager->findProducts();

foreach ($document->orders as $order) {
$orderManager->init($order);
$orderManager->initOrder($order);
$productsOrderArray = [];

foreach ($order->productOrder as $productOrder) {
@@ -556,7 +553,7 @@ class DocumentController extends BackendController
$ordersArray[$order->id] = array_merge(
$order->getAttributes(),
[
'username' => $order->getUsername(),
'username' => $orderManager->getOrderUsername($order),
'distribution_date' => isset($order->distribution) ? date(
'd/m/Y',
strtotime(
@@ -619,9 +616,7 @@ class DocumentController extends BackendController
$productManager = $this->getProductManager();

if ($documentManager->isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $idDocument
]);
$document = $this->findModel($idDocument, $classDocument);
$product = $productManager->findOneProductById($idProduct);

if ($document && $product) {
@@ -787,13 +782,10 @@ class DocumentController extends BackendController
* @return Document
* @throws NotFoundHttpException si le modèle n'est pas trouvé
*/
protected function findModel($id)
protected function findModel($idDocument, $classDocument = null)
{
$class = $this->getClass();

$model = $class::searchOne([
'id' => $id
]);
$documentManager = $this->getDocumentManager();
$model = $documentManager->findOneDocumentByIdAndClass($idDocument, $classDocument ?? $this->getClass());

if ($model) {
return $model;

+ 3
- 2
backend/controllers/ProducerController.php Просмотреть файл

@@ -84,6 +84,7 @@ class ProducerController extends BackendController
*/
public function actionUpdate()
{
$producerManager = $this->getProducerManager();
$request = Yii::$app->request;
$model = $this->findModel(GlobalParam::getCurrentProducerId());
$logoFilenameOld = $model->logo;
@@ -128,8 +129,8 @@ class ProducerController extends BackendController
$model->save();
}

$model->savePrivateKeyApiStripe();
$model->savePrivateKeyEndpointStripe();
$producerManager->savePrivateKeyApiStripe($model);
$producerManager->savePrivateKeyEndpointStripe($model);

$model->option_stripe_private_key = '';
$model->option_stripe_endpoint_secret = '';

+ 1
- 1
backend/controllers/TaxRateAdminController.php Просмотреть файл

@@ -38,7 +38,7 @@

namespace backend\controllers;

use common\logic\Config\TaxRate\TaxRate;
use common\logic\Config\TaxRate\Model\TaxRate;
use Yii;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

+ 15
- 7
backend/controllers/UserController.php Просмотреть файл

@@ -47,11 +47,11 @@ use common\logic\Order\Order\Model\OrderSearch;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\UserPointSale\Model\UserPointSale;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\User\Model\User;
use common\logic\User\User\Model\UserSearch;
use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\UserUserGroup\Model\UserUserGroup;
use yii\base\UserException;
use yii\debug\models\search\User;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use \Yii;
@@ -270,7 +270,7 @@ class UserController extends BackendController
$newPassword = Yii::$app->request->post('submit_new_password');
if ($newPassword) {
$password = Password::generate();
$model->setPassword($password);
$userManager->setPassword($model, $password);
$model->save();

$producer = $this->getProducerCurrent();
@@ -367,8 +367,12 @@ class UserController extends BackendController
*/
public function actionDelete(int $id)
{
$userManager = $this->getUserManager();
$userProducerManager = $this->getUserProducerManager();
$userProducer = $userProducerManager->findOneUserProducer($userProducer);

$user = $userManager->findOneUserById($id);
$producer = $this->getProducerCurrent();
$userProducer = $userProducerManager->findOneUserProducer($user, $producer);

if ($userProducer) {
$userProducer->active = 0;
@@ -413,9 +417,13 @@ class UserController extends BackendController
])->all();

$usersArray = [];
foreach ($users as $user) {
if (isset($user['email']) && strlen($user['email']))
foreach ($users as $key => $user) {
if (isset($user['email']) && strlen($user['email']) > 0) {
$usersArray[] = $user['email'];
}
else {
unset($users[$key]);
}
}

$pointsSaleArray = PointSale::find()->where(['id_producer' => GlobalParam::getCurrentProducerId()])->all();
@@ -437,14 +445,14 @@ class UserController extends BackendController
if (isset($bodyResponseSendMail['Messages'])) {
foreach ($bodyResponseSendMail['Messages'] as $message) {
if ($message['Status'] != 'success') {
$emailsErrorArray[] = $message['To']['Email'];
$emailsErrorArray[] = $message['Errors'][0]['ErrorMessage'];
}
}
}

$messageError = 'Un problème est survenu lors de l\'envoi de votre email.';
if (count($emailsErrorArray) > 0) {
$messageError .= '<br />Problème détecté sur les adresses suivantes : ' . implode(',', $emailsErrorArray);
$messageError .= '<br />Problème détecté : ' . implode(',', $emailsErrorArray);
}
$this->setFlash('error', $messageError);
}

+ 1
- 1
backend/models/AccessUserProducerForm.php Просмотреть файл

@@ -39,6 +39,7 @@ termes.
namespace backend\models;

use common\helpers\GlobalParam;
use common\logic\User\User\Model\User;
use yii\base\Model;

/**
@@ -46,7 +47,6 @@ use yii\base\Model;
*/
class AccessUserProducerForm extends Model
{

public $id_user ;

/**

+ 13
- 5
backend/models/CreditForm.php Просмотреть файл

@@ -40,6 +40,12 @@ namespace backend\models;

use common\helpers\GlobalParam;
use common\helpers\Mailjet;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\CreditHistory\Wrapper\CreditHistoryManager;
use common\logic\User\User\Model\User;
use common\logic\User\User\Wrapper\UserManager;
use common\logic\User\UserProducer\Model\UserProducer;
use Yii;
use yii\base\Model;

@@ -96,10 +102,12 @@ class CreditForm extends Model
*/
public function save()
{
$creditHistoryManager = $this->getCreditHistoryManager();
$userManager = UserManager::getInstance();
$creditHistoryManager = CreditHistoryManager::getInstance();
$producerManager = ProducerManager::getInstance();

if ($this->validate()) {
$creditHistory = new CreditHistory;
$creditHistory = new CreditHistory();
$creditHistory->id_user = $this->id_user;
$creditHistory->id_user_action = Yii::$app->user->identity->id;
$creditHistory->id_producer = GlobalParam::getCurrentProducerId() ;
@@ -108,7 +116,7 @@ class CreditForm extends Model
$creditHistory->amount = $this->amount ;
$creditHistory->mean_payment = $this->mean_payment ;

$creditHistoryManager->save($creditHistory);
$creditHistoryManager->saveCreate($creditHistory);
// on prévient l'utilisateur que son compte vient d'être crédité
if($this->send_mail) {
@@ -119,10 +127,10 @@ class CreditForm extends Model
]);

$paramsEmail = [
'from_email' => $producer->getEmailOpendistrib(),
'from_email' => $producerManager->getEmailOpendistrib($producer),
'from_name' => $producer->name,
'to_email' => $user->email,
'to_name' => $user->getUsername(),
'to_name' => $userManager->getUsername($user),
'subject' => '['.$producer->name.'] Mouvement de crédit',
'content_view_text' => '@common/mail/creditUser-text.php',
'content_view_html' => '@common/mail/creditUser-html.php',

+ 1
- 1
backend/models/MailForm.php Просмотреть файл

@@ -150,7 +150,7 @@ Produits disponibles :
$productDescription .= ' / '.$product->description ;
}
if($product->price) {
$productDescription .= ' / '.Price::format($product->getPriceWithTax()) ;
$productDescription .= ' / '.Price::format($productManager->getPriceWithTax($product)) ;
$productDescription .= ' ('. $productManager->strUnit($product->unit, 'wording_unit').')' ;
}


+ 3
- 1
backend/views/access/index.php Просмотреть файл

@@ -40,6 +40,8 @@ use yii\helpers\Html ;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper ;

$userManager = $this->getUserManager();

$this->setTitle('Accès') ;

?>
@@ -53,7 +55,7 @@ $this->setTitle('Accès') ;
</div>
<div class="panel-body">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($modelAccessUserProducerForm, 'id_user')->dropDownList( User::populateDropdownList(), ['class' => 'select2'])->label(''); ?>
<?= $form->field($modelAccessUserProducerForm, 'id_user')->dropDownList( $userManager->populateUserDropdownList(), ['class' => 'select2'])->label(''); ?>
<?= Html::submitButton('Ajouter', ['class' => 'btn btn-success']) ?>
<?php ActiveForm::end(); ?>
</div>

+ 17
- 28
backend/views/delivery-note/index.php Просмотреть файл

@@ -44,6 +44,8 @@ use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use common\logic\Document\DeliveryNote\Wrapper\DeliveryNoteManager;

$deliveryNoteManager = $this->getDeliveryNoteManager();

$this->setTitle('Bons de livraison');
$this->addBreadcrumb($this->getTitle());
$this->addButton(['label' => 'Nouveau bon de livraison <span class="glyphicon glyphicon-plus"></span>', 'url' => ['distribution/index', 'message_generate_bl' => 1], 'class' => 'btn btn-primary']);
@@ -64,18 +66,14 @@ $this->addButton(['label' => 'Nouveau bon de livraison <span class="glyphicon gl
'valid' => 'Valide',
],
'format' => 'raw',
'value' => function ($model) {
$deliveryNoteManager = DeliveryNoteManager::getInstance();
'value' => function ($model) use ($deliveryNoteManager) {
return $deliveryNoteManager->getHtmlLabel($model);
}
],
[
'attribute' => 'reference',
'value' => function ($model) {
if (strlen($model->reference) > 0) {
return $model->reference;
}
return '';
return (strlen($model->reference) > 0) ? $model->reference : '';
}
],
'name',
@@ -89,13 +87,9 @@ $this->addButton(['label' => 'Nouveau bon de livraison <span class="glyphicon gl
'attribute' => 'date_distribution',
'options' => ['class' => 'form-control']
]),
'value' => function ($model) {
$deliveryNoteManager = DeliveryNoteManager::getInstance();
'value' => function ($model) use ($deliveryNoteManager) {
$distribution = $deliveryNoteManager->getDistribution($model);
if ($distribution) {
return date('d/m/Y', strtotime($distribution->date));
}
return '';
return $distribution ? date('d/m/Y', strtotime($distribution->date)) : '';
}
],
[
@@ -103,20 +97,15 @@ $this->addButton(['label' => 'Nouveau bon de livraison <span class="glyphicon gl
'header' => 'Point de vente',
'filter' => ArrayHelper::map(PointSale::searchAll([], ['as_array' => true]), 'id', 'name'),
'format' => 'html',
'value' => function ($model) {
$deliveryNoteManager = DeliveryNoteManager::getInstance();
'value' => function ($model) use ($deliveryNoteManager) {
$pointSale = $deliveryNoteManager->getPointSale($model);
if ($pointSale) {
return Html::encode($pointSale->name);
}
return '';
return $pointSale ? Html::encode($pointSale->name) : '';
}
],
[
'attribute' => 'amount',
'header' => 'Montant',
'value' => function ($deliveryNote) {
$deliveryNoteManager = DeliveryNoteManager::getInstance();
'value' => function ($deliveryNote) use ($deliveryNoteManager) {
return $deliveryNoteManager->getAmountWithTax($deliveryNote, Order::INVOICE_AMOUNT_TOTAL, true);
}
],
@@ -126,28 +115,28 @@ $this->addButton(['label' => 'Nouveau bon de livraison <span class="glyphicon gl
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'send' => function ($url, $model) {
return ((isset($model->user) && strlen($model->user->email) > 0) ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'send' => function ($url, $deliveryNote) use ($deliveryNoteManager) {
return ((isset($deliveryNote->user) && strlen($deliveryNote->user->email) > 0) ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'title' => 'Envoyer', 'class' => 'btn btn-default'
]) : '');
},
'download' => function ($url, $model) {
'download' => function ($url, $deliveryNote) {
return Html::a('<span class="glyphicon glyphicon-download-alt"></span>', $url, [
'title' => 'Télécharger', 'class' => 'btn btn-default'
]);
},
'validate' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'validate' => function ($url, $deliveryNote) use ($deliveryNoteManager) {
return ($deliveryNoteManager->isStatusDraft($deliveryNote) ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'title' => 'Valider', 'class' => 'btn btn-default'
]) : '');
},
'update' => function ($url, $model) {
'update' => function ($url, $deliveryNote) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => 'Modifier', 'class' => 'btn btn-default'
]);
},
'delete' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'delete' => function ($url, $deliveryNote) use ($deliveryNoteManager) {
return ($deliveryNoteManager->isStatusDraft($deliveryNote) ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => 'Supprimer', 'class' => 'btn btn-default'
]) : '');
}

+ 14
- 3
backend/views/document/_download_product_line.php Просмотреть файл

@@ -1,3 +1,14 @@
<?php

use common\helpers\Price;
use common\logic\Product\Product\Model\Product;
use yii\helpers\Html;

$documentManager = $this->getDocumentManager();
$productManager = $this->getProductManager();

?>

<tr class="<?php if(isset($displayOrders) && $displayOrders): ?>order<?php endif; ?>">
<td class="align-left">
<?php if($productOrder->product): ?>
@@ -13,7 +24,7 @@

<?php
$price = $productOrder->getPrice() ;
if($document->isInvoicePrice() && $productOrder->getInvoicePrice()) {
if($documentManager->isInvoicePrice($document) && $productOrder->getInvoicePrice()) {
$price = $productOrder->getInvoicePrice() ;
}
?>
@@ -26,13 +37,13 @@
<td class="align-center">
<?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?>
</td>
<td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td>
<td class="align-center"><?= $productManager->strUnit($productOrder->unit, 'wording') ?></td>
<?php if($displayPrices): ?>
<?php if($producer->taxRate->value != 0): ?>
<td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td>
<?php endif; ?>
<td class="align-center">
<?php if($document->getClass() == ''): ?>
<?php if($documentManager->getClass($document) == ''): ?>
<?= Price::format($price * $productOrder->quantity) ?>
<?php else: ?>
<?= Price::format($price * $productOrder->quantity) ?>

+ 11
- 7
backend/views/document/_form.php Просмотреть файл

@@ -42,10 +42,14 @@ use yii\widgets\ActiveForm;
\backend\assets\VuejsDocumentFormAsset::register($this);

$producerManager = $this->getProducerManager();
$documentManager = $this->getDocumentManager();
$userManager = $this->getUserManager();

$documentClass = $documentManager->getClass($model);

?>

<div class="document-form" id="app-document-form" data-class-document="<?= $model->getClass() ?>"
<div class="document-form" id="app-document-form" data-class-document="<?= $documentClass ?>"
data-id-document="<?= ($model->id > 0) ? $model->id : $model->id ?>">

<div class="<?= ($action == 'update') ? 'col-md-6' : '' ?>">
@@ -55,7 +59,7 @@ $producerManager = $this->getProducerManager();
</div>
<div class="panel-body">
<?php $form = ActiveForm::begin(); ?>
<?= Html::hiddenInput('classDocument', $model->getClass(), ['id' => 'class-document']) ?>
<?= Html::hiddenInput('classDocument', $documentClass, ['id' => 'class-document']) ?>
<?= Html::hiddenInput('typeAction', $action, ['id' => 'type-action']) ?>
<?php if ($action == 'update'): ?>
<?= Html::hiddenInput('idDocument', $model->id, ['id' => 'id-document']) ?>
@@ -64,7 +68,7 @@ $producerManager = $this->getProducerManager();

<?php if ($action == 'update'): ?>
<?= $form->field($model, 'id_user', [
'template' => '{label} <div>{input}</div>' . $model->user->getUsername(),
'template' => '{label} <div>{input}</div>' . $userManager->getUsername($model->user),
])->hiddenInput(); ?>
<?php else: ?>
<?= $form->field($model, 'id_user', [
@@ -86,7 +90,7 @@ $producerManager = $this->getProducerManager();
<?= $form->field($model, 'comment')->textarea(['rows' => 2])->hint('Affiché en bas du document') ?>
<?php endif; ?>

<?php if ($action == 'create' && $model->getClass() == 'Invoice'): ?>
<?php if ($action == 'create' && $documentClass == 'Invoice'): ?>
<template v-if="idUser > 0">
<strong>Bons de livraison</strong>
<table v-if="deliveryNoteCreateArray && deliveryNoteCreateArray.length > 0" class="table table-bordered">
@@ -117,7 +121,7 @@ $producerManager = $this->getProducerManager();
</div>
</div>

<?php if ($action == 'update' && $model->getClass() == 'Invoice'): ?>
<?php if ($action == 'update' && $documentClass == 'Invoice'): ?>
<div class="panel panel-default">
<div class="panel-heading">
Bons de livraison
@@ -208,12 +212,12 @@ $producerManager = $this->getProducerManager();
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/download', 'id' => $model->id]) ?>"
class="btn btn-sm btn-default"><span class="glyphicon glyphicon-download-alt"></span> Télécharger (PDF)</a>

<?php if($model->isStatusValid()): ?>
<?php if($documentManager->isStatusValid($model)): ?>
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/regenerate', 'id' => $model->id]) ?>"
class="btn btn-sm btn-default"><span class="glyphicon glyphicon-repeat"></span> Regénérer (PDF)</a>
<?php endif; ?>

<?php if ($model->getClass() == 'Invoice' && $producerManager->getConfig('option_export_evoliz')): ?>
<?php if ($documentClass == 'Invoice' && $producerManager->getConfig('option_export_evoliz')): ?>
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/export-csv-evoliz', 'id' => $model->id]) ?>"
class="btn btn-sm btn-default"><span class="glyphicon glyphicon-save-file"></span> Export Evoliz
(CSV)</a>

+ 20
- 13
backend/views/document/download.php Просмотреть файл

@@ -1,6 +1,13 @@
<?php

use yii\helpers\Html;
use common\logic\Order\Order\Model\Order;
use common\helpers\Price;

$producerManager = $this->getProducerManager();
$userManager = $this->getUserManager();
$documentManager = $this->getDocumentManager();
$orderManager = $this->getOrderManager();

$displayPrices = Yii::$app->controller->getClass() != 'DeliveryNote' || (Yii::$app->controller->getClass() == 'DeliveryNote' && $producerManager->getConfig('document_display_prices_delivery_note'));
$displayProductDescription = $producerManager->getConfig('document_display_product_description');
@@ -14,16 +21,16 @@ $documentPriceDecimals = (int) $producerManager->getConfig('option_document_pric
<div class="producer">
<?php if (strlen($producer->logo)) : ?>
<div class="logo">
<img style="max-height: 80px;" src="<?= $producer->getUrlLogo() ?>"/>
<img style="max-height: 80px;" src="<?= $producerManager->getUrlLogo($producer) ?>"/>
</div>
<?php endif; ?>
<div class="address"><?= $producer->getFullAddress(true); ?></div>
<div class="address"><?= $producerManager->getFullAddress($producer, true); ?></div>
</div>
<div class="user">
<?php if ($document->address && strlen($document->address) > 0): ?>
<?= nl2br($document->address) ?>
<?php else: ?>
<?= $document->user->getFullAddress(true); ?>
<?= $userManager->getFullAddress($document->user, true); ?>
<?php endif; ?>
</div>
</div>
@@ -34,7 +41,7 @@ $documentPriceDecimals = (int) $producerManager->getConfig('option_document_pric
</div>
<div class="reference">
<?php if (strlen($document->reference)) : ?>
<?= $document->getType(); ?> N°<?= $document->reference; ?>
<?= $documentManager->getType($document); ?> N°<?= $document->reference; ?>
<?php else: ?>
<div class="block-is-draft"><?= $document->getType(); ?> non
validé<?= ($document->getType() == 'Facture') ? 'e' : '' ?></div>
@@ -80,11 +87,11 @@ $documentPriceDecimals = (int) $producerManager->getConfig('option_document_pric
</thead>
<tbody>

<?php if ($document->isDisplayOrders()): ?>
<?php if ($producerManager->isDocumentDisplayOrders($document)): ?>
<?php foreach ($document->orders as $order): ?>
<tr>
<td>
<strong><?= Html::encode($order->getUsername()); ?></strong>
<strong><?= Html::encode($orderManager->getOrderUsername($order)); ?></strong>
<?php if ($order->distribution): ?>
le <?= date('d/m/Y', strtotime($order->distribution->date)) ?>
<?php endif; ?>
@@ -128,20 +135,20 @@ $documentPriceDecimals = (int) $producerManager->getConfig('option_document_pric
<?php endforeach; ?>
<?php endif; ?>
<?php if ($displayPrices): ?>
<?php $typeAmount = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL; ?>
<?php $typeAmount = $documentManager->isInvoicePrice($document) ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL; ?>

<?php if ($producer->taxRate->value != 0): ?>

<tr>
<td class="align-right" colspan="5"><strong>Total HT</strong></td>
<td class="align-center">
<?= Price::format($document->getAmount($typeAmount)); ?>
<?= Price::format($documentManager->getAmount($document, $typeAmount)); ?>
</td>
</tr>

<?php
$taxRateArray = $this->getTaxRateManager()->findTaxRatesAsArray();
foreach ($document->getTotalVatArray($typeAmount) as $idTaxRate => $totalVat): ?>
foreach ($documentManager->getTotalVatArray($document, $typeAmount) as $idTaxRate => $totalVat): ?>
<tr>
<td class="align-right" colspan="5">
<strong>TVA <?= $taxRateArray[$idTaxRate]->value * 100 ?> %</strong></td>
@@ -154,12 +161,12 @@ $documentPriceDecimals = (int) $producerManager->getConfig('option_document_pric
<!--<tr>
<td class="align-right" colspan="5"><strong>TVA</strong></td>
<td class="align-center">
<?= Price::format($document->getAmountWithTax($typeAmount) - $document->getAmount($typeAmount)) ?>
<?= Price::format($documentManager->getAmountWithTax($document, $typeAmount) - $documentManager->getAmount($document, $typeAmount)) ?>
</td>
</tr>-->
<tr>
<td class="align-right" colspan="5"><strong>Total TTC</strong></td>
<td class="align-center"><?= Price::format($document->getAmountWithTax($typeAmount)) ?></td>
<td class="align-center"><?= Price::format($documentManager->getAmountWithTax($document, $typeAmount)) ?></td>
</tr>
<?php else: ?>
<tr>
@@ -167,7 +174,7 @@ $documentPriceDecimals = (int) $producerManager->getConfig('option_document_pric
<strong>Total</strong><br/>
TVA non applicable
</td>
<td class="align-center"><?= Price::format($document->getAmount($typeAmount)) ?></td>
<td class="align-center"><?= Price::format($documentManager->getAmount($document, $typeAmount)) ?></td>
</tr>
<?php endif; ?>
<?php endif; ?>
@@ -181,7 +188,7 @@ $documentPriceDecimals = (int) $producerManager->getConfig('option_document_pric
</div>

<?php
$fieldProducerDocumentInfo = 'document_infos_' . str_replace('deliverynote', 'delivery_note', strtolower($document->getClass())); ?>
$fieldProducerDocumentInfo = 'document_infos_' . str_replace('deliverynote', 'delivery_note', strtolower($documentManager->getClass($document))); ?>
<?php if (strlen($producer->$fieldProducerDocumentInfo)): ?>
<div class="block-infos">
<strong>Informations</strong><br/>

+ 109
- 107
backend/views/invoice/index.php Просмотреть файл

@@ -39,6 +39,12 @@
use yii\helpers\Html;
use yii\grid\GridView;
use common\helpers\Url;
use common\logic\Document\Invoice\Model\Invoice;
use common\logic\Order\Order\Model\Order;

$producerManager = $this->getProducerManager();
$invoiceManager = $this->getInvoiceManager();
$userManager = $this->getUserManager();

$this->setTitle('Factures');
$this->addBreadcrumb($this->getTitle());
@@ -48,112 +54,108 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-

<div class="invoice-index">

<?php if(Invoice::searchCount()): ?>
<?= GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'status',
'label' => 'Statut',
'filter' => [
'draft' => 'Brouillon',
'valid' => 'Valide',
],
'format' => 'raw',
'value' => function($model) {
return $model->getHtmlLabel() ;
}
],
[
'attribute' => 'reference',
'value' => function($model) {
if(strlen($model->reference) > 0) {
return $model->reference ;
}
return '' ;
}
],
'name',
[
'attribute' => 'username',
'header' => 'Utilisateur',
'value' => function($model) {
return $model->user->getUsername() ;
}
],
[
'attribute' => 'date',
'header' => 'Date',
'value' => function($model) {
return date('d/m/Y',strtotime($model->date)) ;
}
],
[
'attribute' => 'amount',
'header' => 'Montant',
'value' => function($invoice) {
return $invoice->getAmountWithTax(Order::INVOICE_AMOUNT_TOTAL, true) ;
}
],
[
'attribute' => 'is_sent',
'header' => 'Envoyé',
'format' => 'raw',
'value' => function($model) {
if($model->is_sent) {
return '<span class="label label-success">Oui</span>';
}
else {
return '<span class="label label-danger">Non</span>';
}
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{validate} {update} {delete} {send} {download} {export-csv-evoliz}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'validate' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'title' => 'Valider', 'class' => 'btn btn-default'
]) : '');
},
'send' => function($url, $model) {
return ((isset($model->user) && strlen($model->user->email) > 0) ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'title' => 'Envoyer', 'class' => 'btn btn-default'
]) : '');
},
'download' => function($url, $model) {
return Html::a('<span class="glyphicon glyphicon-download-alt"></span>', $url, [
'title' => 'Télécharger', 'class' => 'btn btn-default'
]);
},
'export-csv-evoliz' => function($url, $model) {
if(ProducerModel::getConfig('option_export_evoliz')) {
return Html::a('<span class="glyphicon glyphicon-save-file"></span> Evoliz', $url, [
'title' => 'Export CSV Evoliz', 'class' => 'btn btn-default'
]);
}
<?php if (Invoice::searchCount()): ?>
<?= GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'status',
'label' => 'Statut',
'filter' => [
'draft' => 'Brouillon',
'valid' => 'Valide',
],
'format' => 'raw',
'value' => function ($invoice) use ($invoiceManager) {
return $invoiceManager->getHtmlLabel($invoice);
}
],
[
'attribute' => 'reference',
'value' => function ($invoice) {
return (strlen($invoice->reference) > 0) ? $invoice->reference : '';
}
],
'name',
[
'attribute' => 'username',
'header' => 'Utilisateur',
'value' => function ($invoice) use ($userManager) {
return $userManager->getUsername($invoice->user);
}
],
[
'attribute' => 'date',
'header' => 'Date',
'value' => function ($invoice) {
return date('d/m/Y', strtotime($invoice->date));
}
],
[
'attribute' => 'amount',
'header' => 'Montant',
'value' => function ($invoice) use ($invoiceManager) {
return $invoiceManager->getAmountWithTax($invoice, Order::INVOICE_AMOUNT_TOTAL, true);
}
],
[
'attribute' => 'is_sent',
'header' => 'Envoyé',
'format' => 'raw',
'value' => function ($model) {
if ($model->is_sent) {
return '<span class="label label-success">Oui</span>';
} else {
return '<span class="label label-danger">Non</span>';
}
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{validate} {update} {delete} {send} {download} {export-csv-evoliz}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'validate' => function ($url, $invoice) use ($invoiceManager) {
return ($invoiceManager->isStatusDraft($invoice) ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'title' => 'Valider', 'class' => 'btn btn-default'
]) : '');
},
'send' => function ($url, $invoice) {
return ((isset($invoice->user) && strlen($invoice->user->email) > 0) ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'title' => 'Envoyer', 'class' => 'btn btn-default'
]) : '');
},
'download' => function ($url, $invoice) {
return Html::a('<span class="glyphicon glyphicon-download-alt"></span>', $url, [
'title' => 'Télécharger', 'class' => 'btn btn-default'
]);
},
'export-csv-evoliz' => function ($url, $invoice) use ($producerManager) {
if ($producerManager->getConfig('option_export_evoliz')) {
return Html::a('<span class="glyphicon glyphicon-save-file"></span> Evoliz', $url, [
'title' => 'Export CSV Evoliz', 'class' => 'btn btn-default'
]);
}

return '';
},
'update' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => 'Modifier', 'class' => 'btn btn-default'
]);
},
'delete' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => 'Supprimer', 'class' => 'btn btn-default'
]) : '');
}
],
],
],
]); ?>
<?php else: ?>
<div class="alert alert-info">Aucune facture enregistrée</div>
<?php endif; ?>
return '';
},
'update' => function ($url, $invoice) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => 'Modifier', 'class' => 'btn btn-default'
]);
},
'delete' => function ($url, $invoice) use ($invoiceManager) {
return ($invoiceManager->isStatusDraft($invoice) ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => 'Supprimer', 'class' => 'btn btn-default'
]) : '');
}
],
],
],
]); ?>
<?php else: ?>
<div class="alert alert-info">Aucune facture enregistrée</div>
<?php endif; ?>
</div>

+ 0
- 296
backend/views/layouts/main-old.php Просмотреть файл

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

/**
* Copyright distrib (2018)
*
* contact@opendistrib.net
*
* Ce logiciel est un programme informatique servant à aider les producteurs
* à distribuer leur production en circuits courts.
*
* Ce logiciel est régi par la licence CeCILL soumise au droit français et
* respectant les principes de diffusion des logiciels libres. Vous pouvez
* utiliser, modifier et/ou redistribuer ce programme sous les conditions
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
* sur le site "http://www.cecill.info".
*
* En contrepartie de l'accessibilité au code source et des droits de copie,
* de modification et de redistribution accordés par cette licence, il n'est
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
* seule une responsabilité restreinte pèse sur l'auteur du programme, le
* titulaire des droits patrimoniaux et les concédants successifs.
*
* A cet égard l'attention de l'utilisateur est attirée sur les risques
* associés au chargement, à l'utilisation, à la modification et/ou au
* développement et à la reproduction du logiciel par l'utilisateur étant
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à
* manipuler et qui le réserve donc à des développeurs et des professionnels
* avertis possédant des connaissances informatiques approfondies. Les
* utilisateurs sont donc invités à charger et tester l'adéquation du
* logiciel à leurs besoins dans des conditions permettant d'assurer la
* sécurité de leurs systèmes et ou de leurs données et, plus généralement,
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
*
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
* pris connaissance de la licence CeCILL, et que vous en avez accepté les
* termes.
*/

use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use common\helpers\Url;
use common\helpers\GlobalParam;

/* @var $this \yii\web\View */
/* @var $content string */

\common\assets\CommonAsset::register($this);
\backend\assets\AppAsset::register($this);

$producer = null;
if (!Yii::$app->user->isGuest) {
$producer = Producer::findOne(GlobalParam::getCurrentProducerId());
}

?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="baseurl" content="<?= Yii::$app->urlManagerBackend->baseUrl; ?>">
<meta name="baseurl-absolute"
content="<?= Yii::$app->urlManagerBackend->getHostInfo() . Yii::$app->urlManagerBackend->baseUrl; ?>">
<link rel="icon" type="image/png" href="<?php echo Yii::$app->urlManager->getBaseUrl(); ?>/img/favicon3.png"/>
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?> - distrib</title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => '<img class="logo" src="' . Yii::$app->urlManager->getBaseUrl() . '/img/laboulange3.png" />',
'brandUrl' => Yii::$app->homeUrl,
'innerContainerOptions' => ['class' => 'container-fluid'],
'options' => [
'class' => 'navbar-inverse navbar-fixed-top nav-header',
],
]);

$menuItems = [
[
'label' => '<span class="glyphicon glyphicon-home"></span> Tableau de bord',
'url' => ['/site/index'],
'visible' => !Yii::$app->user->isGuest
],
[
'label' => '<span class="glyphicon glyphicon-calendar"></span> Commandes',
'url' => ['/order/index'],
'visible' => !Yii::$app->user->isGuest,
'items' => [
[
'label' => '<span class="glyphicon glyphicon-calendar"></span> Toutes les commandes',
'url' => ['/order/index'],
'visible' => !Yii::$app->user->isGuest
],
[
'label' => '<span class="glyphicon glyphicon-repeat"></span> Abonnements',
'url' => ['/subscription/index'],
'visible' => !Yii::$app->user->isGuest
],
]
],
[
'label' => '<span class="glyphicon glyphicon-grain"></span> Produits',
'url' => ['/product/index'],
'visible' => !Yii::$app->user->isGuest
],
[
'label' => '<span class="glyphicon glyphicon-map-marker"></span> Points de vente',
'url' => ['/point-sale/index'],
'visible' => !Yii::$app->user->isGuest
],
[
'label' => '<span class="glyphicon glyphicon-user"></span> Clients',
'url' => ['/user/index'],
'visible' => !Yii::$app->user->isGuest
],
[
'label' => '<span class="glyphicon glyphicon-plus"></span>',
'url' => ['/producer/update'],
'visible' => !Yii::$app->user->isGuest,
'items' => [
[
'label' => '<span class="glyphicon glyphicon-cog"></span> Paramètres',
'url' => ['/producer/update'],
'visible' => !Yii::$app->user->isGuest
],
[
'label' => '<span class="glyphicon glyphicon-bullhorn"></span> Communiquer',
'url' => ['/communicate/index'],
'visible' => !Yii::$app->user->isGuest
],
[
'label' => '<span class="glyphicon glyphicon-euro"></span> Mon abonnement',
'url' => ['/producer/billing'],
'visible' => !Yii::$app->user->isGuest,
],
[
'label' => '<span class="glyphicon glyphicon-stats"></span> Statistiques',
'url' => ['/stats/index'],
'visible' => !Yii::$app->user->isGuest,
],
[
'label' => '<span class="glyphicon glyphicon-stats"></span> Statistiques produits',
'url' => ['/stats/products'],
'visible' => !Yii::$app->user->isGuest,
],
[
'label' => '<span class="glyphicon glyphicon-wrench"></span> Développement',
'url' => ['/development/index'],
'visible' => !Yii::$app->user->isGuest
],
],
]
];

if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Connexion', 'url' => ['/site/login']];
} else {

if (Yii::$app->user->identity->status == User::STATUS_ADMIN) {
$menuItems[] = [
'label' => '<span class="glyphicon glyphicon-asterisk"></span>',
'url' => '#',
'items' => [
[
'label' => '<span class="glyphicon glyphicon-th-list"></span> Producteurs',
'url' => ['producer-admin/index'],
'visible' => !Yii::$app->user->isGuest,
],
[
'label' => '<span class="glyphicon glyphicon-euro"></span> Facturation',
'url' => ['producer-admin/billing'],
'visible' => false,
],
]
];
}

$menuItems[] = [
'label' => '<span class="glyphicon glyphicon-off"></span>',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post', 'title' => 'Déconnexion']
];

$menuItems[] = [
'label' => '<span class="retour-site">Retour sur le site</span>',
'url' => Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]),
];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
'encodeLabels' => false
]);
NavBar::end();
?>

<div class="container-fluid container-body">
<?php if (YII_ENV == 'dev' || YII_ENV == 'demo'): ?>
<div id="env-dev"><?php if (YII_ENV == 'dev'): ?>Dév.<?php elseif (YII_ENV == 'demo'): ?>Démo<?php endif; ?></div>
<?php endif; ?>
<?php if (!Yii::$app->user->isGuest): ?>
<div class="name-producer">
<?php if ( User::getCurrentStatus() == User::STATUS_PRODUCER): ?>
<span><?= Html::encode(Yii::$app->user->identity->getNameProducer()); ?></span>
<?php elseif ( User::getCurrentStatus() == User::STATUS_ADMIN): ?>
<?php $form = ActiveForm::begin(['id' => 'select-producer']); ?>
<?=
Html::dropDownList('select_producer', GlobalParam::getCurrentProducerId(), ArrayHelper::map(ProducerModel::find()->orderBy('name ASC')->all(), 'id', function ($model, $defaultValue) {
return $model->name;
}));
?>
<?php ActiveForm::end(); ?>
<?php endif; ?>

<?php
$producer = Producer::findOne(GlobalParam::getCurrentProducerId());
if (!$producer->active):
?>
<span class="label label-danger" data-toggle="tooltip" data-placement="bottom"
data-original-title="Activez votre établissement quand vous le souhaitez afin de la rendre visible à vos clients.">
<?= Html::a('Hors-ligne', ['producer/update']); ?>
</span>
<?php endif; ?>

<div class="clr"></div>
</div>
<?php endif; ?>

<?php if (YII_ENV == 'demo'): ?>
<div id="block-demo">
<div class="container-fluid">
<span class="glyphicon glyphicon-eye-open"></span> <strong>Espace de démonstration</strong> :
Testez la plateforme sans avoir à vous inscrire. Les données sont réinitialisées quotidiennement
&bull; <?= Html::a('Retour', Url::env('prod', 'frontend')) ?>
</div>
</div>
<?php endif; ?>

<?=
Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
])
?>
<?= $content ?>
</div>
</div>

<div id="alerts-fixed"></div>

<footer class="footer">
<div class="container-fluid">
<p class="pull-left">
<a href="<?php echo Url::frontend('site/contact'); ?>">Contact</a> &bull;
<a href="<?php echo Url::frontend('site/mentions'); ?>">Mentions légales</a> &bull;
<a href="<?php echo Url::frontend('site/cgv'); ?>">CGS</a>
<a id="code-source" href="https://framagit.org/guillaume-bourgeois/laboiteapain">Code source <img
src="<?php echo Yii::$app->urlManager->getBaseUrl(); ?>/img/logo-framagit.png"
alt="Hébergé par Framasoft"/> <img
src="<?php echo Yii::$app->urlManager->getBaseUrl(); ?>/img/logo-gitlab.png"
alt="Propulsé par Gitlab"/></a>
</p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
</footer>

<?php $this->endBody() ?>

<!-- analytics -->
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');

ga('create', 'UA-86917043-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>
<?php $this->endPage() ?>

+ 3
- 2
backend/views/producer-admin/_form.php Просмотреть файл

@@ -38,6 +38,7 @@ termes.

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\logic\Producer\Producer\Model\Producer;

?>

@@ -52,9 +53,9 @@ use yii\widgets\ActiveForm;

<h3>Facturation</h3>
<?= $form->field($model, 'option_billing_type')
->dropDownList(ProducerModel::getBillingTypePopulateDropdown()); ?>
->dropDownList(Producer::getBillingTypePopulateDropdown()); ?>
<?= $form->field($model, 'option_billing_frequency')
->dropDownList(ProducerModel::getBillingFrequencyPopulateDropdown()); ?>
->dropDownList(Producer::getBillingFrequencyPopulateDropdown()); ?>
<?= $form->field($model, 'option_billing_reduction')
->dropDownList([
0 => 'Non',

+ 16
- 12
backend/views/producer-admin/index.php Просмотреть файл

@@ -38,6 +38,11 @@ termes.

use yii\helpers\Html;
use yii\grid\GridView;
use common\logic\User\User\Model\User;
use common\logic\Producer\Producer\Model\Producer;
use common\helpers\Price;

$producerManager = $this->getProducerManager();

$this->setTitle('Producteurs') ;
$this->addBreadcrumb($this->getTitle()) ;
@@ -155,24 +160,23 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico
'attribute' => 'À facturer / chiffre d\'affaire',
'label' => 'À facturer / chiffre d\'affaire',
'format' => 'raw',
'value' => function($model) {
'value' => function($producer) use ($producerManager) {

$str = '';

if($model->isBillingFrequencyMonthly()) {
$str .= $model->getSummaryAmountsToBeBilled('Mois dernier', 1);
if($producerManager->isBillingFrequencyMonthly($producer)) {
$str .= $producerManager->getSummaryAmountsToBeBilled($producer, 'Mois dernier', 1);
}
elseif($model->isBillingFrequencyQuarterly()) {
$str .= $model->getSummaryAmountsToBeBilled('3 derniers mois', 3);
elseif($producerManager->isBillingFrequencyQuarterly($producer)) {
$str .= $producerManager->getSummaryAmountsToBeBilled($producer, '3 derniers mois', 3);
}
elseif($model->isBillingFrequencyBiannual()) {
$str .= $model->getSummaryAmountsToBeBilled('6 derniers mois', 6);
elseif($producerManager->isBillingFrequencyBiannual($producer)) {
$str .= $producerManager->getSummaryAmountsToBeBilled($producer, '6 derniers mois', 6);
}

if($model->option_billing_reduction && strlen($str)) {
if($producer->option_billing_reduction && strlen($str)) {
$str .= '<br /><u>Avec réduction</u> : ';
if($model->option_billing_reduction_percentage) {
$str .= ' '.$model->option_billing_reduction_percentage.'&nbsp;%';
if($producer->option_billing_reduction_percentage) {
$str .= ' '.$producer->option_billing_reduction_percentage.'&nbsp;%';
}
}

@@ -185,7 +189,7 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico
'format' => 'raw',
'value' => function($model) {
$str = '<ul style="margin: 0px;padding-left: 15px;">';
$str .= '<li>'.ProducerModel::$billingFrequencyArray[$model->option_billing_frequency].'</li>';
$str .= '<li>'.Producer::$billingFrequencyArray[$model->option_billing_frequency].'</li>';

if($model->option_billing_permanent_transfer) {
$str .= '<li>Virement permanent : <strong>'.Price::format($model->option_billing_permanent_transfer_amount, 0).'</strong></li>';

+ 8
- 5
backend/views/producer/billing.php Просмотреть файл

@@ -36,6 +36,9 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

$producerManager = $this->getProducerManager();
$producerPriceRangeManager = $this->getProducerPriceRangeManager();

$this->setTitle('Tarifs') ;
$this->addBreadcrumb($this->getTitle()) ;

@@ -43,19 +46,19 @@ $this->addBreadcrumb($this->getTitle()) ;

<?php

if($producer->isBillingTypeFreePrice()) {
if($producerManager->isBillingTypeFreePrice($producer)) {
echo '<div class="alert alert-info">';
echo "Vous bénéficiez actuellement d'un abonnement à prix libre dont voici le montant : <strong>".$producer->getFreePrice()."</strong>";
echo '</div>';
}
elseif($producer->isBillingTypeClassic()) {
elseif($producerManager->isBillingTypeClassic($producer)) {
$month = date('Y-m', strtotime('-1 month'));
$turnover = $producer->getTurnover($month);
$amountBilledLastMonth = $producer->getAmountToBeBilledByTurnover($turnover);
$turnover = $producerManager->getTurnover($producer, $month);
$amountBilledLastMonth = $producerPriceRangeManager->getAmountToBeBilledByTurnover($turnover);

if($amountBilledLastMonth) {
echo '<div class="alert alert-info">';
echo "À titre d'information, voici le tarif retenu pour le mois dernier (".strftime('%B', strtotime('-1 month')).") : <strong>".$producer->getAmountToBeBilledByMonth($month, true)."</strong>";
echo "À titre d'information, voici le tarif retenu pour le mois dernier (".strftime('%B', strtotime('-1 month')).") : <strong>".$producerManager->getAmountToBeBilledByMonth($producer, $month, true)."</strong>";
echo "<br />Le chiffre d'affaire pris en compte pour ce calcul est : <strong>".Price::format($turnover)." HT</strong>";
echo '<br /><a href="'.Yii::$app->urlManager->createUrl(['stats/index']).'">Voir l\'évolution de mon chiffre d\'affaire</a>';
echo '</div>';

+ 12
- 7
backend/views/producer/update.php Просмотреть файл

@@ -38,9 +38,14 @@

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\Config\TaxRate\Model\TaxRate;
use common\logic\Document\Document\Model\Document;
use yii\helpers\ArrayHelper;

\backend\assets\VuejsProducerUpdateAsset::register($this);
$userManager = $this->getUserManager();

\backend\assets\VuejsProducerUpdateAsset::register($this);
$this->setTitle('Paramètres');
$this->addBreadcrumb($this->getTitle());

@@ -48,7 +53,7 @@ $this->addBreadcrumb($this->getTitle());

<script>
var appInitValues = {
isAdmin: <?= (int) User::isCurrentAdmin() ?>
isAdmin: <?= (int) $userManager->isCurrentAdmin() ?>
};
</script>

@@ -349,10 +354,10 @@ $this->addBreadcrumb($this->getTitle());

<?= $form->field($model, 'credit_functioning')
->dropDownList([
Producer::CREDIT_FUNCTIONING_OPTIONAL => Producer::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_OPTIONAL],
Producer::CREDIT_FUNCTIONING_MANDATORY => Producer::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_MANDATORY],
Producer::CREDIT_FUNCTIONING_USER => Producer::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_USER],
], [])->hint(ProducerModel::HINT_CREDIT_FUNCTIONING); ?>
Producer::CREDIT_FUNCTIONING_OPTIONAL => Producer::$creditFunctioningArray[Producer::CREDIT_FUNCTIONING_OPTIONAL],
Producer::CREDIT_FUNCTIONING_MANDATORY => Producer::$creditFunctioningArray[Producer::CREDIT_FUNCTIONING_MANDATORY],
Producer::CREDIT_FUNCTIONING_USER => Producer::$creditFunctioningArray[Producer::CREDIT_FUNCTIONING_USER],
], [])->hint(Producer::HINT_CREDIT_FUNCTIONING); ?>

<?= $form->field($model, 'use_credit_checked_default')
->dropDownList([
@@ -379,7 +384,7 @@ $this->addBreadcrumb($this->getTitle());
1 => 'Oui',
], []); ?>
<?= $form->field($model, 'option_online_payment_minimum_amount')
->hint('Valeur par défaut si non défini : '.ProducerModel::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT.' €')
->hint('Valeur par défaut si non défini : '.Producer::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT.' €')
->textInput(); ?>
<?= $form->field($model, 'option_stripe_mode_test')->dropDownList([
0 => 'Non',

+ 96
- 91
backend/views/quotation/index.php Просмотреть файл

@@ -36,6 +36,14 @@
* termes.
*/

use common\logic\Document\Quotation\Model\Quotation;
use yii\grid\GridView;
use common\logic\Order\Order\Model\Order;
use yii\helpers\Html;

$quotationManager = $this->getQuotationManager();
$userManager = $this->getUserManager();

$this->setTitle('Devis');
$this->addBreadcrumb($this->getTitle());
$this->addButton(['label' => 'Nouveau devis <span class="glyphicon glyphicon-plus"></span>', 'url' => 'quotation/create', 'class' => 'btn btn-primary']);
@@ -43,95 +51,92 @@ $this->addButton(['label' => 'Nouveau devis <span class="glyphicon glyphicon-plu
?>

<div class="quotation-index">
<?php if(Quotation::searchCount()): ?>
<?= GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'status',
'label' => 'Statut',
'filter' => [
'draft' => 'Brouillon',
'valid' => 'Valide',
],
'format' => 'raw',
'value' => function($model) {
return $model->getHtmlLabel() ;
}
],
[
'attribute' => 'reference',
'value' => function($model) {
if(strlen($model->reference) > 0) {
return $model->reference ;
}
return '' ;
}
],
'name',
[
'attribute' => 'id_user',
'header' => 'Utilisateur',
'value' => function($model) {
return $model->user->getUsername() ;
}
],
[
'attribute' => 'date',
'header' => 'Date',
'value' => function($model) {
return date('d/m/Y',strtotime($model->date)) ;
}
],
[
'attribute' => 'amount',
'header' => 'Montant',
'value' => function($invoice) {
return $invoice->getAmountWithTax(Order::AMOUNT_TOTAL, true) ;
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{transform} {validate} {update} {delete} {send} {download}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'transform' => function ($url, $model) {
return ($model->isStatusValid() ? Html::a('<span class="glyphicon glyphicon-check"></span>', $url, [
'title' => 'Transformer en facture', 'class' => 'btn btn-default'
]) : '');
},
'validate' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'title' => 'Valider', 'class' => 'btn btn-default'
]) : '');
},
'send' => function($url, $model) {
return ((isset($model->user) && strlen($model->user->email) > 0) ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'title' => 'Envoyer', 'class' => 'btn btn-default'
]) : '');
},
'download' => function($url, $model) {
return Html::a('<span class="glyphicon glyphicon-download-alt"></span>', $url, [
'title' => 'Télécharger', 'class' => 'btn btn-default'
]);
},
'update' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => 'Modifier', 'class' => 'btn btn-default'
]) : '');
},
'delete' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => 'Supprimer', 'class' => 'btn btn-default'
]) : '');
}
],
],
],
]); ?>
<?php else: ?>
<div class="alert alert-info">Aucun devis enregistré</div>
<?php endif; ?>
<?php if (Quotation::searchCount()): ?>
<?= GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'status',
'label' => 'Statut',
'filter' => [
'draft' => 'Brouillon',
'valid' => 'Valide',
],
'format' => 'raw',
'value' => function ($quotation) use ($quotationManager) {
return $quotationManager->getHtmlLabel($quotation);
}
],
[
'attribute' => 'reference',
'value' => function ($model) {
return (strlen($model->reference) > 0) ? $model->reference : '';
}
],
'name',
[
'attribute' => 'id_user',
'header' => 'Utilisateur',
'value' => function ($quotation) use ($userManager) {
return $userManager->getUsername($quotation->user);
}
],
[
'attribute' => 'date',
'header' => 'Date',
'value' => function ($quotation) {
return date('d/m/Y', strtotime($quotation->date));
}
],
[
'attribute' => 'amount',
'header' => 'Montant',
'value' => function ($quotation) use ($quotationManager) {
return $quotationManager->getAmountWithTax($quotation, Order::AMOUNT_TOTAL, true);
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{transform} {validate} {update} {delete} {send} {download}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'transform' => function ($url, $quotation) use ($quotationManager) {
return ($quotationManager->isStatusValid($quotation) ? Html::a('<span class="glyphicon glyphicon-check"></span>', $url, [
'title' => 'Transformer en facture', 'class' => 'btn btn-default'
]) : '');
},
'validate' => function ($url, $quotation) use ($quotationManager) {
return ($quotationManager->isStatusValid($quotation) ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'title' => 'Valider', 'class' => 'btn btn-default'
]) : '');
},
'send' => function ($url, $quotation) {
return ((isset($quotation->user) && strlen($quotation->user->email) > 0) ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'title' => 'Envoyer', 'class' => 'btn btn-default'
]) : '');
},
'download' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-download-alt"></span>', $url, [
'title' => 'Télécharger', 'class' => 'btn btn-default'
]);
},
'update' => function ($url, $quotation) use ($quotationManager) {
return ($quotationManager->isStatusDraft($quotation) ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => 'Modifier', 'class' => 'btn btn-default'
]) : '');
},
'delete' => function ($url, $quotation) use ($quotationManager) {
return ($quotationManager->isStatusDraft($quotation) ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => 'Supprimer', 'class' => 'btn btn-default'
]) : '');
}
],
],
],
]); ?>
<?php else: ?>
<div class="alert alert-info">Aucun devis enregistré</div>
<?php endif; ?>
</div>

+ 4
- 1
backend/views/subscription/index.php Просмотреть файл

@@ -106,7 +106,10 @@ $subscriptionsArray = Subscription::searchAll() ;
'format' => 'raw',
'filter' => ArrayHelper::map(PointSale::find()->where(['id_producer' => GlobalParam::getCurrentProducerId()])->asArray()->all(), 'id', 'name'),
'value' => function($model) {
return Html::encode($model->pointSale->name) ;
if($model->pointSale) {
return Html::encode($model->pointSale->name) ;
}
return '';
}
],
[

+ 6
- 3
backend/views/user/_form.php Просмотреть файл

@@ -38,10 +38,13 @@

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\ProductPrice ;
use yii\helpers\ArrayHelper;

\backend\assets\VuejsUserFormAsset::register($this);

$userManager = $this->getUserManager();
$producerManager = $this->getProducerManager();

?>

<div class="user-form" id="app-user-form">
@@ -52,7 +55,7 @@ use common\models\ProductPrice ;
]); ?>

<?= $form->field($model, 'type')
->dropDownList( User::getTypeChoicesArray(), [
->dropDownList( $userManager->getTypeChoicesArray(), [
'v-model' => 'type'
]) ; ?>
<?= $form->field($model, 'name_legal_person', ['options' => ['v-show' => "type == 'legal-person'"]])->textInput() ?>
@@ -62,7 +65,7 @@ use common\models\ProductPrice ;
<?= $form->field($model, 'email')->textInput() ?>
<?= $form->field($model, 'address')->textarea() ?>

<?php if(ProducerModel::getConfig('option_export_evoliz')): ?>
<?php if($producerManager->getConfig('option_export_evoliz')): ?>
<?= $form->field($model, 'evoliz_code')->textInput() ?>
<?php endif; ?>


+ 6
- 4
backend/views/user/credit.php Просмотреть файл

@@ -39,8 +39,12 @@ termes.
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\helpers\GlobalParam;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\helpers\MeanPayment;

$creditHistoryManager = $this->getCreditHistoryManager();
$producerManager = $this->getProducerManager();
$userManager = $this->getUserManager();

$this->setTitle('Créditer <small>'.Html::encode($user->lastname.' '.$user->name).'</small>', 'Créditer '.Html::encode($user->lastname.' '.$user->name)) ;
$this->addBreadcrumb(['label' => 'Utilisateurs', 'url' => ['index']]) ;
@@ -52,9 +56,7 @@ $this->addBreadcrumb('Créditer') ;
<div class="user-credit">
<?php
$producer = Producer::searchOne([
'id' => GlobalParam::getCurrentProducerId()
]);
$producer = $producerManager->findOneProducerById(GlobalParam::getCurrentProducerId());
if(!$producer->credit)
{
@@ -110,7 +112,7 @@ $this->addBreadcrumb('Créditer') ;
</div>
<div class="col-md-8">
<h2>Historique <span class="the-credit"><?= number_format($user->getCredit($producer->id), 2); ?> €</span></h2>
<h2>Historique <span class="the-credit"><?= number_format($userManager->getCredit($user, $producer), 2); ?> €</span></h2>
<table class="table table-bordered">
<thead>
<tr>

+ 16
- 12
backend/views/user/orders.php Просмотреть файл

@@ -37,8 +37,12 @@
*/

use yii\grid\GridView;
use yii\helpers\Html;

$this->setTitle('Commandes <small>' . Html::encode($user->getUsername()) . '</small>', 'Commandes de ' . Html::encode($user->getUsername()));
$userManager = $this->getUserManager();
$orderManager = $this->getOrderManager();

$this->setTitle('Commandes <small>' . Html::encode($userManager->getUsername($user)) . '</small>', 'Commandes de ' . Html::encode($userManager->getUsername($user)));
$this->addBreadcrumb(['label' => 'Utilisateurs', 'url' => ['index']]);
$this->addBreadcrumb(['label' => Html::encode($user->lastname . ' ' . $user->name)]);
$this->addBreadcrumb('Commandes');
@@ -53,37 +57,37 @@ $this->addBreadcrumb('Commandes');
[
'attribute' => 'distribution.date',
'label' => 'Date de livraison',
'value' => function ($model) {
return date('d/m/Y',strtotime($model->distribution->date));
'value' => function ($user) {
return date('d/m/Y',strtotime($user->distribution->date));
}
],
[
'label' => 'Historique',
'format' => 'raw',
'value' => function ($model) {
return $model->getStrHistory();
'value' => function ($order) use ($orderManager) {
return $orderManager->getHistorySummary($order);
}
],
[
'label' => 'Résumé',
'format' => 'raw',
'value' => function ($model) {
return $model->getCartSummary();
'value' => function ($order) use ($orderManager) {
return $orderManager->getCartSummary($order);
}
],
[
'label' => 'Point de vente',
'format' => 'raw',
'value' => function ($model) {
return $model->getPointSaleSummary();
'value' => function ($order) use ($orderManager) {
return $orderManager->getPointSaleSummary($order);
}
],
[
'label' => 'Montant',
'format' => 'raw',
'value' => function ($model) {
$model->init();
return $model->getAmountSummary();
'value' => function ($order) use ($orderManager) {
$orderManager->initOrder($order);
return $orderManager->getAmountSummary($order);
}
],
[

+ 1
- 1
common/components/BusinessLogicTrait.php Просмотреть файл

@@ -17,7 +17,7 @@ use common\logic\Document\Document\Wrapper\DocumentManager;
use common\logic\Document\Invoice\Wrapper\InvoiceContainer;
use common\logic\Document\Invoice\Wrapper\InvoiceManager;
use common\logic\Document\Quotation\Wrapper\QuotationContainer;
use common\logic\Document\Invoice\Wrapper\QuotationManager;
use common\logic\Document\Quotation\Wrapper\QuotationManager;
use common\logic\Order\Order\Wrapper\OrderContainer;
use common\logic\Order\Order\Wrapper\OrderManager;
use common\logic\Order\OrderStatusHistory\Wrapper\OrderStatusHistoryContainer;

+ 1
- 3
common/logic/Distribution/Distribution/Service/DistributionSolver.php Просмотреть файл

@@ -51,6 +51,7 @@ class DistributionSolver extends AbstractService implements SolverInterface
// isAvailable
public function isDistributionAvailable(Distribution $distribution): bool
{
$dateToday = date('Y-m-d');
$producer = $distribution->producer;
$dateDistribution = $distribution->date;
$dayDistribution = strtolower(date('l', strtotime($dateDistribution)));
@@ -86,9 +87,6 @@ class DistributionSolver extends AbstractService implements SolverInterface
*/
public function filterDistributionsByDateDelay(array $distributionsArray): array
{
$producer = GlobalParam::getCurrentProducer();
$dateToday = date('Y-m-d');

foreach ($distributionsArray as $keyDistribution => $distribution) {
if(!$this->isDistributionAvailable($distribution)) {
unset($distributionsArray[$keyDistribution]);

+ 12
- 5
common/logic/Document/DeliveryNote/Wrapper/DeliveryNoteContainer.php Просмотреть файл

@@ -4,6 +4,7 @@ namespace common\logic\Document\DeliveryNote\Wrapper;

use common\logic\AbstractContainer;
use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Document\DeliveryNote\Repository\DeliveryNoteRepository;
use common\logic\Document\DeliveryNote\Service\DeliveryNoteBuilder;
use common\logic\Document\DeliveryNote\Service\DeliveryNoteSolver;

@@ -17,18 +18,24 @@ class DeliveryNoteContainer extends AbstractContainer
public function getServices(): array
{
return [
DeliveryNoteBuilder::class,
DeliveryNoteSolver::class,
DeliveryNoteRepository::class,
DeliveryNoteBuilder::class,
];
}

public function getBuilder(): DeliveryNoteBuilder
public function getSolver(): DeliveryNoteSolver
{
return DeliveryNoteBuilder::getInstance();
return DeliveryNoteSolver::getInstance();
}

public function getSolver(): DeliveryNoteSolver
public function getRepository(): DeliveryNoteRepository
{
return DeliveryNoteSolver::getInstance();
return DeliveryNoteRepository::getInstance();
}

public function getBuilder(): DeliveryNoteBuilder
{
return DeliveryNoteBuilder::getInstance();
}
}

+ 44
- 0
common/logic/Document/Document/Repository/DocumentRepository.php Просмотреть файл

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

namespace common\logic\Document\Document\Repository;

use common\logic\AbstractRepository;
use common\logic\Document\DeliveryNote\Repository\DeliveryNoteRepository;
use common\logic\Document\Invoice\Repository\InvoiceRepository;
use common\logic\Document\Quotation\Repository\QuotationRepository;

class DocumentRepository extends AbstractRepository
{
protected DeliveryNoteRepository $deliveryNoteRepository;
protected InvoiceRepository $invoiceRepository;
protected QuotationRepository $quotationRepository;

public function loadDependencies(): void
{
$this->deliveryNoteRepository = $this->loadService(DeliveryNoteRepository::class);
$this->invoiceRepository = $this->loadService(InvoiceRepository::class);
$this->quotationRepository = $this->loadService(QuotationRepository::class);
}

public function getDefaultOptionsSearch(): array
{
return [];
}

public function findOneDocumentByIdAndClass($idDocument, $classDocument)
{
$model = null;

if($classDocument == 'DeliveryNote') {
$model = $this->deliveryNoteRepository->findOneDeliveryNoteById($idDocument);
}
elseif($classDocument == 'Quotation') {
$model = $this->quotationRepository->findOneQuotationById($idDocument);
}
elseif($classDocument == 'Invoice') {
$model = $this->invoiceRepository->findOneInvoiceById($idDocument);
}

return $model;
}
}

+ 5
- 1
common/logic/Document/Document/Service/DocumentBuilder.php Просмотреть файл

@@ -5,29 +5,33 @@ namespace common\logic\Document\Document\Service;
use common\logic\AbstractBuilder;
use common\logic\Document\Document\Model\Document;
use common\logic\Document\Document\Model\DocumentInterface;
use common\logic\Document\Document\Repository\DocumentRepository;
use common\logic\Producer\Producer\Repository\ProducerRepository;

class DocumentBuilder extends AbstractBuilder
{
protected DocumentSolver $documentSolver;
protected DocumentRepository $documentRepository;
protected ProducerRepository $producerRepository;

public function loadDependencies(): void
{
$this->documentSolver = $this->loadService(DocumentSolver::class);
$this->documentRepository = $this->loadService(DocumentRepository::class);
$this->producerRepository = $this->loadService(ProducerRepository::class);
}

public function generateReference(DocumentInterface $document): void
{
$class = $this->documentSolver->getClass($document);
$classComplete = $this->documentSolver->getClass($document, true);
$classLower = strtolower($class);
if ($classLower == 'deliverynote') {
$classLower = 'delivery_note';
}

$prefix = $this->producerRepository->getConfig('document_' . $classLower . '_prefix');
$oneDocumentExist = $class::searchOne(['status' => Document::STATUS_VALID], ['orderby' => 'reference DESC']);
$oneDocumentExist = $classComplete::searchOne(['status' => Document::STATUS_VALID], ['orderby' => 'reference DESC']);

if ($oneDocumentExist) {
$referenceDocument = $oneDocumentExist->reference;

+ 16
- 4
common/logic/Document/Document/Service/DocumentSolver.php Просмотреть файл

@@ -72,7 +72,7 @@ class DocumentSolver extends AbstractService implements SolverInterface
}

$totalVatArray[$idTaxRate] += Price::getVat(
$productOrder->getPriceByTypeTotal($typeTotal) * $productOrder->quantity,
$this->productOrderSolver->getPriceByTypeTotal($productOrder, $typeTotal) * $productOrder->quantity,
$productOrder->taxRate->value,
$document->tax_calculation_method
);
@@ -100,9 +100,21 @@ class DocumentSolver extends AbstractService implements SolverInterface
return null;
}

public function getClass(DocumentInterface $document): string
public function getClass(DocumentInterface $document, bool $pathComplete = false): string
{
return str_replace('common\models\\', '', get_class($document));
$classDocument = get_class($document);

if(!$pathComplete) {
return str_replace(
[
'common\logic\Document\DeliveryNote\Model\\',
'common\logic\Document\Invoice\Model\\',
'common\logic\Document\Quotation\Model\\'],
'',
$classDocument);
}

return $classDocument;
}

public function getType(DocumentInterface $document): string
@@ -208,7 +220,7 @@ class DocumentSolver extends AbstractService implements SolverInterface

public function getFilename(DocumentInterface $document): string
{
$filename = $document->getType() . '-';
$filename = $this->getType($document) . '-';

if($this->isStatusValid($document)) {
$filename .= $document->reference;

+ 8
- 8
common/logic/Document/Document/Service/DocumentUtils.php Просмотреть файл

@@ -27,12 +27,12 @@ class DocumentUtils extends AbstractService implements UtilsInterface
$this->producerRepository = $this->loadService(ProducerRepository::class);
}

public function generatePdf(DocumentInterface $document, string $destination): string
public function generatePdf(DocumentInterface $document, string $destination): ?string
{
$producer = $document->producer;
$content = \Yii::$app->controller->renderPartial('/document/download', [
'producer' => $producer,
'document' => $this
'document' => $document
]);

$contentFooter = '<div id="footer">';
@@ -40,11 +40,11 @@ class DocumentUtils extends AbstractService implements UtilsInterface
if ($this->documentSolver->isStatusValid($document) || $this->documentSolver->isStatusDraft($document)) {
$contentFooter .= '<div class="reference-document">';
if ($this->documentSolver->isStatusValid($document)) {
$contentFooter .= $this->getType() . ' N°' . $document->reference;
$contentFooter .= $this->documentSolver->getType($document) . ' N°' . $document->reference;
}
if ($this->documentSolver->isStatusDraft($document)) {
$contentFooter .= $document->getType() . ' non validé';
if ($document->getType() == 'Facture') {
$contentFooter .= $this->documentSolver->getType($document) . ' non validé';
if ($this->documentSolver->getType($document) == 'Facture') {
$contentFooter .= 'e';
}
}
@@ -105,7 +105,7 @@ class DocumentUtils extends AbstractService implements UtilsInterface
if (isset($document->user) && strlen($document->user->email) > 0) {
$producer = GlobalParam::getCurrentProducer();

$subjectEmail = $document->getType();
$subjectEmail = $this->documentSolver->getType($document);
if ($this->documentSolver->isStatusValid($document)) {
$subjectEmail .= ' N°' . $document->reference;
}
@@ -115,10 +115,10 @@ class DocumentUtils extends AbstractService implements UtilsInterface
'html' => 'sendDocument-html',
'text' => 'sendDocument-text'
], [
'document' => $this,
'document' => $document
])
->setTo($document->user->email)
->setFrom([$producer->getEmailOpendistrib() => $producer->name])
->setFrom([$this->producerSolver->getEmailOpendistrib($producer) => $producer->name])
->setSubject('[' . $producer->name . '] ' . $subjectEmail);

$this->generatePdf($document, Pdf::DEST_FILE);

+ 7
- 0
common/logic/Document/Document/Wrapper/DocumentContainer.php Просмотреть файл

@@ -4,6 +4,7 @@ namespace common\logic\Document\Document\Wrapper;

use common\logic\AbstractContainer;
use common\logic\Document\Document\Model\Document;
use common\logic\Document\Document\Repository\DocumentRepository;
use common\logic\Document\Document\Service\DocumentBuilder;
use common\logic\Document\Document\Service\DocumentSolver;
use common\logic\Document\Document\Service\DocumentUtils;
@@ -19,6 +20,7 @@ class DocumentContainer extends AbstractContainer
{
return [
DocumentSolver::class,
DocumentRepository::class,
DocumentBuilder::class,
DocumentUtils::class,
];
@@ -29,6 +31,11 @@ class DocumentContainer extends AbstractContainer
return DocumentSolver::getInstance();
}

public function getRepository(): DocumentRepository
{
return DocumentRepository::getInstance();
}

public function getBuilder(): DocumentBuilder
{
return DocumentBuilder::getInstance();

+ 1
- 0
common/logic/Document/Invoice/Wrapper/InvoiceContainer.php Просмотреть файл

@@ -19,6 +19,7 @@ class InvoiceContainer extends AbstractContainer
{
return [
DocumentSolver::class,
InvoiceRepository::class,
InvoiceBuilder::class,
];
}

+ 1
- 1
common/logic/Document/Quotation/Model/QuotationSearch.php Просмотреть файл

@@ -39,7 +39,7 @@
namespace common\logic\Document\Quotation\Model;

use common\helpers\GlobalParam;
use common\logic\PointSale\PointSale\Repository\QuotationRepository;
use common\logic\Document\Quotation\Repository\QuotationRepository;
use yii\data\ActiveDataProvider;

class QuotationSearch extends Quotation

+ 7
- 2
common/logic/Document/Quotation/Repository/QuotationRepository.php Просмотреть файл

@@ -1,9 +1,9 @@
<?php

namespace common\logic\PointSale\PointSale\Repository;
namespace common\logic\Document\Quotation\Repository;

use common\logic\AbstractRepository;
use common\logic\Document\Quotation\Repository\QuotationRepositoryQuery;
use common\logic\Document\Quotation\Model\Quotation;

class QuotationRepository extends AbstractRepository
{
@@ -23,4 +23,9 @@ class QuotationRepository extends AbstractRepository
'attribute_id_producer' => 'quotation.id_producer'
];
}

public function findOneQuotationById(int $id): ?Quotation
{
return Quotation::searchOne(['id' => $id]);
}
}

+ 3
- 1
common/logic/Document/Quotation/Wrapper/QuotationContainer.php Просмотреть файл

@@ -5,8 +5,8 @@ namespace common\logic\Document\Quotation\Wrapper;
use common\logic\AbstractContainer;
use common\logic\Document\Document\Service\DocumentSolver;
use common\logic\Document\Quotation\Model\Quotation;
use common\logic\Document\Quotation\Repository\QuotationRepository;
use common\logic\Document\Quotation\Service\QuotationBuilder;
use common\logic\PointSale\PointSale\Repository\QuotationRepository;

class QuotationContainer extends AbstractContainer
{
@@ -18,6 +18,8 @@ class QuotationContainer extends AbstractContainer
public function getServices(): array
{
return [
DocumentSolver::class,
QuotationRepository::class,
QuotationBuilder::class,
];
}

+ 2
- 2
common/logic/Document/Quotation/Wrapper/QuotationManager.php Просмотреть файл

@@ -1,10 +1,10 @@
<?php

namespace common\logic\Document\Invoice\Wrapper;
namespace common\logic\Document\Quotation\Wrapper;

use common\logic\Document\Document\Wrapper\DocumentManager;
use common\logic\Document\Quotation\Repository\QuotationRepository;
use common\logic\Document\Quotation\Service\QuotationBuilder;
use common\logic\PointSale\PointSale\Repository\QuotationRepository;

/**
* @mixin QuotationRepository

+ 4
- 1
common/logic/Order/Order/Repository/OrderRepository.php Просмотреть файл

@@ -12,6 +12,7 @@ use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Service\ProductSolver;
use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Model\UserProducer;
use yii\helpers\Html;
@@ -23,6 +24,7 @@ class OrderRepository extends AbstractRepository
protected ProducerRepository $producerRepository;
protected OrderSolver $orderSolver;
protected ProductDistributionRepository $productDistributionRepository;
protected ProductSolver $productSolver;

public function loadDependencies(): void
{
@@ -31,6 +33,7 @@ class OrderRepository extends AbstractRepository
$this->producerRepository = $this->loadService(ProducerRepository::class);
$this->orderSolver = $this->loadService(OrderSolver::class);
$this->productDistributionRepository = $this->loadService(ProductDistributionRepository::class);
$this->productSolver = $this->loadService(ProductSolver::class);
}

public function getDefaultOptionsSearch(): array
@@ -148,7 +151,7 @@ class OrderRepository extends AbstractRepository
$count = count($order->productOrder);
foreach ($order->productOrder as $p) {
if (isset($p->product)) {
$html .= Html::encode($p->product->name) . ' (' . $p->quantity . '&nbsp;' . Product::strUnit(
$html .= Html::encode($p->product->name) . ' (' . $p->quantity . '&nbsp;' . $this->productSolver->strUnit(
$p->unit,
'wording_short',
true

+ 3
- 3
common/logic/Order/Order/Service/OrderBuilder.php Просмотреть файл

@@ -210,11 +210,11 @@ class OrderBuilder extends AbstractBuilder
$theOrder = $this->orderRepository->findOneOrderById($order->id);

// remboursement de la commande
if ($theOrder->id_user && $theOrder->getAmount(Order::AMOUNT_PAID) && $configCredit) {
if ($theOrder->id_user && $this->orderSolver->getOrderAmount($theOrder, Order::AMOUNT_PAID) && $configCredit) {

$this->creditHistoryBuilder->createCreditHistory(
CreditHistory::TYPE_REFUND,
$theOrder->getAmount(Order::AMOUNT_PAID),
$this->orderSolver->getAmount($theOrder, Order::AMOUNT_PAID),
$theOrder->distribution->producer,
$theOrder->user,
GlobalParam::getCurrentUser()
@@ -297,7 +297,7 @@ class OrderBuilder extends AbstractBuilder
$order->auto_payment = 1;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {

$userProducer = $this->userProducerRepository->findOneUserProducer($order->user, $order->producer);
$userProducer = $this->userProducerRepository->findOneUserProducer($order->user, $subscription->producer);

if ($userProducer) {
$order->auto_payment = $userProducer->credit_active;

+ 2
- 2
common/logic/Order/Order/Service/OrderSolver.php Просмотреть файл

@@ -309,7 +309,7 @@ class OrderSolver extends AbstractService implements SolverInterface
* Retourne le montant de la commande (total, payé, restant, ou en surplus).
*/
// getAmount
public function getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false): float
public function getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false)
{
$amount = $order->amount;
if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) {
@@ -320,7 +320,7 @@ class OrderSolver extends AbstractService implements SolverInterface
}

// getAmountWithTax
public function getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false): float
public function getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false)
{
$amount = $order->amount + $this->getOrderTotalVat($order, $type);
if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) {

+ 1
- 1
common/logic/Producer/Producer/Service/ProducerBuilder.php Просмотреть файл

@@ -102,7 +102,7 @@ class ProducerBuilder extends AbstractBuilder
);
}

public function savePrivateKeyEndpointStripe(Producer $producer): bool
public function savePrivateKeyEndpointStripe(Producer $producer): void
{
$this->savePrivateKeyStripe(
$this->producerSolver->getFilenamePrivateKeyEndpointStripe($producer),

+ 1
- 1
common/logic/Producer/ProducerPriceRange/Repository/ProducerPriceRangeRepository.php Просмотреть файл

@@ -46,7 +46,7 @@ class ProducerPriceRangeRepository extends AbstractRepository
return $this->queryProducerPriceRanges()->all();
}

public function getAmountToBeBilledByTurnover(float $turnover, $format = false)
public function getAmountToBeBilledByTurnover(float $turnover = null, $format = false)
{
$amountToBeBilled = 0;
$producerPriceRangeArray = $this->findProducerPriceRanges();

+ 3
- 3
common/logic/User/CreditHistory/Service/CreditHistorySolver.php Просмотреть файл

@@ -91,12 +91,12 @@ class CreditHistorySolver extends AbstractService implements SolverInterface

$user = $creditHistory->getUserObject();
if ($user) {
$str .= '<br />Client : ' . Html::encode($user->getName() . ' CreditHistorySolver.php' . $user->getLastname());
$str .= '<br />Client : ' . Html::encode($user->getName() . ' ' . $user->getLastname());
}

$userAction = $creditHistory->getUserActionObject();
if ($userAction) {
$str .= '<br />Action : ' . Html::encode($userAction->getName() . ' CreditHistorySolver.php' . $userAction->getLastname());
$str .= '<br />Action : ' . Html::encode($userAction->getName() . ' ' . $userAction->getLastname());
}

return $str;
@@ -124,7 +124,7 @@ class CreditHistorySolver extends AbstractService implements SolverInterface
$userAction = $creditHistory->getUserActionObject();

if ($userAction) {
return $userAction->getName() . ' CreditHistorySolver.php' . $userAction->getlastname();
return $userAction->getName() . ' ' . $userAction->getlastname();
} else {
return 'Système';
}

+ 1
- 1
common/mail/creditUser-html.php Просмотреть файл

@@ -38,7 +38,7 @@ termes.

use yii\helpers\Html;
use common\helpers\Price;
use common\logic\User\CreditHistory\CreditHistory;
use common\logic\User\CreditHistory\Model\CreditHistory;

?>


+ 1
- 1
common/mail/creditUser-text.php Просмотреть файл

@@ -37,7 +37,7 @@ termes.
*/

use common\helpers\Price ;
use common\models\CreditHistorique;
use common\logic\User\CreditHistory\Model\CreditHistory;

?>
Bonjour <?= $user->name; ?>,</p>

+ 4
- 1
common/mail/sendDocument-html.php Просмотреть файл

@@ -37,11 +37,14 @@ termes.
*/

use yii\helpers\Html;
use common\logic\Document\Document\Wrapper\DocumentManager;

$documentManager = DocumentManager::getInstance();

?>

<p>Bonjour <?= Html::encode($document->user->name); ?>,</p>

<p>Veuillez trouver en pièce jointe votre <?= strtolower($document->getType()) ?> <?php if($document->isStatusValid()): ?>N°<?= $document->reference ?><?php endif; ?>.</p>
<p>Veuillez trouver en pièce jointe votre <?= strtolower($documentManager->getType($document)) ?> <?php if($documentManager->isStatusValid($document)): ?>N°<?= $document->reference ?><?php endif; ?>.</p>

<p>À bientôt.</p>

+ 5
- 1
common/mail/sendDocument-text.php Просмотреть файл

@@ -36,10 +36,14 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use common\logic\Document\Document\Wrapper\DocumentManager;

$documentManager = DocumentManager::getInstance();

?>

Bonjour <?= $document->user->name ?>,

Veuillez trouver en pièce jointe votre <?= strtolower($document->getType()) ?> <?php if($document->isStatusValid()): ?>N°<?= $document->reference ?><?php endif; ?>.
Veuillez trouver en pièce jointe votre <?= strtolower($documentManager->getType($document)) ?> <?php if($documentManager->isStatusValid($document)): ?>N°<?= $document->reference ?><?php endif; ?>.

À bientôt.

+ 2
- 1
console/migrations/m190206_135142_ajout_champs_gestion_credit_avancee.php Просмотреть файл

@@ -2,11 +2,12 @@

use yii\db\Migration;
use yii\db\mysql\Schema;
use common\logic\Producer\Producer\Model\Producer;

class m190206_135142_ajout_champs_gestion_credit_avancee extends Migration {

public function up() {
$this->addColumn('producer', 'credit_functioning', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::CREDIT_FUNCTIONING_OPTIONAL.'\'') ;
$this->addColumn('producer', 'credit_functioning', Schema::TYPE_STRING.' DEFAULT \''.Producer::CREDIT_FUNCTIONING_OPTIONAL.'\'') ;
$this->addColumn('point_sale', 'credit_functioning', Schema::TYPE_STRING) ;
}


+ 2
- 1
console/migrations/m210326_104759_add_option_order_entry_point.php Просмотреть файл

@@ -2,12 +2,13 @@

use yii\db\Migration;
use yii\db\Schema;
use common\logic\Producer\Producer\Model\Producer;

class m210326_104759_add_option_order_entry_point extends Migration
{
public function safeUp()
{
$this->addColumn('producer', 'option_order_entry_point', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::ORDER_ENTRY_POINT_DATE.'\'');
$this->addColumn('producer', 'option_order_entry_point', Schema::TYPE_STRING.' DEFAULT \''.Producer::ORDER_ENTRY_POINT_DATE.'\'');
}

public function safeDown()

Загрузка…
Отмена
Сохранить