Selaa lähdekoodia

[Backend] Bons de livraison : désactiver anciens BL Terre de Pains #989

feature/souke
Guillaume Bourgeois 1 vuosi sitten
vanhempi
commit
e49bc26708
3 muutettua tiedostoa jossa 187 lisäystä ja 163 poistoa
  1. +160
    -162
      backend/controllers/DocumentController.php
  2. +1
    -1
      common/models/Document.php
  3. +26
    -0
      console/migrations/m230405_090528_add_field_delivery_note_ignore_when_billing.php

+ 160
- 162
backend/controllers/DocumentController.php Näytä tiedosto

@@ -59,23 +59,23 @@ class DocumentController extends BackendController
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
],
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
}
]
],
],
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
}
]
],
],
];
}

@@ -89,8 +89,8 @@ class DocumentController extends BackendController
Invoice::find()->where(['status' => Document::STATUS_VALID])->all()
);

foreach($validatedDocumentsArray as $document) {
if(!file_exists($document->getFilenameComplete())) {
foreach ($validatedDocumentsArray as $document) {
if (!file_exists($document->getFilenameComplete())) {
$document->generatePdf(Pdf::DEST_FILE);
}
}
@@ -116,9 +116,9 @@ class DocumentController extends BackendController
}

return $this->render('/document/create', [
'title' => $this->getTitle('Ajouter'),
'typeDocument' => $this->getDocumentType(),
'model' => $model,
'title' => $this->getTitle('Ajouter'),
'typeDocument' => $this->getDocumentType(),
'model' => $model,
]);
}

@@ -128,10 +128,10 @@ class DocumentController extends BackendController
if ($model->deliveryNotes && is_array($model->deliveryNotes) && count($model->deliveryNotes)) {
foreach ($model->deliveryNotes as $key => $idDeliveryNote) {
Order::updateAll([
'id_invoice' => $model->id
], [
'id_delivery_note' => $idDeliveryNote
]);
'id_invoice' => $model->id
], [
'id_delivery_note' => $idDeliveryNote
]);
}
}
}
@@ -157,9 +157,9 @@ class DocumentController extends BackendController
}

return $this->render('/document/update', [
'title' => $this->getTitle('Modifier'),
'typeDocument' => $this->getDocumentType(),
'model' => $model,
'title' => $this->getTitle('Modifier'),
'typeDocument' => $this->getDocumentType(),
'model' => $model,
]);
}

@@ -175,26 +175,26 @@ class DocumentController extends BackendController

if ($this->getClass() == 'DeliveryNote') {
Order::updateAll([
'order.id_delivery_note' => null
], [
'order.id_delivery_note' => $id
]);
'order.id_delivery_note' => null
], [
'order.id_delivery_note' => $id
]);
}

if ($this->getClass() == 'Quotation') {
Order::updateAll([
'order.id_quotation' => null
], [
'order.id_quotation' => $id
]);
'order.id_quotation' => null
], [
'order.id_quotation' => $id
]);
}

if ($this->getClass() == 'Invoice') {
Order::updateAll([
'order.id_invoice' => null
], [
'order.id_invoice' => $id
]);
'order.id_invoice' => null
], [
'order.id_invoice' => $id
]);
}

Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('delete', $model));
@@ -247,12 +247,12 @@ class DocumentController extends BackendController
'Code Classification vente',
];

foreach($document->getProductsOrders() as $productOrderArray) {
foreach($productOrderArray as $productOrder) {
foreach ($document->getProductsOrders() as $productOrderArray) {
foreach ($productOrderArray as $productOrder) {

$price = $productOrder->getPrice() ;
if($document->isInvoicePrice() && $productOrder->getInvoicePrice()) {
$price = $productOrder->getInvoicePrice() ;
$price = $productOrder->getPrice();
if ($document->isInvoicePrice() && $productOrder->getInvoicePrice()) {
$price = $productOrder->getInvoicePrice();
}

$typeTotal = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL;
@@ -307,17 +307,17 @@ class DocumentController extends BackendController

// nom fichier
$reference = $document->id;
if($document->reference && strlen($document->reference)) {
if ($document->reference && strlen($document->reference)) {
$reference = $document->reference;
}

// status
$status = '';
if($document->isStatusDraft()) {
if ($document->isStatusDraft()) {
$status = 'brouillon_';
}

CSV::downloadSendHeaders(strtolower($this->getDocumentType()).'_' . $status . $reference . '.csv');
CSV::downloadSendHeaders(strtolower($this->getDocumentType()) . '_' . $status . $reference . '.csv');
echo CSV::array2csv($datas);
die();
}
@@ -348,10 +348,9 @@ class DocumentController extends BackendController
Yii::$app->getSession()->setFlash('danger', $this->getFlashMessage('send', $document));
}

if($backUpdateForm) {
if ($backUpdateForm) {
return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]);
}
else {
} else {
return $this->redirect([$this->getControllerUrl() . '/index']);
}
}
@@ -362,16 +361,16 @@ class DocumentController extends BackendController

if ($idUser > 0) {
$user = User::searchOne([
'id' => $idUser
]);
'id' => $idUser
]);

if ($user) {
$document = null;
if (Document::isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $idDocument,
'id_user' => $idUser
]);
'id' => $idDocument,
'id_user' => $idUser
]);
}

if ($document && $document->id_user == $user->id) {
@@ -381,8 +380,8 @@ class DocumentController extends BackendController
}

$json = [
'return' => 'success',
'address' => $address
'return' => 'success',
'address' => $address
];

if ($classDocument == 'Invoice') {
@@ -391,14 +390,16 @@ class DocumentController extends BackendController
'join_with' => ['user AS user_delivery_note', 'orders', 'producer']
];
$deliveryNotesCreateArray = DeliveryNote::searchAll([
'id_user' => $user->id,
'status' => Document::STATUS_VALID
], $options);
'id_user' => $user->id,
'status' => Document::STATUS_VALID,
'ignore_when_billing' => null
], $options);
$deliveryNotesUpdateArray = DeliveryNote::searchAll([
'id_user' => $user->id,
'status' => Document::STATUS_VALID,
'order.id_invoice' => $idDocument
], $options);
'id_user' => $user->id,
'status' => Document::STATUS_VALID,
'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);
}
@@ -414,14 +415,14 @@ class DocumentController extends BackendController
{
$deliveryNoteArray = [];
$isCreate = false;
if($type == 'create') {
if ($type == 'create') {
$isCreate = true;
}

if($deliveryNoteArrayResults) {
if ($deliveryNoteArrayResults) {
foreach ($deliveryNoteArrayResults as $deliveryNote) {
$deliveryNoteData = $this->addDeliveryNoteToArray($deliveryNote, $isCreate);
if($deliveryNoteData) {
if ($deliveryNoteData) {
$deliveryNoteArray[] = $deliveryNoteData;
}
}
@@ -453,8 +454,8 @@ class DocumentController extends BackendController

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

if ($document) {
$document->changeStatus(Document::STATUS_VALID);
@@ -465,10 +466,9 @@ class DocumentController extends BackendController

Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('validate', $document));

if($backUpdateForm) {
if ($backUpdateForm) {
return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]);
}
else {
} else {
return $this->redirect([$this->getControllerUrl() . '/index']);
}
}
@@ -484,28 +484,28 @@ class DocumentController extends BackendController

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

if ($document) {
$document->changeStatus(Document::STATUS_VALID);
$document->save();
return [
'return' => 'success',
'alert' => [
'type' => 'success',
'message' => 'Document validé'
]
'return' => 'success',
'alert' => [
'type' => 'success',
'message' => 'Document validé'
]
];
}
}

return [
'return' => 'error',
'alert' => [
'type' => 'danger',
'message' => 'Une erreur est survenue lors de la validation du document.'
]
'return' => 'error',
'alert' => [
'type' => 'danger',
'message' => 'Une erreur est survenue lors de la validation du document.'
]
];
}

@@ -515,12 +515,12 @@ class DocumentController extends BackendController

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

if ($document) {
$productsArray = Product::searchAll([], [
'orderby' => 'product.order ASC'
'orderby' => 'product.order ASC'
]);

$ordersArray = [];
@@ -533,61 +533,59 @@ class DocumentController extends BackendController
]);
}
$ordersArray[$order->id] = array_merge(
$order->getAttributes(),
[
'username' => $order->getUsername(),
'distribution_date' => isset($order->distribution) ? date(
'd/m/Y',
strtotime(
$order->distribution->date
)
) : null,
'point_sale_name' => isset($order->pointSale) ? $order->pointSale->name : null,
'productOrder' => $productsOrderArray,
]
$order->getAttributes(),
[
'username' => $order->getUsername(),
'distribution_date' => isset($order->distribution) ? date(
'd/m/Y',
strtotime(
$order->distribution->date
)
) : null,
'point_sale_name' => isset($order->pointSale) ? $order->pointSale->name : null,
'productOrder' => $productsOrderArray,
]
);
}

$userProducer = UserProducer::searchOne([
'id_user' => $document->user->id,
'id_producer' => GlobalParam::getCurrentProducerId()
]);
'id_user' => $document->user->id,
'id_producer' => GlobalParam::getCurrentProducerId()
]);
$pointSale = PointSale::searchOne([
'id_user' => $document->user->id
]);
'id_user' => $document->user->id
]);

$productsArray = yii\helpers\ArrayHelper::map(
$productsArray,
'order',
function ($product) use ($document, $userProducer, $pointSale) {
return array_merge($product->getAttributes(), [
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $product->getPriceArray($userProducer->user, $pointSale),
'wording_unit' => $product->wording_unit,
'tax_rate' => $product->taxRate->value
]);
}
$productsArray,
'order',
function ($product) use ($document, $userProducer, $pointSale) {
return array_merge($product->getAttributes(), [
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $product->getPriceArray($userProducer->user, $pointSale),
'wording_unit' => $product->wording_unit,
'tax_rate' => $product->taxRate->value
]);
}
);

return [
'return' => 'success',
'tax_rate_producer' => GlobalParam::getCurrentProducer()->taxRate->value,
'document' => array_merge($document->getAttributes(), [
'html_label' => $document->getHtmlLabel(),
'class' => $document->getClass()
]),
'id_user' => $document->user->id,
'products' => $productsArray,
'orders' => $ordersArray,
'total' => ($document->getClass() == 'Invoice' || $document->getClass(
) == 'DeliveryNote') ? $document->getAmount(
Order::INVOICE_AMOUNT_TOTAL
) : $document->getAmount(Order::AMOUNT_TOTAL),
'total_with_tax' => ($document->getClass() == 'Invoice' || $document->getClass(
) == 'DeliveryNote') ? $document->getAmountWithTax(
Order::INVOICE_AMOUNT_TOTAL
) : $document->getAmountWithTax(Order::AMOUNT_TOTAL),
'invoice_url' => ($document->getClass() == 'DeliveryNote' && $document->getInvoice()) ? Yii::$app->urlManager->createUrl(['invoice/update', 'id' => $document->getInvoice()->id]) : null
'return' => 'success',
'tax_rate_producer' => GlobalParam::getCurrentProducer()->taxRate->value,
'document' => array_merge($document->getAttributes(), [
'html_label' => $document->getHtmlLabel(),
'class' => $document->getClass()
]),
'id_user' => $document->user->id,
'products' => $productsArray,
'orders' => $ordersArray,
'total' => ($document->getClass() == 'Invoice' || $document->getClass() == 'DeliveryNote') ? $document->getAmount(
Order::INVOICE_AMOUNT_TOTAL
) : $document->getAmount(Order::AMOUNT_TOTAL),
'total_with_tax' => ($document->getClass() == 'Invoice' || $document->getClass() == 'DeliveryNote') ? $document->getAmountWithTax(
Order::INVOICE_AMOUNT_TOTAL
) : $document->getAmountWithTax(Order::AMOUNT_TOTAL),
'invoice_url' => ($document->getClass() == 'DeliveryNote' && $document->getInvoice()) ? Yii::$app->urlManager->createUrl(['invoice/update', 'id' => $document->getInvoice()->id]) : null
];
}
}
@@ -601,11 +599,11 @@ class DocumentController extends BackendController

if (Document::isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $idDocument
]);
'id' => $idDocument
]);
$product = Product::searchOne([
'id' => $idProduct
]);
'id' => $idProduct
]);

if ($document && $product) {
if (count($document->orders) == 0) {
@@ -636,22 +634,22 @@ class DocumentController extends BackendController
$productOrder->save();

return [
'return' => 'success',
'alert' => [
'type' => 'success',
'message' => 'Produit ajouté'
]
'return' => 'success',
'alert' => [
'type' => 'success',
'message' => 'Produit ajouté'
]
];
}
}
}

return [
'return' => 'error',
'alert' => [
'type' => 'danger',
'message' => 'Une erreur est survenue lors de la suppression du produit.'
]
'return' => 'error',
'alert' => [
'type' => 'danger',
'message' => 'Une erreur est survenue lors de la suppression du produit.'
]
];
}

@@ -660,27 +658,27 @@ class DocumentController extends BackendController
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$productOrder = ProductOrder::searchOne([
'id' => $idProductOrder
]);
'id' => $idProductOrder
]);

if ($productOrder) {
$productOrder->delete();

return [
'return' => 'success',
'alert' => [
'type' => 'danger',
'message' => 'Produit supprimé'
]
'return' => 'success',
'alert' => [
'type' => 'danger',
'message' => 'Produit supprimé'
]
];
}

return [
'return' => 'error',
'alert' => [
'type' => 'danger',
'message' => 'Une erreur est survenue lors de la suppression du produit.'
]
'return' => 'error',
'alert' => [
'type' => 'danger',
'message' => 'Une erreur est survenue lors de la suppression du produit.'
]
];
}

@@ -775,10 +773,10 @@ class DocumentController extends BackendController
$class = $this->getClass();

$model = $class::searchOne([
'id' => $id
], [
'orderby' => 'teshtygjhtyt'
]);
'id' => $id
], [
'orderby' => 'teshtygjhtyt'
]);

if ($model) {
return $model;

+ 1
- 1
common/models/Document.php Näytä tiedosto

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

+ 26
- 0
console/migrations/m230405_090528_add_field_delivery_note_ignore_when_billing.php Näytä tiedosto

@@ -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…
Peruuta
Tallenna