diff --git a/src/schedule-2.0/.env b/src/schedule-2.0/.env index 9b1367b..75b159f 100644 --- a/src/schedule-2.0/.env +++ b/src/schedule-2.0/.env @@ -64,4 +64,8 @@ CAS_FIRSTNAME=firstname MAILER_URL= ## Sentry DSN -SENTRY_DSN= \ No newline at end of file +SENTRY_DSN= + +DOLIBARR_ACTIVE=false +DOLIBARR_API_KEY= +DOLIBARR_URI= diff --git a/src/schedule-2.0/config/packages/http_client.yaml b/src/schedule-2.0/config/packages/http_client.yaml new file mode 100644 index 0000000..6dfae85 --- /dev/null +++ b/src/schedule-2.0/config/packages/http_client.yaml @@ -0,0 +1,6 @@ +# config/packages/framework.yaml +framework: + http_client: + default_options: + headers: + DOLAPIKEY: '%env(DOLIBARR_API_KEY)%' \ No newline at end of file diff --git a/src/schedule-2.0/config/routes.yaml b/src/schedule-2.0/config/routes.yaml index 60334f7..870f7b1 100644 --- a/src/schedule-2.0/config/routes.yaml +++ b/src/schedule-2.0/config/routes.yaml @@ -233,6 +233,14 @@ app_offer_activeoffer: path: /master/offer/activeoffer defaults: { _controller: App\Controller\OfferController:activeoffer } +app_offer_getorders: + path: /master/offer/getorders + defaults: { _controller: App\Controller\OfferController:getorders } + +app_offer_convert: + path: /master/offer/convert/{type}/{id} + defaults: { _controller: App\Controller\OfferController:convert } + #== Task ==================================================================================================== app_task: path: /master/task diff --git a/src/schedule-2.0/config/services.yaml b/src/schedule-2.0/config/services.yaml index c9ebaa1..cb5a388 100644 --- a/src/schedule-2.0/config/services.yaml +++ b/src/schedule-2.0/config/services.yaml @@ -21,6 +21,9 @@ parameters: casFirstname: '%env(resolve:CAS_FIRSTNAME)%' officeHourStart: '%env(resolve:OFFICE_HOUR_START)%' officeHourEnd: '%env(resolve:OFFICE_HOUR_END)%' + doliActive: '%env(resolve:DOLIBARR_ACTIVE)%' + doliApiKey: '%env(resolve:DOLIBARR_API_KEY)%' + doliUri: '%env(resolve:DOLIBARR_URI)%' services: # default configuration for services in *this* file diff --git a/src/schedule-2.0/src/Controller/OfferController.php b/src/schedule-2.0/src/Controller/OfferController.php index 7ffc0b9..1b4512b 100755 --- a/src/schedule-2.0/src/Controller/OfferController.php +++ b/src/schedule-2.0/src/Controller/OfferController.php @@ -17,21 +17,25 @@ class OfferController extends AbstractController private $route = "app_offer"; private $render = "Offer/"; private $entity = "App:Offer"; + private $dolibarrapi; private $knpSnappy; - public function __construct(\Knp\Snappy\Pdf $knpSnappy) { $this->knpSnappy = $knpSnappy; } + public function __construct(\Knp\Snappy\Pdf $knpSnappy, \App\Service\dolibarrApi $dolibarrapi) { + $this->knpSnappy = $knpSnappy; + $this->dolibarrapi = $dolibarrapi; + } public function list(Request $request) { $em = $this->getDoctrine()->getManager(); $services=$em->getRepository("App:Service")->findAllOfferActive($this->get('session')->get('activeproject'),$this->get('session')->get('activeoffer'),$this->get('session')->get('idservice')); - + if($request->query->get('fgprint')) { $render = $this->renderView($this->render.'list.html.twig',[ "services" => $services, "useheader" => true, "usesidebar" => true, - "fgprint" => true, + "fgprint" => true, ]); return new PdfResponse( @@ -44,6 +48,7 @@ class OfferController extends AbstractController "services" => $services, "useheader" => true, "usesidebar" => true, + "doliactive" => $this->getParameter('doliActive'), ]); } } @@ -53,7 +58,6 @@ class OfferController extends AbstractController // Initialisation de l'enregistrement $em = $this->getDoctrine()->getManager(); $data = new Entity(); - // Création du formulaire $form = $this->createForm(Form::class,$data,array("mode"=>"submit")); @@ -82,7 +86,52 @@ class OfferController extends AbstractController 'form' => $form->createView() ]); } - + public function convert($type, $id, Request $request) + { + // Initialisation de l'enregistrement + $em = $this->getDoctrine()->getManager(); + $data = new Entity(); + $order = $this->dolibarrapi->getOrder($id, $type); + if (isset($order["ref_customer"]) && $order["ref_customer"]!= ""){ + $data->setRef($order["ref_customer"]); + } + if (isset($order["ref"]) && $order["ref"]!= ""){ + $data->setRef($order["ref"]); + } + $data->setName($order["customer_name"]); + $data->setQuantity($order["total_qty"]); + + // Création du formulaire + $form = $this->createForm(Form::class,$data,array("mode"=>"submit")); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur erreur + $this->getErrorForm(null,$form,$request,$data,"submit"); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + + $data = $form->getData(); + $data->setIddolibarr($order["id"]); + $data->setTypedolibarr($type); + $em->persist($data); + $em->flush(); + + // Retour à la liste + return $this->redirectToRoute($this->route); + } + + // Affichage du formulaire + return $this->render($this->render.'edit.html.twig', [ + 'useheader' => true, + 'usesidebar' => true, + $this->data => $data, + 'mode' => 'submit', + 'form' => $form->createView() + ]); + } public function update($id,Request $request) { // Initialisation de l'enregistrement @@ -170,8 +219,66 @@ class OfferController extends AbstractController $this->get('session')->set('activeoffer',!$this->get('session')->get('activeoffer')); return $this->redirectToRoute($this->route); } + public function getorders(){ + $em = $this->getDoctrine()->getManager(); + $orders = $this->dolibarrapi->getOrders(); + $propals = $this->dolibarrapi->getPropals(); - + $tborders = []; + foreach($orders as $order){ + if (intval($order["statut"]> 0)){ + + $exist1 = $em->getRepository($this->entity)->findOneBy(['ref' => $order["ref"]]); + $exist2 = $em->getRepository($this->entity)->findOneBy(['ref' => $order["ref_client"]]); + + if (!$exist1 && !$exist2) { + $torder["id"]=$order["id"]; + $torder["customer_name"]=$order["customer_name"]; + $torder["ref"]=$order["ref"]; + $torder["ref_client"]=$order["ref_client"]; + $torder["statut"]=$order["statut"]; + $torder["total_ht"]=$order["total_ht"]; + $torder["total_tva"]=$order["total_tva"]; + $torder["total_ttc"]=$order["total_ttc"]; + $torder["type"] = "commande"; + + array_push($tborders, $torder); + } + } + } + foreach($propals as $propal){ + if (intval($propal["statut"]> 1)){ + $exist1 = false; + $exist2 = false; + if ($propal["ref"] != ""){ + $exist1 = $em->getRepository($this->entity)->findOneBy(['ref' => $propal["ref"]]); + } + if ($propal["ref_client"] != ""){ + $exist2 = $em->getRepository($this->entity)->findOneBy(['ref' => $propal["ref_client"]]); + } + + if (!$exist1 && !$exist2) { + $tpropal["id"]=$propal["id"]; + $tpropal["customer_name"]=$propal["customer_name"]; + $tpropal["ref"]=$propal["ref"]; + $tpropal["ref_client"]=$propal["ref_client"]; + $tpropal["statut"]=$propal["statut"]; + $tpropal["total_ht"]=$propal["total_ht"]; + $tpropal["total_tva"]=$propal["total_tva"]; + $tpropal["total_ttc"]=$propal["total_ttc"]; + $tpropal["type"] = "propal"; + + array_push($tborders, $tpropal); + } + } + } + + return $this->render($this->render.'getorders.html.twig', [ + 'useheader' => true, + 'usesidebar' => true, + 'orders' => $tborders + ]); + } protected function getErrorForm($id,$form,$request,$data,$mode) { if ($form->get('submit')->isClicked()&&$mode=="delete") { } diff --git a/src/schedule-2.0/src/Entity/Offer.php b/src/schedule-2.0/src/Entity/Offer.php index fd39472..c8996a4 100644 --- a/src/schedule-2.0/src/Entity/Offer.php +++ b/src/schedule-2.0/src/Entity/Offer.php @@ -59,6 +59,17 @@ class Offer */ private $active; + /** + * @ORM\Column(name="iddolibarr", type="decimal", scale=5, nullable=true) + * + */ + private $iddolibarr; + /** + * @ORM\Column(name="typedolibarr", type="string", nullable=true) + * + */ + private $typedolibarr; + /** * @ORM\ManyToOne(targetEntity="Project", inversedBy="offers") */ @@ -145,7 +156,6 @@ class Offer return $this; } - public function getProject(): ?Project { return $this->project; @@ -158,5 +168,29 @@ class Offer return $this; } + public function getIddolibarr(): ?string + { + return $this->iddolibarr; + } + + public function setIddolibarr(?string $iddolibarr): self + { + $this->iddolibarr = $iddolibarr; + + return $this; + } + + public function getTypedolibarr(): ?string + { + return $this->typedolibarr; + } + + public function setTypedolibarr(?string $typedolibarr): self + { + $this->typedolibarr = $typedolibarr; + + return $this; + } + } diff --git a/src/schedule-2.0/src/Service/dolibarrApi.php b/src/schedule-2.0/src/Service/dolibarrApi.php new file mode 100644 index 0000000..1bf2e1b --- /dev/null +++ b/src/schedule-2.0/src/Service/dolibarrApi.php @@ -0,0 +1,98 @@ +em = $em; + $this->container = $container; + $this->client = $client; + $this->doliuri = $this->container->getParameter('doliUri'); + + } + public function getOrders() { + + $start=new \Datetime(); + $start->sub(new \DateInterval('P6M')); + $response = $this->client->request('GET',$this->doliuri."/api/index.php/orders?sortfield=t.rowid&sortorder=DESC&limit=100&sqlfilters=(t.date_creation%3A%3E%3A'".$start->format("Ymd")."')"); + + $content = $response->toArray(); + $tbcontent = []; + foreach($content as $order){ + $order['customer_name'] = $this->getCustomer($order['socid']); + $qty = 0; + foreach($order['lines'] as $line){ + $qty = $qty + intval($line['qty']); + } + $order['total_qty'] = $qty; + array_push($tbcontent, $order); + } + return $tbcontent; + } + public function getOrder($id, $type) { + + $start=new \Datetime(); + $start->sub(new \DateInterval('P6M')); + $order=[]; + if ($type =="commande") { + $response = $this->client->request('GET',$this->doliuri."/api/index.php/orders/".$id); + $order=$response->toArray(); + } + if ($type =="propal") { + $response = $this->client->request('GET',$this->doliuri."/api/index.php/proposals/".$id); + $order=$response->toArray(); + } + + $order['customer_name'] = $this->getCustomer($order['socid']); + $qty = 0; + foreach($order['lines'] as $line){ + $qty = $qty + intval($line['qty']); + } + $order['total_qty'] = $qty; + return $order; + } + + public function getPropals() { + + $start=new \Datetime(); + $start->sub(new \DateInterval('P6M')); + + $response = $this->client->request('GET',$this->doliuri."/api/index.php/proposals?sortfield=t.rowid&sortorder=DESC&limit=100&sqlfilters=(t.datec%3A%3E%3A'".$start->format("Ymd")."')"); + + $content = $response->toArray(); + $tbcontent = []; + foreach($content as $propal){ + $propal['customer_name'] = $this->getCustomer($propal['socid']); + $qty = 0; + foreach($propal['lines'] as $line){ + $qty = $qty + intval($line['qty']); + } + $propal['total_qty'] = $qty; + //$propal['customer_name'] = $this->getCustomer($propal['socid']); + array_push( $tbcontent, $propal); + } + return $tbcontent; + } + public function getCustomer($customerid) { + + $response = $this->client->request('GET',$this->doliuri."/api/index.php/thirdparties/".$customerid); + + $content = $response->toArray(); + + return $content['name']; + } +} \ No newline at end of file diff --git a/src/schedule-2.0/templates/Offer/getorders.html.twig b/src/schedule-2.0/templates/Offer/getorders.html.twig new file mode 100644 index 0000000..55fe391 --- /dev/null +++ b/src/schedule-2.0/templates/Offer/getorders.html.twig @@ -0,0 +1,75 @@ +{% extends "base.html.twig" %} + +{% block localstyle %} + td { + padding:5px !important; + } + {% if fgprint is defined and fgprint %} + table { font-size:10px;} + th,td { + border: 1px solid #37474F; + } + thead { + display: table-header-group; + } + tr { page-break-inside: avoid; } + {%endif%} +{% endblock %} + +{% block body %} +
Liste des dernières commandes/propal récupérées depuis Dolibarr.
+ Les commandes doivent avoir un statut "Validée", et le Propal un statut "Signée" pour apparaître dans la liste.
Action | +client | +ref | +ref_client | +statut | +total_ht | +total_tva | +total_ttc | +|
---|---|---|---|---|---|---|---|---|
+ + | +{{order.customer_name}} | + {% if order.type =="commande" %}{{order.ref}} | {% endif %} + {% if order.type =="propal" %}{{order.ref}} | {% endif %} +{{order.ref_client}} | +{{order.statut}} | +{{order.total_ht|number_format(2, '.', ' ')}} | +{{order.total_tva|number_format(2, '.', ' ')}} | +{{order.total_ttc|number_format(2, '.', ' ')}} | +