Browse Source

[Backend] Bons de livraison : ajout champs 'ignore_when_billing' #999

refactoring
Guillaume Bourgeois 1 year ago
parent
commit
4802c1b8ba
6 changed files with 64 additions and 18 deletions
  1. +10
    -5
      backend/controllers/DocumentController.php
  2. +8
    -4
      backend/views/document/_form.php
  3. +9
    -0
      common/logic/Document/DeliveryNote/Model/DeliveryNote.php
  4. +1
    -1
      common/logic/Document/Document/Model/Document.php
  5. +10
    -8
      common/logic/Document/Document/Repository/DocumentRepository.php
  6. +26
    -0
      console/migrations/m230405_090528_add_field_delivery_note_ignore_when_billing.php

+ 10
- 5
backend/controllers/DocumentController.php View File

@@ -103,7 +103,9 @@ class DocumentController extends BackendController
$documentManager = $this->getDocumentManager();

$class = $this->getClass();
$class = 'common\\logic\\Document\\'.$class.'\\Model\\'.$class;
$model = new $class();

$documentManager->initTaxCalculationMethod($model);

if ($model->load(\Yii::$app->request->post())) {
@@ -128,7 +130,8 @@ class DocumentController extends BackendController

public function processInvoiceViaDeliveryNotes($model)
{
if ($model->getClass() == 'Invoice') {
$documentManager = $this->getDocumentManager();
if ($documentManager->getClass($model) == 'Invoice') {
if ($model->deliveryNotes && is_array($model->deliveryNotes) && count($model->deliveryNotes)) {
foreach ($model->deliveryNotes as $key => $idDeliveryNote) {
Order::updateAll([
@@ -379,14 +382,14 @@ class DocumentController extends BackendController

if ($user) {
$document = null;
if ($documentManager->isValidClass($classDocument)) {
if ($documentManager->isValidClass($classDocument) && $idDocument) {
$document = $this->findModel($idDocument, $classDocument);
}

if ($document && $document->id_user == $user->id) {
$address = $document->address;
} else {
$address = $user->getFullAddress();
$address = $userManager->getFullAddress($user);
}

$json = [
@@ -401,12 +404,14 @@ class DocumentController extends BackendController
];
$deliveryNotesCreateArray = DeliveryNote::searchAll([
'id_user' => $user->id,
'status' => Document::STATUS_VALID
'status' => Document::STATUS_VALID,
'ignore_when_billing' => null
], $options);
$deliveryNotesUpdateArray = DeliveryNote::searchAll([
'id_user' => $user->id,
'status' => Document::STATUS_VALID,
'order.id_invoice' => $idDocument
'order.id_invoice' => $idDocument,
'ignore_when_billing' => null
], $options);
$json['delivery_note_create_array'] = $this->initDeliveryNoteArray('create', $deliveryNotesCreateArray);
$json['delivery_note_update_array'] = $this->initDeliveryNoteArray('update', $deliveryNotesUpdateArray);

+ 8
- 4
backend/views/document/_form.php View File

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

use common\logic\Document\Document\Wrapper\DocumentManager;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use common\logic\User\User\Model\User;
use common\logic\User\User\Wrapper\UserManager;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

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

$producerManager = $this->getProducerManager();
$documentManager = $this->getDocumentManager();
$userManager = $this->getUserManager();
$producerManager = ProducerManager::getInstance();
$documentManager = DocumentManager::getInstance();
$userManager = UserManager::getInstance();

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

@@ -75,7 +79,7 @@ $documentClass = $documentManager->getClass($model);
'template' => '{label} <a href="' . Yii::$app->urlManager->createUrl(['user/create']) . '" class="btn btn-xs btn-default">Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span></a><div>{input}</div>{hint}',
])
->dropDownList(
User::populateDropdownList(),
$userManager->populateUserDropdownList(),
[
'@change' => 'changeUser',
'v-model' => 'idUser',

+ 9
- 0
common/logic/Document/DeliveryNote/Model/DeliveryNote.php View File

@@ -50,6 +50,15 @@ class DeliveryNote extends Document
return 'delivery_note';
}

public function rules()
{
$rules = parent::rules();

$rules[] = ['ignore_when_billing', 'boolean'];

return $rules;
}

/*
* Relations
*/

+ 1
- 1
common/logic/Document/Document/Model/Document.php View File

@@ -68,7 +68,7 @@ class Document extends ActiveRecordCommon implements DocumentInterface
[['date'], 'safe'],
[['comment', 'address', 'tax_calculation_method'], 'string'],
[['id_user', 'id_producer'], 'integer'],
['is_sent', 'boolean'],
[['is_sent'], 'boolean'],
[['name', 'reference', 'status'], 'string', 'max' => 255],
[['deliveryNotes'], 'safe']
];

+ 10
- 8
common/logic/Document/Document/Repository/DocumentRepository.php View File

@@ -29,14 +29,16 @@ class DocumentRepository extends AbstractRepository
{
$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);
if($idDocument) {
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;

+ 26
- 0
console/migrations/m230405_090528_add_field_delivery_note_ignore_when_billing.php View File

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

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

/**
* Class m230405_090528_add_field_delivery_note_ignore_when_billing
*/
class m230405_090528_add_field_delivery_note_ignore_when_billing extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('delivery_note', 'ignore_when_billing', Schema::TYPE_BOOLEAN.' DEFAULT NULL');
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('delivery_note', 'ignore_when_billing');
}
}

Loading…
Cancel
Save