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

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


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

$documentManager->initTaxCalculationMethod($model); $documentManager->initTaxCalculationMethod($model);


if ($model->load(\Yii::$app->request->post())) { if ($model->load(\Yii::$app->request->post())) {


public function processInvoiceViaDeliveryNotes($model) 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)) { if ($model->deliveryNotes && is_array($model->deliveryNotes) && count($model->deliveryNotes)) {
foreach ($model->deliveryNotes as $key => $idDeliveryNote) { foreach ($model->deliveryNotes as $key => $idDeliveryNote) {
Order::updateAll([ Order::updateAll([


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


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


$json = [ $json = [
]; ];
$deliveryNotesCreateArray = DeliveryNote::searchAll([ $deliveryNotesCreateArray = DeliveryNote::searchAll([
'id_user' => $user->id, 'id_user' => $user->id,
'status' => Document::STATUS_VALID
'status' => Document::STATUS_VALID,
'ignore_when_billing' => null
], $options); ], $options);
$deliveryNotesUpdateArray = DeliveryNote::searchAll([ $deliveryNotesUpdateArray = DeliveryNote::searchAll([
'id_user' => $user->id, 'id_user' => $user->id,
'status' => Document::STATUS_VALID, 'status' => Document::STATUS_VALID,
'order.id_invoice' => $idDocument
'order.id_invoice' => $idDocument,
'ignore_when_billing' => null
], $options); ], $options);
$json['delivery_note_create_array'] = $this->initDeliveryNoteArray('create', $deliveryNotesCreateArray); $json['delivery_note_create_array'] = $this->initDeliveryNoteArray('create', $deliveryNotesCreateArray);
$json['delivery_note_update_array'] = $this->initDeliveryNoteArray('update', $deliveryNotesUpdateArray); $json['delivery_note_update_array'] = $this->initDeliveryNoteArray('update', $deliveryNotesUpdateArray);

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

* termes. * 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\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;


\backend\assets\VuejsDocumentFormAsset::register($this); \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); $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}', '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( ->dropDownList(
User::populateDropdownList(),
$userManager->populateUserDropdownList(),
[ [
'@change' => 'changeUser', '@change' => 'changeUser',
'v-model' => 'idUser', 'v-model' => 'idUser',

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

return 'delivery_note'; return 'delivery_note';
} }


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

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

return $rules;
}

/* /*
* Relations * Relations
*/ */

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

[['date'], 'safe'], [['date'], 'safe'],
[['comment', 'address', 'tax_calculation_method'], 'string'], [['comment', 'address', 'tax_calculation_method'], 'string'],
[['id_user', 'id_producer'], 'integer'], [['id_user', 'id_producer'], 'integer'],
['is_sent', 'boolean'],
[['is_sent'], 'boolean'],
[['name', 'reference', 'status'], 'string', 'max' => 255], [['name', 'reference', 'status'], 'string', 'max' => 255],
[['deliveryNotes'], 'safe'] [['deliveryNotes'], 'safe']
]; ];

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

{ {
$model = null; $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; return $model;

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

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