Преглед изворни кода

Documents : export CSV Evoliz #479

[Backend] Documents : ventiler la TVA #451
refactoring
Guillaume Bourgeois пре 2 година
родитељ
комит
876e4f7c3d
14 измењених фајлова са 540 додато и 392 уклоњено
  1. +1
    -1
      backend/controllers/DocumentController.php
  2. +3
    -0
      backend/views/document/_form.php
  3. +17
    -3
      backend/views/document/download.php
  4. +10
    -1
      backend/views/invoice/index.php
  5. +4
    -0
      backend/views/producer/update.php
  6. +5
    -0
      backend/views/user/_form.php
  7. +10
    -17
      common/helpers/Price.php
  8. +363
    -339
      common/models/Document.php
  9. +71
    -27
      common/models/Order.php
  10. +4
    -2
      common/models/Producer.php
  11. +9
    -0
      common/models/ProductOrder.php
  12. +12
    -0
      common/models/TaxRate.php
  13. +3
    -2
      common/models/User.php
  14. +28
    -0
      console/migrations/m220919_084020_add_fields_export_evoliz.php

+ 1
- 1
backend/controllers/DocumentController.php Прегледај датотеку

@@ -236,7 +236,7 @@ class DocumentController extends BackendController
$document->reference, // N° facture externe *
date('d/m/Y', strtotime($document->date)), // Date facture *
'', // Client
'C1', // Code client *
$document->user->evoliz_code, // Code client *
'', // Total TVA
'', // Total HT
'', // Total TTC

+ 3
- 0
backend/views/document/_form.php Прегледај датотеку

@@ -155,6 +155,9 @@ use common\models\Producer;
<span class="info-box-icon bg-blue"><i class="fa fa-download"></i></span>
<div class="info-box-content">
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl().'/download', 'id' => $model->id]) ?>" class="btn btn-default"><span class="glyphicon glyphicon-download-alt"></span> Télécharger (PDF)</a>
<?php if($model->getClass() == 'Invoice' && Producer::getConfig('option_export_evoliz')): ?>
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl().'/export-csv-evoliz', 'id' => $model->id]) ?>" class="btn btn-default"><span class="glyphicon glyphicon-save-file"></span> Export Evoliz (CSV)</a>
<?php endif; ?>
</div>
</div>
<div v-if="document.status == 'draft'" id="" class="info-box">

+ 17
- 3
backend/views/document/download.php Прегледај датотеку

@@ -128,10 +128,24 @@ $displayProductDescription = Producer::getConfig('document_display_product_descr
<?= Price::format($document->getAmount($typeAmount)); ?>
</td>
</tr>
<tr>

<?php
$taxRateArray = TaxRate::getTaxRateArray();
foreach($document->getTotalVatArray($typeAmount) as $idTaxRate => $totalVat): ?>
<tr>
<td class="align-right" colspan="5"><strong>TVA <?= $taxRateArray[$idTaxRate]->value * 100 ?> %</strong></td>
<td class="align-center">
<?= Price::format($totalVat); ?>
</td>
</tr>
<?php endforeach; ?>

<!--<tr>
<td class="align-right" colspan="5"><strong>TVA</strong></td>
<td class="align-center"><?= Price::format($document->getAmountWithTax($typeAmount) - $document->getAmount($typeAmount)) ?></td>
</tr>
<td class="align-center">
<?= Price::format($document->getAmountWithTax($typeAmount) - $document->getAmount($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>

+ 10
- 1
backend/views/invoice/index.php Прегледај датотеку

@@ -101,7 +101,7 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{validate} {update} {delete} {send} {download}',
'template' => '{validate} {update} {delete} {send} {download} {export-csv-evoliz}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
@@ -120,6 +120,15 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
'title' => 'Télécharger', 'class' => 'btn btn-default'
]);
},
'export-csv-evoliz' => function($url, $model) {
if(Producer::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'

+ 4
- 0
backend/views/producer/update.php Прегледај датотеку

@@ -434,6 +434,10 @@ $this->addBreadcrumb($this->getTitle()) ;
->label('TVA à appliquer par défaut'); ?>
<?= $form->field($model, 'option_tax_calculation_method')
->dropDownList(Document::$taxCalculationMethodArray); ?>
<?= $form->field($model, 'option_export_evoliz')->dropDownList([
0 => 'Non',
1 => 'Oui'
]) ; ?>
<?= $form->field($model, 'document_quotation_prefix') ; ?>
<?= $form->field($model, 'document_quotation_first_reference') ; ?>
<?= $form->field($model, 'document_quotation_duration') ; ?>

+ 5
- 0
backend/views/user/_form.php Прегледај датотеку

@@ -61,6 +61,11 @@ use common\models\ProductPrice ;
<?= $form->field($model, 'phone')->textInput() ?>
<?= $form->field($model, 'email')->textInput() ?>
<?= $form->field($model, 'address')->textarea() ?>

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

<?= $form->field($model, 'points_sale')->checkboxlist(
ArrayHelper::map($pointsSaleArray, 'id', function ($pointSale) use ($model) {
$commentUserPointSale = isset($pointSale->userPointSale[0]) ? $pointSale->userPointSale[0]->comment : '';

+ 10
- 17
common/helpers/Price.php Прегледај датотеку

@@ -58,28 +58,21 @@ class Price

public static function getPriceWithTax($priceWithoutTax, $taxRate, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT)
{
// tax
$tax = $priceWithoutTax * $taxRate;
if($taxCalculationMethod == Document::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS) {
$tax = self::round($tax);
}

// price
$priceWithoutTax = floatval($priceWithoutTax);
$priceWithoutTax = self::round($priceWithoutTax);
$vat = self::getVat($priceWithoutTax, $taxRate, $taxCalculationMethod);

$priceWithTax = $priceWithoutTax + $tax;

return $priceWithTax;
return $priceWithoutTax + $vat;
}

/*$priceWithTax = floatval($priceWithoutTax) * ($taxRate + 1);
public static function getVat($priceTotalWithoutTax, $taxRate, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT)
{
$vat = $priceTotalWithoutTax * $taxRate;

if($taxCalculationMethod == Document::TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM) {
return $priceWithTax;
if($taxCalculationMethod == Document::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS) {
$vat = self::round($vat);
}
else {
return self::numberTwoDecimals($priceWithTax);
}*/

return $vat;
}

public static function numberTwoDecimals($number)

+ 363
- 339
common/models/Document.php Прегледај датотеку

@@ -39,387 +39,411 @@
namespace common\models;

use common\helpers\GlobalParam;
use kartik\mpdf\Pdf;

class Document extends ActiveRecordCommon
{
const STATUS_DRAFT = 'draft';
const STATUS_VALID = 'valid';

const TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS = 'sum-roundings';
const TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM = 'rounding-sum';
const TAX_CALCULATION_METHOD_DEFAULT = self::TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM;

public static $taxCalculationMethodArray = [
self::TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM => 'Arrondi de la somme des lignes',
self::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS => 'Somme des arrondis de chaque ligne'
const STATUS_DRAFT = 'draft';
const STATUS_VALID = 'valid';

const TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS = 'sum-roundings';
const TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM = 'rounding-sum';
const TAX_CALCULATION_METHOD_DEFAULT = self::TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM;

public static $taxCalculationMethodArray = [
self::TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM => 'Arrondi de la somme des lignes',
self::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS => 'Somme des arrondis de chaque ligne'
];

/**
* @inheritdoc
*/
public function rules()
{
return [
[['name', 'id_user'], 'required'],
[['date'], 'safe'],
[['comment', 'address', 'tax_calculation_method'], 'string'],
[['id_user', 'id_producer'], 'integer'],
[['name', 'reference', 'status'], 'string', 'max' => 255],
[['deliveryNotes'], 'safe']
];

/**
* @inheritdoc
*/
public function rules()
{
return [
[['name', 'id_user'], 'required'],
[['date'], 'safe'],
[['comment', 'address', 'tax_calculation_method'], 'string'],
[['id_user', 'id_producer'], 'integer'],
[['name', 'reference', 'status'], 'string', 'max' => 255],
[['deliveryNotes'], 'safe']
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Nom',
'reference' => 'Référence',
'date' => 'Date',
'comment' => 'Commentaire',
'id_user' => 'Utilisateur',
'address' => 'Adresse',
'id_producer' => 'Producteur',
'status' => 'Statut',
'tax_calculation_method' => 'Méthode de calcul de la TVA'
];
}

/*
* Relations
*/

public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'id_user']);
}

public function getProducer()
{
return $this->hasOne(Producer::className(), ['id' => 'id_producer']);
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Nom',
'reference' => 'Référence',
'date' => 'Date',
'comment' => 'Commentaire',
'id_user' => 'Utilisateur',
'address' => 'Adresse',
'id_producer' => 'Producteur',
'status' => 'Statut',
'tax_calculation_method' => 'Méthode de calcul de la TVA'
];
}

/*
* Relations
*/

public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'id_user']);
}

public function getProducer()
{
return $this->hasOne(Producer::className(), ['id' => 'id_producer']);
}

public function relationOrders($fieldIdDocument)
{
$defaultOptionsSearch = Order::defaultOptionsSearch();

return $this->hasMany(Order::className(), [$fieldIdDocument => 'id'])
->with($defaultOptionsSearch['with'])
->joinWith($defaultOptionsSearch['join_with'])
->orderBy('distribution.date ASC');
}

/*
* Méthodes
*/

public function getAmount($type = Order::AMOUNT_TOTAL, $format = false)
{
return $this->_getAmountGeneric($type, false, $format);
}

public function getAmountWithTax($type = Order::AMOUNT_TOTAL, $format = false)
{
return $this->_getAmountGeneric($type, true, $format);
}

protected function _getAmountGeneric($type = Order::AMOUNT_TOTAL, $withTax = true, $format = false)
{
$amount = 0;
$totalVat = 0;
$ordersArray = $this->orders;

foreach ($ordersArray as $order) {
$order->init($this->tax_calculation_method);
$amount += $order->getAmount($type);
$totalVat += $order->getTotalVat($type);
}

public function relationOrders($fieldIdDocument)
{
$defaultOptionsSearch = Order::defaultOptionsSearch();

return $this->hasMany(Order::className(), [$fieldIdDocument => 'id'])
->with($defaultOptionsSearch['with'])
->joinWith($defaultOptionsSearch['join_with'])
->orderBy('distribution.date ASC');
if($this->isTaxCalculationMethodRoundingOfTheSum()) {
$totalVat = Price::round($totalVat);
}

/*
* Méthodes
*/

public function getAmount($type = Order::AMOUNT_TOTAL, $format = false)
{
return $this->_getAmountGeneric($type, false, $format);
if($withTax) {
$amount += $totalVat;
}

public function getAmountWithTax($type = Order::AMOUNT_TOTAL, $format = false)
{
return $this->_getAmountGeneric($type, true, $format);
if ($format) {
return Price::format($amount);
} else {
return $amount;
}
}

protected function _getAmountGeneric($type = Order::AMOUNT_TOTAL, $withTax = true, $format = false)
{
$amount = 0;
$ordersArray = $this->orders;
public function getTotalVatArray($typeTotal)
{
$totalVatArray = [];

foreach ($ordersArray as $order) {
$order->init($this->tax_calculation_method);
$ordersArray = $this->orders;

if ($withTax) {
$amount += $order->getAmountWithTax($type);
}
else {
$amount += $order->getAmount($type);
}
}

if ($format) {
return Price::format($amount);
} else {
return $amount;
foreach($ordersArray as $order) {
$order->init($this->tax_calculation_method);
$fieldNameVat = $order->getFieldNameAmount($typeTotal, 'vat');
foreach($order->$fieldNameVat as $idTaxRate => $vat) {
if(!isset($totalVatArray[$idTaxRate])) {
$totalVatArray[$idTaxRate] = 0;
}
$totalVatArray[$idTaxRate] += $vat;
}
}

public function getPointSale()
{
if (isset($this->orders) && isset($this->orders[0])) {
return $this->orders[0]->pointSale;
} else {
return '';
}
}
return $totalVatArray;
}

public function getDistribution()
{
if (isset($this->orders) && isset($this->orders[0])) {
return $this->orders[0]->distribution;
} else {
return '';
}
public function getPointSale()
{
if (isset($this->orders) && isset($this->orders[0])) {
return $this->orders[0]->pointSale;
} else {
return '';
}

public function getClass()
{
return str_replace('common\models\\', '', get_class($this));
}

public function getDistribution()
{
if (isset($this->orders) && isset($this->orders[0])) {
return $this->orders[0]->distribution;
} else {
return '';
}

public function getType()
{
$class = $this->getClass();

if ($class == 'Invoice') {
$documentType = 'Facture';
} elseif ($class == 'DeliveryNote') {
$documentType = 'Bon de livraison';
} elseif ($class == 'Quotation') {
$documentType = 'Devis';
}

if (isset($documentType)) {
return $documentType;
}

return '';
}

public function getClass()
{
return str_replace('common\models\\', '', get_class($this));
}

public function getType()
{
$class = $this->getClass();

if ($class == 'Invoice') {
$documentType = 'Facture';
} elseif ($class == 'DeliveryNote') {
$documentType = 'Bon de livraison';
} elseif ($class == 'Quotation') {
$documentType = 'Devis';
}

public function isValidClass($typeDocument)
{
return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']);
if (isset($documentType)) {
return $documentType;
}

public function generateReference()
{
$class = $this->getClass();
$classLower = strtolower($class);
if ($classLower == 'deliverynote') {
$classLower = 'delivery_note';
}
return '';
}

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

if ($oneDocumentExist) {
$reference = $oneDocumentExist->reference;
$pattern = '#([A-Z]+)?([0-9]+)#';
preg_match($pattern, $reference, $matches, PREG_OFFSET_CAPTURE);
$sizeNumReference = strlen($matches[2][0]);
$numReference = ((int)$matches[2][0]) + 1;
$numReference = str_pad($numReference, $sizeNumReference, '0', STR_PAD_LEFT);

return $prefix . $numReference;
} else {
$firstReference = Producer::getConfig('document_' . $classLower . '_first_reference');

if (strlen($firstReference) > 0) {
return $firstReference;
} else {
return $prefix . '00001';
}
}
}

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

$contentFooter = '<div id="footer">';
$contentFooter .= '<div class="infos-bottom">' . Html::encode($producer->document_infos_bottom) . '</div>';
if ($this->isStatusValid() || $this->isStatusDraft()) {
$contentFooter .= '<div class="reference-document">';
if ($this->isStatusValid()) {
$contentFooter .= $this->getType() . ' N°' . $this->reference;
}
if ($this->isStatusDraft()) {
$contentFooter .= $this->getType() . ' non validé';
if($this->getType() == 'Facture') {
$contentFooter .= 'e' ;
}
}
$contentFooter .= '</div>';
}
$contentFooter .= '</div>';
public function isValidClass($typeDocument)
{
return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']);
}

$marginBottom = 10 ;
if(strlen(Producer::getConfig('document_infos_bottom')) > 0) {
$marginBottom = 40 ;
}

$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => $destination,
'content' => $content,
'filename' => $this->getFilename(),
'cssFile' => Yii::getAlias('@webroot/css/document/download.css'),
'marginBottom' => $marginBottom,
'methods' => [
'SetHTMLFooter' => $contentFooter
]
]);

return $pdf->render();
public function generateReference()
{
$class = $this->getClass();
$classLower = strtolower($class);
if ($classLower == 'deliverynote') {
$classLower = 'delivery_note';
}

public function send()
{
if(isset($this->user) && strlen($this->user->email) > 0) {
$producer = GlobalParam::getCurrentProducer();

$subjectEmail = $this->getType() ;
if($this->isStatusValid()) {
$subjectEmail .= ' N°'.$this->reference ;
}

$email = Yii::$app->mailer->compose(
[
'html' => 'sendDocument-html',
'text' => 'sendDocument-text'
], [
'document' => $this,
])
->setTo($this->user->email)
->setFrom([$producer->getEmailOpendistrib() => $producer->name])
->setSubject('['.$producer->name.'] '.$subjectEmail) ;

$this->generatePdf(Pdf::DEST_FILE) ;
$email->attach($this->getFilename());

return $email->send() ;
}

return false ;
$prefix = Producer::getConfig('document_' . $classLower . '_prefix');
$oneDocumentExist = $class::searchOne(['status' => Document::STATUS_VALID], ['orderby' => 'reference DESC']);

if ($oneDocumentExist) {
$reference = $oneDocumentExist->reference;
$pattern = '#([A-Z]+)?([0-9]+)#';
preg_match($pattern, $reference, $matches, PREG_OFFSET_CAPTURE);
$sizeNumReference = strlen($matches[2][0]);
$numReference = ((int)$matches[2][0]) + 1;
$numReference = str_pad($numReference, $sizeNumReference, '0', STR_PAD_LEFT);

return $prefix . $numReference;
} else {
$firstReference = Producer::getConfig('document_' . $classLower . '_first_reference');

if (strlen($firstReference) > 0) {
return $firstReference;
} else {
return $prefix . '00001';
}
}

public function changeStatus($status)
{
if ($status == Document::STATUS_VALID) {
$this->status = $status;
$this->reference = $this->generateReference();
}

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

$contentFooter = '<div id="footer">';
$contentFooter .= '<div class="infos-bottom">' . Html::encode($producer->document_infos_bottom) . '</div>';
if ($this->isStatusValid() || $this->isStatusDraft()) {
$contentFooter .= '<div class="reference-document">';
if ($this->isStatusValid()) {
$contentFooter .= $this->getType() . ' N°' . $this->reference;
}
if ($this->isStatusDraft()) {
$contentFooter .= $this->getType() . ' non validé';
if ($this->getType() == 'Facture') {
$contentFooter .= 'e';
}
}
$contentFooter .= '</div>';
}
$contentFooter .= '</div>';

public function getStatusWording()
{
return ($this->status == self::STATUS_DRAFT) ? 'Brouillon' : 'Validé';
}

public function getStatusCssClass()
{
return ($this->status == self::STATUS_DRAFT) ? 'default' : 'success';
$marginBottom = 10;
if (strlen(Producer::getConfig('document_infos_bottom')) > 0) {
$marginBottom = 40;
}

public function getHtmlLabel()
{
$label = $this->getStatusWording();
$classLabel = $this->getStatusCssClass();
return '<span class="label label-' . $classLabel . '">' . $label . '</span>';
}
$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => $destination,
'content' => $content,
'filename' => $this->getFilename(),
'cssFile' => Yii::getAlias('@webroot/css/document/download.css'),
'marginBottom' => $marginBottom,
'methods' => [
'SetHTMLFooter' => $contentFooter
]
]);

return $pdf->render();
}

public function send()
{
if (isset($this->user) && strlen($this->user->email) > 0) {
$producer = GlobalParam::getCurrentProducer();

$subjectEmail = $this->getType();
if ($this->isStatusValid()) {
$subjectEmail .= ' N°' . $this->reference;
}

public function isStatus($status)
{
return $this->status == $status;
$email = Yii::$app->mailer->compose(
[
'html' => 'sendDocument-html',
'text' => 'sendDocument-text'
], [
'document' => $this,
])
->setTo($this->user->email)
->setFrom([$producer->getEmailOpendistrib() => $producer->name])
->setSubject('[' . $producer->name . '] ' . $subjectEmail);

$this->generatePdf(Pdf::DEST_FILE);
$email->attach($this->getFilename());

return $email->send();
}

public function isStatusDraft()
{
return $this->isStatus(self::STATUS_DRAFT);
}
return false;
}

public function isStatusValid()
{
return $this->isStatus(self::STATUS_VALID);
public function changeStatus($status)
{
if ($status == Document::STATUS_VALID) {
$this->status = $status;
$this->reference = $this->generateReference();
}

public function getProductsOrders()
{
$productsOrdersArray = [];
$ordersArray = $this->orders ;
if ($ordersArray && count($ordersArray)) {
foreach ($ordersArray as $order) {
foreach ($order->productOrder as $productOrder) {
$indexProductOrder = $productOrder->product->order ;
$newProductOrder = clone $productOrder ;

if (!isset($productsOrdersArray[$indexProductOrder])) {
$productsOrdersArray[$indexProductOrder] = [$newProductOrder];
} else {
$productOrderMatch = false;
foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) {
if ($theProductOrder->unit == $productOrder->unit
&& ( (!$this->isInvoicePrice() && $theProductOrder->price == $productOrder->price)
|| ($this->isInvoicePrice() && $theProductOrder->invoice_price == $productOrder->invoice_price)
)) {

$theProductOrder->quantity += $productOrder->quantity;
$productOrderMatch = true;
}
}
if (!$productOrderMatch) {
$productsOrdersArray[$indexProductOrder][] = $newProductOrder;
}
}
}
}

public function getStatusWording()
{
return ($this->status == self::STATUS_DRAFT) ? 'Brouillon' : 'Validé';
}

public function getStatusCssClass()
{
return ($this->status == self::STATUS_DRAFT) ? 'default' : 'success';
}

public function getHtmlLabel()
{
$label = $this->getStatusWording();
$classLabel = $this->getStatusCssClass();
return '<span class="label label-' . $classLabel . '">' . $label . '</span>';
}

public function isStatus($status)
{
return $this->status == $status;
}

public function isStatusDraft()
{
return $this->isStatus(self::STATUS_DRAFT);
}

public function isStatusValid()
{
return $this->isStatus(self::STATUS_VALID);
}

public function getProductsOrders()
{
$productsOrdersArray = [];
$ordersArray = $this->orders;
if ($ordersArray && count($ordersArray)) {
foreach ($ordersArray as $order) {
foreach ($order->productOrder as $productOrder) {
$indexProductOrder = $productOrder->product->order;
$newProductOrder = clone $productOrder;

if (!isset($productsOrdersArray[$indexProductOrder])) {
$productsOrdersArray[$indexProductOrder] = [$newProductOrder];
} else {
$productOrderMatch = false;
foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) {
if ($theProductOrder->unit == $productOrder->unit
&& ((!$this->isInvoicePrice() && $theProductOrder->price == $productOrder->price)
|| ($this->isInvoicePrice() && $theProductOrder->invoice_price == $productOrder->invoice_price)
)) {

$theProductOrder->quantity += $productOrder->quantity;
$productOrderMatch = true;
}
}
if (!$productOrderMatch) {
$productsOrdersArray[$indexProductOrder][] = $newProductOrder;
}
}
}

// tri des orderProduct par product.order
ksort($productsOrdersArray);

return $productsOrdersArray;
}

public function isDisplayOrders()
{
$displayOrders = ($this->getClass() == 'Invoice') ?
Producer::getConfig('document_display_orders_invoice') :
Producer::getConfig('document_display_orders_delivery_note') ;

return $displayOrders ;
}

public function getFilename()
{
return Yii::getAlias('@app/web/pdf/'.$this->getType().'-' . $this->reference. '.pdf') ;
}

public function isInvoicePrice()
{
return $this->getClass() == 'Invoice' || $this->getClass() == 'DeliveryNote' ;
}

public function isTaxCalculationMethodSumOfRoundings()
{
return $this->tax_calculation_method == self::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS;
}

public function isTaxCalculationMethodRoundingOfTheSum()
{
return $this->tax_calculation_method == self::TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM;
}
}

public function initTaxCalculationMethod()
{
$producerTaxCalculationMethod = Producer::getConfig('option_tax_calculation_method');

if($producerTaxCalculationMethod) {
$this->tax_calculation_method = $producerTaxCalculationMethod;
}
else {
$this->tax_calculation_method = self::TAX_CALCULATION_METHOD_DEFAULT;
}
// tri des orderProduct par product.order
ksort($productsOrdersArray);

return $productsOrdersArray;
}

public function isDisplayOrders()
{
$displayOrders = ($this->getClass() == 'Invoice') ?
Producer::getConfig('document_display_orders_invoice') :
Producer::getConfig('document_display_orders_delivery_note');

return $displayOrders;
}

public function getFilename()
{
return Yii::getAlias('@app/web/pdf/' . $this->getType() . '-' . $this->reference . '.pdf');
}

public function isInvoicePrice()
{
return $this->getClass() == 'Invoice' || $this->getClass() == 'DeliveryNote';
}

public function isTaxCalculationMethodSumOfRoundings()
{
return $this->tax_calculation_method == self::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS;
}

public function isTaxCalculationMethodRoundingOfTheSum()
{
return $this->tax_calculation_method == self::TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM;
}

public function initTaxCalculationMethod()
{
$producerTaxCalculationMethod = Producer::getConfig('option_tax_calculation_method');

if ($producerTaxCalculationMethod) {
$this->tax_calculation_method = $producerTaxCalculationMethod;
} else {
$this->tax_calculation_method = self::TAX_CALCULATION_METHOD_DEFAULT;
}
}
}

+ 71
- 27
common/models/Order.php Прегледај датотеку

@@ -63,8 +63,10 @@ class Order extends ActiveRecordCommon
{
var $amount = 0;
var $amount_with_tax = 0;
var $amount_vat = [];
var $invoice_amount = 0;
var $invoice_amount_with_tax = 0;
var $invoice_amount_vat = [];
var $paid_amount = 0;
var $weight = 0;

@@ -239,44 +241,86 @@ class Order extends ActiveRecordCommon
{
$this->amount = 0;
$this->amount_with_tax = 0;
$this->amount_vat = [];
$this->invoice_amount = 0;
$this->invoice_amount_with_tax = 0;
$this->invoice_amount_vat = [];
$this->weight = 0;

if (isset($this->productOrder)) {
foreach ($this->productOrder as $productOrder) {
$this->amount += $productOrder->price * $productOrder->quantity;
$this->amount_with_tax += Price::getPriceWithTax(
$productOrder->price,
$productOrder->taxRate->value,
$taxCalculationMethod
) * $productOrder->quantity;

if($productOrder->invoice_price) {
$invoicePrice = $productOrder->invoice_price;
}
else {
$invoicePrice = $productOrder->price;
}

$this->invoice_amount += $invoicePrice * $productOrder->quantity;
$this->invoice_amount_with_tax += Price::getPriceWithTax(
$invoicePrice,
$productOrder->taxRate->value,
$taxCalculationMethod
) * $productOrder->quantity;
$this->addAmount(self::AMOUNT_TOTAL, $productOrder, $taxCalculationMethod);
$this->addAmount(self::INVOICE_AMOUNT_TOTAL, $productOrder, $taxCalculationMethod);
$this->addWeight($productOrder);
}
}
}

if ($productOrder->unit == 'piece') {
if (isset($productOrder->product)) {
$this->weight += ($productOrder->quantity * $productOrder->product->weight) / 1000;
}
} else {
$this->weight += $productOrder->quantity;
}
public function addWeight($productOrder)
{
if ($productOrder->unit == 'piece') {
if (isset($productOrder->product)) {
$this->weight += ($productOrder->quantity * $productOrder->product->weight) / 1000;
}
} else {
$this->weight += $productOrder->quantity;
}
}

public function addAmount($typeTotal, $productOrder, $taxCalculationMethod)
{
$fieldNameAmount = $this->getFieldNameAmount($typeTotal);
$fieldNameAmountWithTax = $this->getFieldNameAmount($typeTotal, 'with_tax');
$price = $productOrder->getPriceByTypeTotal($typeTotal);
$this->$fieldNameAmount += $price * $productOrder->quantity;
$this->$fieldNameAmountWithTax += Price::getPriceWithTax(
$price,
$productOrder->taxRate->value,
$taxCalculationMethod
) * $productOrder->quantity;
$this->addVat($typeTotal, $price * $productOrder->quantity, $productOrder->taxRate, $taxCalculationMethod);
}

public function addVat($typeTotal, $priceTotalWithoutTax, $taxRate, $taxCalculationMethod)
{
$fieldName = $this->getFieldNameAmount($typeTotal, 'vat');

if(!isset($this->$fieldName[$taxRate->id])) {
$this->$fieldName[$taxRate->id] = 0;
}

$this->$fieldName[$taxRate->id] += Price::getVat($priceTotalWithoutTax, $taxRate->value, $taxCalculationMethod);
}

public function getTotalVat($typeTotal = self::AMOUNT_TOTAL)
{
$fieldName = $this->getFieldNameAmount($typeTotal, 'vat');
$totalVat = 0;

foreach($this->$fieldName as $vat) {
$totalVat += $vat;
}

return $totalVat;
}

public function getFieldNameAmount($typeTotal = self::AMOUNT_TOTAL, $typeField = '')
{
$fieldName = 'amount';
if($typeTotal == self::INVOICE_AMOUNT_TOTAL) {
$fieldName = 'invoice_amount';
}

if($typeField == 'vat') {
$fieldName = $fieldName.'_vat';
}
elseif($typeField == 'with_tax') {
$fieldName = $fieldName.'_with_tax';
}

return $fieldName;
}

/**
* Initialise le montant payé de la commande et le retourne.
*

+ 4
- 2
common/models/Producer.php Прегледај датотеку

@@ -252,7 +252,8 @@ class Producer extends ActiveRecordCommon
'option_display_export_grid',
'option_stripe_mode_test',
'option_notify_producer_order_summary',
'option_billing_reduction'
'option_billing_reduction',
'option_export_evoliz'
],
'boolean'
],
@@ -388,7 +389,8 @@ class Producer extends ActiveRecordCommon
'option_billing_type' => 'Type de facturation',
'option_billing_frequency' => 'Fréquence de facturation',
'option_billing_reduction' => 'Réduction appliquée au moment de la facturation',
'option_tax_calculation_method' => 'Méthode de calcul de la TVA'
'option_tax_calculation_method' => 'Méthode de calcul de la TVA',
'option_export_evoliz' => 'Activer l\'export vers Evoliz'
];
}


+ 9
- 0
common/models/ProductOrder.php Прегледај датотеку

@@ -149,4 +149,13 @@ class ProductOrder extends ActiveRecordCommon
return Price::getPriceWithTax($this->price, $this->taxRate->value);
}

public function getPriceByTypeTotal($typeTotal = Order::AMOUNT_TOTAL)
{
if($typeTotal == Order::INVOICE_AMOUNT_TOTAL && $this->invoice_price) {
return $this->invoice_price;
}

return $this->price;
}

}

+ 12
- 0
common/models/TaxRate.php Прегледај датотеку

@@ -58,4 +58,16 @@ class TaxRate extends ActiveRecordCommon
'attribute_id_producer' => ''
] ;
}

public static function getTaxRateArray()
{
$taxRateArrayReturn = [];
$taxRateArray = TaxRate::find()->all();

foreach($taxRateArray as $taxRate) {
$taxRateArrayReturn[$taxRate->id] = $taxRate;
}

return $taxRateArrayReturn;
}
}

+ 3
- 2
common/models/User.php Прегледај датотеку

@@ -105,7 +105,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
{
return [
[['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday', 'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday', 'mail_distribution_sunday', 'is_main_contact'], 'boolean'],
[['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person'], 'string'],
[['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code'], 'string'],
['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false],
['email', 'email', 'message' => 'Cette adresse email n\'est pas valide'],
['email', 'verifyEmail'],
@@ -145,7 +145,8 @@ class User extends ActiveRecordCommon implements IdentityInterface
'name_legal_person' => 'Libellé',
'is_main_contact' => 'Contact principal',
'product_price_percent' => 'Prix produits : pourcentage',
'user_groups' => "Groupes d'utilisateurs"
'user_groups' => "Groupes d'utilisateurs",
'evoliz_code' => 'Code client Evoliz'
];
}


+ 28
- 0
console/migrations/m220919_084020_add_fields_export_evoliz.php Прегледај датотеку

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

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

/**
* Class m220919_084020_add_fields_export_evoliz
*/
class m220919_084020_add_fields_export_evoliz extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('producer', 'option_export_evoliz', Schema::TYPE_BOOLEAN .' DEFAULT 0');
$this->addColumn('user', 'evoliz_code', Schema::TYPE_STRING);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('producer', 'option_export_evoliz');
$this->dropColumn('user', 'evoliz_code');
}
}

Loading…
Откажи
Сачувај