$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); |
* 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', |
return 'delivery_note'; | return 'delivery_note'; | ||||
} | } | ||||
public function rules() | |||||
{ | |||||
$rules = parent::rules(); | |||||
$rules[] = ['ignore_when_billing', 'boolean']; | |||||
return $rules; | |||||
} | |||||
/* | /* | ||||
* Relations | * Relations | ||||
*/ | */ |
[['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'] | ||||
]; | ]; |
{ | { | ||||
$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; |
<?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'); | |||||
} | |||||
} |