Browse Source

Merge branch 'develop'

prodstable
Guillaume Bourgeois 1 year ago
parent
commit
7159a3a5b5
8 changed files with 194 additions and 194 deletions
  1. +160
    -162
      backend/controllers/DocumentController.php
  2. +1
    -1
      backend/views/distribution/index.php
  3. +1
    -1
      backend/web/js/vuejs/distribution-index.js
  4. +1
    -0
      common/config/.gitignore
  5. +0
    -29
      common/config/test-local.php
  6. +4
    -0
      common/models/DeliveryNoteSearch.php
  7. +1
    -1
      common/models/Document.php
  8. +26
    -0
      console/migrations/m230405_090528_add_field_delivery_note_ignore_when_billing.php

+ 160
- 162
backend/controllers/DocumentController.php View File

public function behaviors() public function behaviors()
{ {
return [ 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();
}
]
], ],
],
]; ];
} }


Invoice::find()->where(['status' => Document::STATUS_VALID])->all() 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); $document->generatePdf(Pdf::DEST_FILE);
} }
} }
} }


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


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([
'id_invoice' => $model->id
], [
'id_delivery_note' => $idDeliveryNote
]);
'id_invoice' => $model->id
], [
'id_delivery_note' => $idDeliveryNote
]);
} }
} }
} }
} }


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




if ($this->getClass() == 'DeliveryNote') { if ($this->getClass() == 'DeliveryNote') {
Order::updateAll([ 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') { if ($this->getClass() == 'Quotation') {
Order::updateAll([ Order::updateAll([
'order.id_quotation' => null
], [
'order.id_quotation' => $id
]);
'order.id_quotation' => null
], [
'order.id_quotation' => $id
]);
} }


if ($this->getClass() == 'Invoice') { if ($this->getClass() == 'Invoice') {
Order::updateAll([ 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)); Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('delete', $model));
'Code Classification vente', '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; $typeTotal = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL;


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


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


CSV::downloadSendHeaders(strtolower($this->getDocumentType()).'_' . $status . $reference . '.csv');
CSV::downloadSendHeaders(strtolower($this->getDocumentType()) . '_' . $status . $reference . '.csv');
echo CSV::array2csv($datas); echo CSV::array2csv($datas);
die(); die();
} }
Yii::$app->getSession()->setFlash('danger', $this->getFlashMessage('send', $document)); Yii::$app->getSession()->setFlash('danger', $this->getFlashMessage('send', $document));
} }


if($backUpdateForm) {
if ($backUpdateForm) {
return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]); return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]);
}
else {
} else {
return $this->redirect([$this->getControllerUrl() . '/index']); return $this->redirect([$this->getControllerUrl() . '/index']);
} }
} }


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


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


if ($document && $document->id_user == $user->id) { if ($document && $document->id_user == $user->id) {
} }


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


if ($classDocument == 'Invoice') { if ($classDocument == 'Invoice') {
'join_with' => ['user AS user_delivery_note', 'orders', 'producer'] 'join_with' => ['user AS user_delivery_note', 'orders', 'producer']
]; ];
$deliveryNotesCreateArray = DeliveryNote::searchAll([ $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([ $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_create_array'] = $this->initDeliveryNoteArray('create', $deliveryNotesCreateArray);
$json['delivery_note_update_array'] = $this->initDeliveryNoteArray('update', $deliveryNotesUpdateArray); $json['delivery_note_update_array'] = $this->initDeliveryNoteArray('update', $deliveryNotesUpdateArray);
} }
{ {
$deliveryNoteArray = []; $deliveryNoteArray = [];
$isCreate = false; $isCreate = false;
if($type == 'create') {
if ($type == 'create') {
$isCreate = true; $isCreate = true;
} }


if($deliveryNoteArrayResults) {
if ($deliveryNoteArrayResults) {
foreach ($deliveryNoteArrayResults as $deliveryNote) { foreach ($deliveryNoteArrayResults as $deliveryNote) {
$deliveryNoteData = $this->addDeliveryNoteToArray($deliveryNote, $isCreate); $deliveryNoteData = $this->addDeliveryNoteToArray($deliveryNote, $isCreate);
if($deliveryNoteData) {
if ($deliveryNoteData) {
$deliveryNoteArray[] = $deliveryNoteData; $deliveryNoteArray[] = $deliveryNoteData;
} }
} }


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


if ($document) { if ($document) {
$document->changeStatus(Document::STATUS_VALID); $document->changeStatus(Document::STATUS_VALID);


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


if($backUpdateForm) {
if ($backUpdateForm) {
return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]); return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]);
}
else {
} else {
return $this->redirect([$this->getControllerUrl() . '/index']); return $this->redirect([$this->getControllerUrl() . '/index']);
} }
} }


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


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


return [ 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.'
]
]; ];
} }




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


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


$ordersArray = []; $ordersArray = [];
]); ]);
} }
$ordersArray[$order->id] = array_merge( $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([ $userProducer = UserProducer::searchOne([
'id_user' => $document->user->id,
'id_producer' => GlobalParam::getCurrentProducerId()
]);
'id_user' => $document->user->id,
'id_producer' => GlobalParam::getCurrentProducerId()
]);
$pointSale = PointSale::searchOne([ $pointSale = PointSale::searchOne([
'id_user' => $document->user->id
]);
'id_user' => $document->user->id
]);


$productsArray = yii\helpers\ArrayHelper::map( $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 [
'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
]; ];
} }
} }


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


if ($document && $product) { if ($document && $product) {
if (count($document->orders) == 0) { if (count($document->orders) == 0) {
$productOrder->save(); $productOrder->save();


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


return [ 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.'
]
]; ];
} }


\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;


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


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


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


return [ 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.'
]
]; ];
} }


$class = $this->getClass(); $class = $this->getClass();


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


if ($model) { if ($model) {
return $model; return $model;

+ 1
- 1
backend/views/distribution/index.php View File



<span class="glyphicon glyphicon-time" title="Paiement automatique" v-if="order.auto_payment && producer && producer.credit && (order.amount_paid == 0 || order.amount_paid < order.amount)"></span> <span class="glyphicon glyphicon-time" title="Paiement automatique" v-if="order.auto_payment && producer && producer.credit && (order.amount_paid == 0 || order.amount_paid < order.amount)"></span>
</div> </div>
<script type="text/x-template" id="order-form-template">
</script>


<!-- template for the order-form component --> <!-- template for the order-form component -->
<script type="text/x-template" id="order-form-template"> <script type="text/x-template" id="order-form-template">

+ 1
- 1
backend/web/js/vuejs/distribution-index.js View File



Vue.component('modal', { Vue.component('modal', {
template: '#modal-template' template: '#modal-template'
})
});


Vue.component('order-form',{ Vue.component('order-form',{
props: ['date', 'dateFormat', 'pointsSale', 'idActivePointSale', 'meansPayment', 'users', 'products', 'order', 'producer', 'loadingUpdateProductOrder'], props: ['date', 'dateFormat', 'pointsSale', 'idActivePointSale', 'meansPayment', 'users', 'products', 'order', 'producer', 'loadingUpdateProductOrder'],

+ 1
- 0
common/config/.gitignore View File

bootstrap.php bootstrap.php
main-local.php main-local.php
params-local.php params-local.php
test-local.php


stripe/*.key stripe/*.key
mailjet/*.key mailjet/*.key

+ 0
- 29
common/config/test-local.php View File

<?php

return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=opendistrib_test',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp-laclic.alwaysdata.net',
'username' => 'nepasrepondre@laclic.fr',
'password' => 'UPdz4ain73u3T3S74z2MHG9gUKnu6Qq6',
'port' => '25',
//'encryption' => 'tls',
],
],
],
];

+ 4
- 0
common/models/DeliveryNoteSearch.php View File

{ {
$optionsSearch = self::defaultOptionsSearch(); $optionsSearch = self::defaultOptionsSearch();


if(isset($params['DeliveryNoteSearch']['id_point_sale'])) {
$optionsSearch['join_with'][] = 'orders';
}

$query = DeliveryNote::find() $query = DeliveryNote::find()
->with($optionsSearch['with']) ->with($optionsSearch['with'])
->joinWith($optionsSearch['join_with']) ->joinWith($optionsSearch['join_with'])

+ 1
- 1
common/models/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', 'ignore_when_billing'], 'boolean'],
[['name', 'reference', 'status'], 'string', 'max' => 255], [['name', 'reference', 'status'], 'string', 'max' => 255],
[['deliveryNotes'], 'safe'] [['deliveryNotes'], 'safe']
]; ];

+ 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