瀏覽代碼

[Admin] Factures producteurs via API Dolibarr

feature/souke
Guillaume Bourgeois 11 月之前
父節點
當前提交
250e3cdb60
共有 6 個檔案被更改,包括 59 行新增23 行删除
  1. +17
    -14
      backend/controllers/ProducerInvoiceController.php
  2. +1
    -1
      backend/views/layouts/left.php
  3. +6
    -1
      backend/views/producer-invoice/index.php
  4. +19
    -7
      common/components/DolibarrApi.php
  5. +6
    -0
      common/controllers/CommonController.php
  6. +10
    -0
      common/logic/Producer/Producer/Service/DolibarrProducerUtils.php

+ 17
- 14
backend/controllers/ProducerInvoiceController.php 查看文件

@@ -3,7 +3,6 @@
namespace backend\controllers;

use yii\filters\AccessControl;
use yii\filters\VerbFilter;

class ProducerInvoiceController extends BackendController
{
@@ -17,7 +16,9 @@ class ProducerInvoiceController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return $this->getUserModule()
return
$this->getParameterBag()->get('dolibarrApiKey')
&& $this->getUserModule()
->getAuthorizationChecker()
->isGrantedAsProducer($this->getUserCurrent());
}
@@ -29,22 +30,24 @@ class ProducerInvoiceController extends BackendController

public function actionIndex()
{
$producerCurrent = $this->getProducerCurrent();
$invoicesArray = [];
if($producerCurrent->dolibarr_socid) {
$invoicesArray = \Yii::$app->dolibarrApi->getInvoices($producerCurrent->dolibarr_socid);
}

return $this->render('index', [
'invoicesArray' => $invoicesArray
'invoicesArray' => $this->getProducerModule()
->getDolibarrUtils()
->getDolibarrProducerInvoices($this->getProducerCurrent())
]);
}

public function actionDownload(string $filename)
public function actionDownload(int $idDolibarrInvoice)
{
$documentDownload = \Yii::$app->dolibarrApi->downloadInvoice($filename);
return \Yii::$app->response->sendContentAsFile(base64_decode($documentDownload['content']), $documentDownload['filename'], [
'mimeType' => $documentDownload['content-type']
]);
$documentDownload = \Yii::$app->dolibarrApi->downloadInvoice($idDolibarrInvoice);
if($documentDownload) {
return \Yii::$app->response->sendContentAsFile(base64_decode($documentDownload['content']), $documentDownload['filename'], [
'mimeType' => $documentDownload['content-type']
]);
}
else {
$this->addFlash('error', 'Facture introuvable');
return $this->redirectReferer();
}
}
}

+ 1
- 1
backend/views/layouts/left.php 查看文件

@@ -156,7 +156,7 @@ $isUserCurrentGrantedAsProducer = $userModule->getAuthorizationChecker()->isGran
'label' => 'Mes factures',
'icon' => 'clone',
'url' => ['/producer-invoice/index'],
'visible' => $isUserCurrentGrantedAsProducer,
'visible' => $isUserCurrentGrantedAsProducer && Yii::$app->parameterBag->get('dolibarrApiKey'),
'active' => Yii::$app->controller->id == 'producer-invoice',
],
[

+ 6
- 1
backend/views/producer-invoice/index.php 查看文件

@@ -43,6 +43,11 @@ $this->setTitle('Mes factures') ;
$this->addBreadcrumb($this->getTitle()) ;

?>

<div class="callout callout-info">
<span class="glyphicon glyphicon-info-sign"></span> Les factures et les réglements sont saisis en début de mois.
</div>

<?php if($invoicesArray && count($invoicesArray)): ?>
<table class="table table-striped table-bordered">
<thead>
@@ -62,7 +67,7 @@ $this->addBreadcrumb($this->getTitle()) ;
<td><?= Price::format($invoice['total_ttc']); ?></td>
<td><?= ($invoice['remaintopay'] > 0) ? '<span class="label label-warning">Impayée</span>' : '<span class="label label-success">Payée</span>'; ?></td>
<td>
<a class="btn btn-default" href="<?= $this->getUrlManagerBackend()->createUrl(['producer-invoice/download', 'filename' => str_replace('facture/', '', $invoice['last_main_doc'])]); ?>">
<a class="btn btn-default" href="<?= $this->getUrlManagerBackend()->createUrl(['producer-invoice/download', 'idDolibarrInvoice' => $invoice['id']]); ?>">
<span class="glyphicon glyphicon-download-alt"></span> Télécharger
</a>
</td>

+ 19
- 7
common/components/DolibarrApi.php 查看文件

@@ -2,15 +2,13 @@

namespace common\components;

use Psr\Http\Message\ResponseInterface;

class DolibarrApi extends AbstractApi
{
const RESOURCE_INVOICES = 'invoices';
const RESOURCE_PRODUCTS = 'products';
const RESOURCE_DOCUMENTS = 'documents';

public function getInvoices(int $idThirdParty)
public function getInvoicesByThirParty(int $idThirdParty)
{
return $this->get(self::RESOURCE_INVOICES, [
'sortfield' => 't.rowid',
@@ -20,14 +18,28 @@ class DolibarrApi extends AbstractApi
]);
}

public function downloadInvoice(string $originalFile)
public function getInvoice(int $idInvoice)
{
return $this->get(self::RESOURCE_DOCUMENTS.'/download', [
'modulepart' => 'facture',
'original_file' => $originalFile
return $this->get(self::RESOURCE_INVOICES.'/'.$idInvoice, [
'contact_list' => 1
]);
}

public function downloadInvoice(string $idInvoice)
{
$invoice = $this->getInvoice($idInvoice);
if($invoice && isset($invoice['last_main_doc'])) {
$originalFilename = str_replace('facture/', '', $invoice['last_main_doc']);

return $this->get(self::RESOURCE_DOCUMENTS.'/download', [
'modulepart' => 'facture',
'original_file' => $originalFilename
]);
}

return null;
}

public function createInvoice(int $idUser)
{
return $this->post(self::RESOURCE_INVOICES, [

+ 6
- 0
common/controllers/CommonController.php 查看文件

@@ -40,6 +40,7 @@ namespace common\controllers;

use common\components\BusinessLogic;
use common\components\BusinessLogicTrait;
use common\components\ParameterBag;
use common\logic\User\User\Model\User;
use yii;
use yii\web\Response;
@@ -111,6 +112,11 @@ class CommonController extends \yii\web\Controller
{
return $this->redirect(Yii::$app->request->referrer ?: Yii::$app->homeUrl);
}

public function getParameterBag(): ParameterBag
{
return Yii::$app->parameterBag;
}
}

?>

+ 10
- 0
common/logic/Producer/Producer/Service/DolibarrProducerUtils.php 查看文件

@@ -22,6 +22,16 @@ class DolibarrProducerUtils extends AbstractManager
$this->producerRepository = $this->loadService(ProducerRepository::class);
}

public function getDolibarrProducerInvoices(Producer $producer): array
{
$invoicesArray = [];
if($producer->dolibarr_socid) {
$invoicesArray = $this->dolibarrApi->getInvoicesByThirParty($producer->dolibarr_socid);
}

return $invoicesArray;
}

public function generateDolibarrProducerInvoice(Producer $producer)
{
$idProduct = $this->getDolibarrProductId($producer);

Loading…
取消
儲存